void putop(enum e_op op) { if (prm_nasm) { skipsize = (op == op_lea); addsize = (op == op_push); if (op == op_fwait) { /* NASM uses WAIT instead of FWAIT */ outop(oplst[op_fwait].word+1); return; } } if (op > op_fyl2xp1) DIAG("illegal opcode."); else outop(oplst[op].word); uses_float=(op >=op_f2xm1); }
void __stdcall out( void ) { char buf[MAXSTR]; init_output_buffer(buf, sizeof(buf)); OutMnem(); if (cmd.Op1.type != o_void) { // output first operand out_one_operand( 0 ); } if( cmd.Op2.type != o_void ) { //pading out_symbol( ',' ); OutChar( ' ' ); // output second operand out_one_operand( 1 ); } if( cmd.Op3.type != o_void ) { //pading out_symbol( ',' ); OutChar( ' ' ); // output third operand out_one_operand( 2 ); } if( cmd.Op4.type != o_void ) { //pading out_symbol( ',' ); OutChar( ' ' ); // output fourth operand out_one_operand( 3 ); } if( cmd.Op5.type != o_void ) { //pading out_symbol( ',' ); OutChar( ' ' ); // output fifth operand out_one_operand( 4 ); } if( cmd.Op6.type != o_void ) { //pading out_symbol( ',' ); OutChar( ' ' ); // output sixth operand out_one_operand( 5 ); } //more processing due to instructions //having more than 6 operands op_t op; op.flags = OF_SHOW; switch(cmd.insnpref) { case SWFACTION_PUSH: { uint16 length = get_word(cmd.ea + 1) + 3; uint16 p = cmd.auxpref; uint8 error = 0; while((length - p) > 0 && error == 0) { switch(get_byte(cmd.ea + p++)) { case 0: //string op.type = o_string; op.dtyp = dt_string; op.addr = cmd.ea + p; //increment the pointer past the string while((length - p) > 0 && get_byte(cmd.ea + p)){ p++; } if ((length - p) > 0) { p++; //adjust for the null caracter } else { error = 1; } break; case 1: //float op.type = o_imm; //op.dtyp = dt_float; op.dtyp = dt_dword; if ((length - p) >= 4) { op.value = get_long(cmd.ea + p); p += 4; } else { error = 1; } break; case 2: //null op.type = o_null; op.dtyp = dt_void; break; case 3: //undefined op.type = o_undefined; op.dtyp = dt_void; break; case 4: //register op.type = o_reg; op.dtyp = dt_byte; if ((length - p) >= 1) { op.reg = get_byte(cmd.ea + p++); } else { error = 1; } break; case 5: //bool op.type = o_bool; op.dtyp = dt_byte; if ((length - p) >= 1) { op.value = get_byte(cmd.ea + p++); } else { error = 1; } break; case 6: //double op.type = o_imm; op.dtyp = dt_double; if ((length - p) >= 8) { double d = (double)(get_qword(cmd.ea + p)); op.value = d; p += 8; } else { error = 1; } break; case 7: //integer op.type = o_imm; op.dtyp = dt_dword; if ((length - p) >= 4) { op.value = get_long(cmd.ea + p); p += 4; } else { error = 1; } break; case 8: //constant 8 op.type = o_const; op.dtyp = dt_byte; if ((length - p) >= 1) { op.value = get_byte(cmd.ea + p++); } else { error = 1; } break; case 9: //constant 16 op.type = o_const; op.dtyp = dt_word; if ((length - p) >= 2) { op.value = get_word(cmd.ea + p); p += 2; } else { error = 1; } default: //unknown type, will not search for more items if this happens error = 1; } //switch if (error == 0) { //pading out_symbol( ',' ); OutChar( ' ' ); // output extra operand outop(op); } } //while } //case break; case SWFACTION_TRY: //ToDo break; case SWFACTION_DEFINEFUNCTION: // Todo: highlight somehow the function body // this must be written some other place because // every time IDA rephreshes the view a duplicate line appears. :( //describe(cmd.ea + cmd.size, true, "%s {", cmd.segpref ? (char*)cmd.Op1.addr : "<anonymous>"); //describe(cmd.ea + cmd.size + get_word(cmd.ea + cmd.size - 2), true, " }"); break; default:; } term_output_buffer(); // attach a possible user-defined comment to this instruction gl_comm = 1; MakeLine( buf ); //multiline instruction printing switch (cmd.insnpref) { case SWFACTION_CONSTANTPOOL: { uint16 length = get_word(cmd.ea + 1); uint8 c = 0, count = 0; if(cmd.Op1.value == 0) break; //limit printed lines to 499 //IDA does not suport more than 500 per item if (cmd.Op1.value > 498) { cmd.Op1.value = 498; msg ("\nWarning: CONSTANTPOOL instruction ar %X has more that 498 declared constants!\n", cmd.ea); } char line[MAXSTR], buf[MAXSTR]; init_output_buffer(line, sizeof(line)); OutChar( ' ' ); out_char('0', COLOR_NUMBER); out_line(": \"",COLOR_SYMBOL); for (uint16 i = 2; i < length; i++) { c = get_byte(cmd.ea + i + 3); if (c == 0) { if (count++ < (cmd.Op1.value - 1)) { out_line("\"", COLOR_SYMBOL); //terminate buffer for current constant //and print it term_output_buffer(); MakeLine(line); //initialize buffer for next constant init_output_buffer(line, sizeof(line)); OutChar( ' ' ); qsnprintf(buf, MAXSTR, "%d", count); out_line(buf, COLOR_NUMBER); out_line(": \"", COLOR_SYMBOL); } else break; } else { if (is_printable(c)) out_char(c, COLOR_CHAR); else { qsnprintf(buf, MAXSTR, "\\x%02X", c); out_line(buf, COLOR_STRING); } }//else }//for out_char('"',COLOR_SYMBOL); //terminate buffer for last constant //and print it term_output_buffer(); MakeLine(line); } break; } }