//---------------------------------------------------------------------- void idaapi out(void) { char buf[MAXSTR]; init_output_buffer(buf, sizeof(buf)); OutMnem(); out_one_operand(0); if ( cmd.Op2.type != o_void ) { out_symbol(','); OutChar(' '); out_one_operand(1); } if ( cmd.Op3.type != o_void ) { out_symbol(','); OutChar(' '); out_one_operand(2); } if ( isVoid(cmd.ea, uFlag, 0) ) OutImmChar(cmd.Op1); if ( isVoid(cmd.ea, uFlag, 1) ) OutImmChar(cmd.Op2); term_output_buffer(); gl_comm = 1; MakeLine(buf); }
//---------------------------------------------------------------------- void out(void) { char buf[MAXSTR]; init_output_buffer(buf, sizeof(buf)); const char *postfix = NULL; if ( cmd.auxpref & aux_byte ) postfix = ".b"; else if ( cmd.auxpref & aux_word ) postfix = ".w"; else if ( cmd.auxpref & aux_f ) postfix = "/f"; else if ( cmd.auxpref & aux_ne ) postfix = "/ne"; else if ( cmd.auxpref & aux_eq ) postfix = "/eq"; OutMnem(8, postfix); out_one_operand(0); if ( cmd.Op2.type != o_void ) { out_symbol(','); OutChar(' '); out_one_operand(1); } if ( isVoid(cmd.ea, uFlag, 0) ) OutImmChar(cmd.Op1); if ( isVoid(cmd.ea, uFlag, 1) ) OutImmChar(cmd.Op2); term_output_buffer(); gl_comm = 1; MakeLine(buf); }
// Output an instruction void out(void) { // // print insn mnemonic // char buf[MAXSTR]; init_output_buffer(buf, sizeof(buf)); char postfix[5]; postfix[0] = '\0'; if ( is_jmp_cc(cmd.itype) ) qstrncpy(postfix, ConditionCodes[cmd.auxpref], sizeof(postfix)); OutMnem(8, postfix); // // print insn operands // out_one_operand(0); // output the first operand if ( cmd.Op2.type != o_void ) { out_symbol(','); OutChar(' '); out_one_operand(1); } if ( cmd.Op3.type != o_void ) { out_symbol(','); OutChar(' '); out_one_operand(2); } // output a character representation of the immediate values // embedded in the instruction as comments if ( isVoid(cmd.ea,uFlag,0)) OutImmChar(cmd.Op1 ); if ( isVoid(cmd.ea,uFlag,1)) OutImmChar(cmd.Op2 ); if ( isVoid(cmd.ea,uFlag,2)) OutImmChar(cmd.Op3 ); if ( gr_cmt != NULL ) { OutChar(' '); out_line(ash.cmnt, COLOR_AUTOCMT); OutChar(' '); out_line(gr_cmt, COLOR_AUTOCMT); if ( ash.cmnt2 != NULL ) { OutChar(' '); out_line(ash.cmnt2, COLOR_AUTOCMT); } gr_cmt = NULL; } term_output_buffer(); // terminate the output string gl_comm = 1; // ask to attach a possible user- // defined comment to it MakeLine(buf); // pass the generated line to the // kernel }
//---------------------------------------------------------------------- // generate a text representation of an instruction // the information about the instruction is in the 'cmd' structure void idaapi out(void) { char buf[MAXSTR]; // setup the output pointer init_output_buffer(buf, sizeof(buf)); // output instruction mnemonics OutMnem(); // check for JP/JR instruction with condition code // add the condition on as a pseudo operand if present if ((cmd.itype == SAM8_JR) || ((cmd.itype == SAM8_JP) && (cmd.c_condition != ccNone))) { // sanity check if (cmd.c_condition >= cc_last) { warning("%a (%s): Internal error: bad condition code %i", cmd.ea, cmd.get_canon_mnem(), cmd.c_condition); return; } // output the condition code normally out_keyword(ccNames[cmd.c_condition]); out_symbol(','); OutChar(' '); } // output the first operand if (cmd.Op1.type != o_void) { out_one_operand(0); } // output the second operand if (cmd.Op2.type != o_void) { out_symbol(','); OutChar(' '); out_one_operand(1); } // output the third operand if (cmd.Op3.type != o_void) { out_symbol(','); OutChar(' '); out_one_operand(2); } // terminate the output string term_output_buffer(); // ask to attach a possible user-defined comment to it gl_comm = 1; // pass the generated line to the kernel MakeLine(buf); }
//---------------------------------------------------------------------- static int utfstr(ushort index, const ConstOpis *) { register int i; init_output_buffer(bufbeg, bufsize); i = fmtString(index, maxpos -= curpos, fmt_string, wrtutf); term_output_buffer(); maxpos += curpos; if(i < 0) return(0); qfprintf(myFile, "%s\n", bufbeg); return(++i); }
//---------------------------------------------------------------------- static void idaapi func_header(func_t *f) { char buf[256]; char name[64]; printf_line(0, "# =============== S U B R O U T I N E ======================================="); printf_line(0, ""); get_func_name(f->startEA, name, sizeof(name)); init_output_buffer(buf, sizeof(buf)); out_snprintf("def %s(", name); out_snprintf("...):"); term_output_buffer(); printf_line(0, "%s", buf); printf_line(0, ""); }
//---------------------------------------------------------------------- static void make_new_name(ushort name, ushort subnam, uchar mode, unsigned ip) { char str[MAXNAMELEN]; init_output_buffer(str, sizeof(str)); if ( fmtString(name, sizeof(str)-2, fmt_fullname) ) { trunc: trunc_name(ip, mode & 4); } else if ( (char)mode > 0 ) { register char *p = get_output_ptr(); if ( p >= &str[sizeof(str)-3] ) goto trunc; *p++ = '.'; set_output_ptr(p); if ( fmtString(subnam, &str[sizeof(str)-2] - p, fmt_name) ) goto trunc; } term_output_buffer(); do_name_anyway(ip, convert_clsname(str)); hide_name(ip); }
//---------------------------------------------------------------------- static int outnum(ushort type, const ConstOpis *co) { char str[40]; op_t x; x.value = co->value; x.addr = co->value2; #ifdef __EA64__ x.value = make_ulonglong((uint32)x.value, (uint32)x.addr); #endif x.type = o_imm; x.dtyp = (uchar)(type - 3); x.offb = 0; init_output_buffer(str, sizeof(str)); OutValue(x, OOF_NUMBER | OOF_SIGNED | OOFW_IMM); term_output_buffer(); tag_remove(str, str, 0); qfprintf(myFile, "value = %s\n", str); return(1); }
//---------------------------------------------------------------------- // основная выводилка команд void idaapi C39_out(void) { char buf[MAXSTR]; #if IDP_INTERFACE_VERSION > 37 init_output_buffer(buf, sizeof(buf)); // setup the output pointer #else u_line = buf; #endif // выведем мнемонику OutMnem(); // выведем первый операнд if(cmd.Op1.type!=o_void)out_one_operand(0); // выведем второй операнд if(cmd.Op2.type != o_void){ out_symbol(','); OutChar(' '); out_one_operand(1); // выведем третий операнд if(cmd.Op3.type != o_void){ out_symbol(','); OutChar(' '); out_one_operand(2); } } // выведем непосредственные данные, если они есть if ( isVoid(cmd.ea,uFlag,0) ) OutImmChar(cmd.Op1); if ( isVoid(cmd.ea,uFlag,1) ) OutImmChar(cmd.Op2); if ( isVoid(cmd.ea,uFlag,2) ) OutImmChar(cmd.Op3); // завершим строку #if IDP_INTERFACE_VERSION > 37 term_output_buffer(); #else *u_line = '\0'; #endif gl_comm = 1; MakeLine(buf); }
void out(void) { char buf[MAXSTR]; init_output_buffer(buf, sizeof(buf)); // setup the output pointer OutMnem(); // output instruction mnemonics out_one_operand(0); // output the first operand if ( cmd.Op2.type != o_void) { out_symbol(','); OutChar(' '); out_one_operand(1); // output the second operand } if ( cmd.Op3.type != o_void) { out_symbol(','); OutChar(' '); out_one_operand(2); // output the third operand } // output a character representation of the immediate values // embedded in the instruction as comments if ( isVoid(cmd.ea,uFlag,0) ) OutImmChar(cmd.Op1); if ( isVoid(cmd.ea,uFlag,1) ) OutImmChar(cmd.Op2); if ( isVoid(cmd.ea,uFlag,2) ) OutImmChar(cmd.Op3); term_output_buffer(); // terminate the output string gl_comm = 1; // ask to attach a possible user- // defined comment to it MakeLine(buf); // pass the generated line to the // kernel }
/* #<pydoc> def term_output_buffer(): """Use this function to terminate an output buffer.""" pass #</pydoc> */ void py_term_output_buffer() { term_output_buffer(); }
//---------------------------------------------------------------------- void idaapi cr16c_out(void) { char str[MAXSTR]; //MAXSTR is an IDA define from pro.h init_output_buffer(str, sizeof(str)); OutMnem(12); //first we output the mnemonic switch(cmd.auxpref) { case ooType0: //no operands break; case ooType1: //4,0x444(r0) ->1,20 out_one_operand(1); out_symbol(','); out_one_operand(2); out_one_operand(0); break; case ooType2: //4 ->0 out_one_operand(0); break; case ooType3: //6(r5), r1 ->20,1 out_one_operand(2); out_one_operand(0); out_symbol(','); out_one_operand(1); break; case ooType4: //$4,0x444 ->1,0 out_one_operand(1); out_symbol(','); out_one_operand(0); break; case ooType5: //0x66666, r5 ->0,1 out_one_operand(0); out_symbol(','); out_one_operand(1); break; case ooType6: //$7, [r12]0x26666 ->1,[2]0 out_one_operand(1); out_symbol(','); out_symbol('['); out_one_operand(2); out_symbol(']'); out_one_operand(0); break; case ooType7: //$7, [r12]0x26666(r3,r2) out_one_operand(1); out_symbol(','); out_symbol('['); out_one_operand(3); out_symbol(']'); out_one_operand(2); out_one_operand(0); break; case ooType8: //[r12]0x26666(r3,r2), r0 out_symbol('['); out_one_operand(3); out_symbol(']'); out_one_operand(2); out_one_operand(0); out_symbol(','); out_one_operand(1); break; case ooType9: //[r12]0x26666,R3 ->[2]0,1 out_symbol('['); out_one_operand(2); out_symbol(']'); out_one_operand(0); out_symbol(','); out_one_operand(1); break; case ooType10: //x,y,z ->0,1,2 out_one_operand(0); out_symbol(','); out_one_operand(1); out_symbol(','); out_one_operand(2); break; case ooType11: //4 ->2 out_one_operand(2); break; case ooType12: //y,x{,z} ->1,0{,2} out_one_operand(1); out_symbol(','); out_one_operand(0); if(cmd.Op3.type != o_void) { out_symbol(','); out_one_operand(2); } break; default: if(cmd.Op1.type != o_void) { out_one_operand(0); } out_snprintf(" , "); if(cmd.Op2.type != o_void) { //then there is an argument to print out_one_operand(1); } out_snprintf(" , "); if(cmd.Op3.type != o_void) { //then there is an argument to print out_one_operand(2); } } term_output_buffer(); gl_comm = 1; //we want comments! MakeLine(str); //output the line with default indentation }
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; } }
//---------------------------------------------------------------------- void out(void) { char buf[MAXSTR]; init_output_buffer(buf, sizeof(buf)); // output instruction mnemonics char postfix[10]; postfix[0] = '\0'; OutMnem(8); bool comma = out_one_operand(0); if ( cmd.Op2.type != o_void ) { if ( comma ) out_symbol(','); out_one_operand(1); } if ( cmd.Op3.type != o_void ) { out_symbol(','); out_one_operand(2); } if ( isVoid(cmd.ea, uFlag, 0) ) OutImmChar(cmd.Op1); if ( isVoid(cmd.ea, uFlag, 1) ) OutImmChar(cmd.Op2); if ( isVoid(cmd.ea, uFlag, 3) ) OutImmChar(cmd.Op3); switch ( cmd.itype ) { case OAK_Dsp_callr: case OAK_Dsp_ret: case OAK_Dsp_br: case OAK_Dsp_call: case OAK_Dsp_reti: case OAK_Dsp_brr: case OAK_Dsp_shfc: case OAK_Dsp_shr: case OAK_Dsp_shr4: case OAK_Dsp_shl: case OAK_Dsp_shl4: case OAK_Dsp_ror: case OAK_Dsp_rol: case OAK_Dsp_clr: case OAK_Dsp_not: case OAK_Dsp_neg: case OAK_Dsp_rnd: case OAK_Dsp_pacr: case OAK_Dsp_clrr: case OAK_Dsp_inc: case OAK_Dsp_dec: case OAK_Dsp_copy: case OAK_Dsp_maxd: case OAK_Dsp_max: case OAK_Dsp_min: qsnprintf(postfix, sizeof(postfix), "%s%s%s", ( (cmd.auxpref & aux_comma_cc) ? ", ": ""), \ cc_text[cmd.auxpref & aux_cc], \ ( (cmd.auxpref & aux_iret_context) ? ", context": "") ); out_line(postfix, COLOR_REG); break; } term_output_buffer(); gl_comm = 1; MakeLine(buf); }
// output an instruction and its operands void idaapi out(void) { char buf[MAXSTR]; init_output_buffer(buf, sizeof(buf)); // setup the output pointer // if this DSP instruction in executed in parallel with a NOP instruction // (example: nop || machi r1, r2), first print the NOP. if ( cmd.segpref & NEXT_INSN_PARALLEL_DSP ) { out_line("nop", COLOR_INSN); OutChar(' '); out_symbol('|'); out_symbol('|'); OutChar(' '); } char postfix[3]; // postfix to eventually insert after the insn name postfix[0] = '\0'; // postfix is null by default // use synthetic option is selected if ( use_synthetic_insn() ) { if ( cmd.segpref & SYNTHETIC_SHORT ) qstrncpy(postfix, (cmd.itype == m32r_ldi ? "8" : ".s"), sizeof(postfix)); if ( cmd.segpref & SYNTHETIC_LONG ) qstrncpy(postfix, (cmd.itype == m32r_ldi ? "16" : ".l"), sizeof(postfix)); } OutMnem(8, postfix); out_one_operand(0); // output the first operand if ( cmd.Op2.type != o_void ) { out_symbol(','); OutChar(' '); out_one_operand(1); // output the second operand } if ( cmd.Op3.type != o_void ) { out_symbol(','); OutChar(' '); out_one_operand(2); // output the third operand } // output a character representation of the immediate values // embedded in the instruction as comments if ( isVoid(cmd.ea,uFlag,0) ) OutImmChar(cmd.Op1); if ( isVoid(cmd.ea,uFlag,1) ) OutImmChar(cmd.Op2); if ( isVoid(cmd.ea,uFlag,2) ) OutImmChar(cmd.Op3); // print a parallel NOP instruction unless the current instruction // is either push or pop (in this special case, nop cannot be executed in //) if ( (cmd.itype != m32r_push && cmd.itype != m32r_pop) && cmd.segpref & NEXT_INSN_PARALLEL_NOP ) { // don't print NOP if the instruction was ld/st reg, fp, and has been converted to ld/st reg, @(arg, fp) // (in other words, in the second operand is a stack variable). // because the o_displ form of ld/st insn is 32 bits, and cannot handle a parallel nop. if ( (cmd.itype != m32r_ld && cmd.itype != m32r_st) || !isStkvar1(uFlag) ) { if ( cmd.Op1.type != o_void ) OutChar(' '); out_symbol('|'); out_symbol('|'); OutChar(' '); out_line("nop", COLOR_INSN); } } if ( cmd.segpref & NEXT_INSN_PARALLEL_OTHER ) { if ( cmd.Op1.type != o_void ) OutChar(' '); out_symbol('|'); out_symbol('|'); out_symbol('\\'); } term_output_buffer(); // terminate the output string gl_comm = 1; // ask to attach a possible user- // defined comment to it MakeLine(buf); // pass the generated line to the // kernel }
int dline_add(dline_t * dl, ea_t ea, char options) { char buf[256]; char tmp[256]; char dis[256]; char addr[30]; char * dll; int len; flags_t f; buf[0] = '\0'; f = getFlags(ea); generate_disasm_line(ea, dis, sizeof(dis)); decode_insn(ea); init_output_buffer(buf, sizeof(buf)); // Adds block label if (has_dummy_name(f)) { get_nice_colored_name(ea,tmp,sizeof(tmp),GNCN_NOSEG|GNCN_NOFUNC); out_snprintf("%s", tmp); out_line(":\n", COLOR_DATNAME); } if (options) { qsnprintf(addr, sizeof(addr), "%a", ea); out_snprintf("%s ", addr); } out_insert(get_output_ptr(), dis); term_output_buffer(); len = strlen(buf); if (dl->available < (len+3)) { dll = (char *)qrealloc(dl->lines, sizeof(char*) * (dl->num+len+256)); if (!dll) return -1; dl->available = len+256; dl->lines = dll; } if (dl->num) { dl->lines[dl->num] = '\n'; dl->num++; } memcpy(&dl->lines[dl->num], buf, len); dl->available -= len+1; dl->num += len; dl->lines[dl->num] = '\0'; return 0; }
//---------------------------------------------------------------------- void idaapi out(void) { char buf[MAXSTR]; init_output_buffer(buf, sizeof(buf)); OutMnem(); out_one_operand(0); if ( cmd.Op2.type != o_void ) { out_symbol(','); OutChar(' '); out_one_operand(1); if ( cmd.IsParallel ) { // new line for Parallel instructions term_output_buffer(); MakeLine(buf); init_output_buffer(buf, sizeof(buf)); out_line("|| ", COLOR_INSN); const char *insn2 = NULL; switch ( cmd.itype ) { case TMS320C54_ld_mac: insn2 = "mac "; break; case TMS320C54_ld_macr: insn2 = "macr "; break; case TMS320C54_ld_mas: insn2 = "mas "; break; case TMS320C54_ld_masr: insn2 = "masr "; break; case TMS320C54_st_add: insn2 = "add "; break; case TMS320C54_st_sub: insn2 = "sub "; break; case TMS320C54_st_ld: insn2 = "ld "; break; case TMS320C54_st_mpy: insn2 = "mpy "; break; case TMS320C54_st_mac: insn2 = "mac "; break; case TMS320C54_st_macr: insn2 = "macr "; break; case TMS320C54_st_mas: insn2 = "mas "; break; case TMS320C54_st_masr: insn2 = "masr "; break; default: warning("interr: out parallel instruction"); } out_line(insn2, COLOR_INSN); } if ( cmd.Op3.type != o_void ) { if ( !cmd.IsParallel ) { out_symbol(','); OutChar(' '); } out_one_operand(2); if ( cmd.Op4_type != 0 ) { out_symbol(','); OutChar(' '); switch ( cmd.Op4_type ) { case o_reg: out_register(ph.regNames[cmd.Op4_value]); break; case o_cond8: out_cond8(cmd.Op4_value); break; default: break; } } } } if ( isVoid(cmd.ea, uFlag, 0) ) OutImmChar(cmd.Op1); if ( isVoid(cmd.ea, uFlag, 1) ) OutImmChar(cmd.Op2); if ( isVoid(cmd.ea, uFlag, 2) ) OutImmChar(cmd.Op3); term_output_buffer(); gl_comm = 1; MakeLine(buf); }