//---------------------------------------------------------------------- void out(void) { char buf[MAXSTR]; init_output_buffer(buf, sizeof(buf)); int op; if (!(cmd.SpecialModes & TMS_MODE_USER_PARALLEL)) { if ((cmd.SpecialModes & TMS_MODE_LR) || (cmd.SpecialModes & TMS_MODE_CR)) { out_line(cmd.get_canon_mnem(), COLOR_INSN); out_line((cmd.SpecialModes & TMS_MODE_LR) ? ".lr ":".cr ", COLOR_INSN); } else OutMnem(); } else { // user-defined parallelism out_line("|| ", COLOR_INSN); out_line(cmd.get_canon_mnem(), COLOR_INSN); out_line(" ", COLOR_INSN); } for (op = 0; op < UA_MAXOP; op++) { if (cmd.Operands[op].type == o_void) break; if (op != 0) // not the first operand { if (cmd.Parallel != TMS_PARALLEL_BIT && op == cmd.Parallel) // multi-line instruction { term_output_buffer(); MakeLine(buf); // print the second instruction line init_output_buffer(buf, sizeof(buf)); if (cmd.SpecialModes & TMS_MODE_SIMULATE_USER_PARALLEL) out_line("|| ", COLOR_INSN); else out_line(":: ", COLOR_INSN); const char *insn2 = cmd.get_canon_mnem(); insn2 += strlen(insn2); insn2++; out_line(insn2, COLOR_INSN); } else out_symbol(','); OutChar(' '); } // print the operand out_one_operand(op); } // print immediate values for (op = 0; op < UA_MAXOP; op++) if ( isVoid(cmd.ea, uFlag, op) ) OutImmChar(cmd.Operands[op]); term_output_buffer(); gl_comm = 1; MakeLine(buf); }
//--------------------------------------------------------------------------- uchar putVal(op_t &x, uchar mode, uchar warn) { char str[MAXSTR]; uint32 sv_bufsize = bufsize; char *sv_bufbeg = bufbeg, *sv_ptr = get_output_ptr(); init_output_buffer(str, sizeof(str)); { flags_t sv_uFlag = uFlag; uFlag = 0; OutValue(x, mode); uFlag = sv_uFlag; } out_zero(); init_output_buffer(sv_bufbeg, sv_bufsize); set_output_ptr(sv_ptr); if ( warn) out_tagon(COLOR_ERROR ); { register size_t i; if ( !warn) i = tag_strlen(str ); else i = tag_remove(str, str, 0); if ( chkOutLine(str, i)) return(0 ); } if ( warn) out_tagoff(COLOR_ERROR ); return(1); }
//---------------------------------------------------------------------- void out(void) { char buf[MAXSTR]; // output .org for enties without any labels if ( !has_any_name(uFlag) && helper.altval(cmd.ea) ) { btoa(buf, sizeof(buf), cmd.ip); printf_line(inf.indent, COLSTR("%s %s", SCOLOR_ASMDIR), ash.origin, buf); } 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 ( 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)); 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 ); if( isVoid( cmd.ea, uFlag, 2 ) ) OutImmChar( cmd.Op3 ); term_output_buffer(); gl_comm = 1; MakeLine( buf ); }
//---------------------------------------------------------------------- void idaapi out(void) { char buf[MAXSTR]; init_output_buffer(buf, sizeof(buf)); // output instruction mnemonics char postfix[4]; postfix[0] = '\0'; OutMnem(8, postfix); 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); term_output_buffer(); gl_comm = 1; MakeLine(buf); }
static void before_assert_trap(WasmSourceLocation loc, void* user_data) { Context* ctx = user_data; ctx->in_assert = 1; if (g_verbose) printf("; before assert_trap_%d\n", ctx->assert_trap_count); init_output_buffer(&ctx->buf, INITIAL_OUTPUT_BUFFER_CAPACITY); }
//---------------------------------------------------------------------- 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(',');//вывод разделителя между операндами //если неуказан флаг UAS_NOSPA ставим пробел if(!(ash.uflag & UAS_NOSPA)) OutChar(' '); out_one_operand(1); } if(cmd.Op3.type != o_void) { out_symbol(','); if(!(ash.uflag & UAS_NOSPA)) 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); term_output_buffer(); gl_comm = 1; MakeLine(buf); }
//-------------------------------------------------------------------------- void idaapi cr16c_data(ea_t ea) { char obuf[256]; init_output_buffer(obuf, sizeof(obuf)); int col = 0; uint32 flags = get_flags_novalue(ea); if (isWord(flags)) { out_snprintf("%s %xh", ash.a_word ? ash.a_word : "", get_word(ea)); } else if (isDwrd(flags)) { out_snprintf("%s %xh", ash.a_dword ? ash.a_dword : "", get_long(ea)); } else { //if (isByte(flags)) { int val = get_byte(ea); char ch = ' '; if (val >= 0x20 && val <= 0x7E) { ch = val; } out_snprintf("%s %02xh ; %c", ash.a_byte ? ash.a_byte : "", val, ch); } term_output_buffer(); gl_comm = 1; MakeLine(obuf); return; }
//---------------------------------------------------------------------- // основная выводилка команд void N78K_out(void) { char buf[MAXSTR]; #if IDP_INTERFACE_VERSION > 37 init_output_buffer(buf, sizeof(buf)); // setup the output pointer #else uFlag = getFlags(cmd.ea); 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(isVoid(cmd.ea, uFlag, 0)) OutImmChar(cmd.Op1); if(isVoid(cmd.ea, uFlag, 1)) OutImmChar(cmd.Op2); #if IDP_INTERFACE_VERSION > 37 term_output_buffer(); #else *u_line = '\0'; #endif gl_comm = 1; MakeLine(buf); }
void write_bin_files(void) { lan_blk_t *lbp; token_t *ttab; int ntab; int i; get_tokentable(&ttab, &ntab); for (lbp = lanblockhead; lbp; lbp = lbp->next) { char *cptr = NULL; for (i = 0; i < ntab; i++) { if (ttab[i].type == tok_language && ttab[i].token == lbp->lan) { if (ttab[i].alias) cptr = dup_u2c(WMC_DEFAULT_CODEPAGE, ttab[i].alias); break; } } if(!cptr) internal_error(__FILE__, __LINE__, "Filename vanished for language 0x%0x\n", lbp->lan); init_output_buffer(); output_bin_data( lbp ); cptr = xrealloc( cptr, strlen(cptr) + 5 ); strcat( cptr, ".bin" ); flush_output_buffer( cptr ); free(cptr); } }
// outputs an instruction void idaapi out(void) { char buf[MAXSTR]; init_output_buffer(buf, sizeof(buf)); OutMnem(); 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 ); 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 }
static HRESULT create_writer(IUnknown *stream, IMalloc *imalloc, xml_encoding encoding, IXmlWriterOutput **output) { xmlwriteroutput *writeroutput; HRESULT hr; *output = NULL; if (imalloc) writeroutput = IMalloc_Alloc(imalloc, sizeof(*writeroutput)); else writeroutput = heap_alloc(sizeof(*writeroutput)); if(!writeroutput) return E_OUTOFMEMORY; writeroutput->IXmlWriterOutput_iface.lpVtbl = &xmlwriteroutputvtbl; writeroutput->ref = 1; writeroutput->imalloc = imalloc; if (imalloc) IMalloc_AddRef(imalloc); writeroutput->encoding = encoding; writeroutput->stream = NULL; hr = init_output_buffer(writeroutput); if (FAILED(hr)) { IUnknown_Release(&writeroutput->IXmlWriterOutput_iface); return hr; } IUnknown_QueryInterface(stream, &IID_IUnknown, (void**)&writeroutput->output); *output = &writeroutput->IXmlWriterOutput_iface; TRACE("returning iface %p\n", *output); return S_OK; }
void out(void) { char buf[MAXSTR]; char postfix[MAXSTR]=""; init_output_buffer(buf, sizeof(buf)); /* if we have a load or store instruction, flags are used a bit different */ if (cmd.itype<=ARC_store_instructions) { switch ((cmd.auxpref&6)>>1) { case 0: qstrncat(postfix, "", sizeof(postfix)); break; case 1: qstrncat(postfix, "b", sizeof(postfix)); break; case 2: qstrncat(postfix, "w", sizeof(postfix)); break; default: qstrncat(postfix, "?", sizeof(postfix)); break; } if (cmd.auxpref&1) qstrncat(postfix, ".x", sizeof(postfix)); if (cmd.auxpref&8) qstrncat(postfix, ".a", sizeof(postfix)); if (cmd.auxpref&32) qstrncat(postfix, ".di", sizeof(postfix)); } else if (cmd.auxpref&31)
static void before_module(WasmModule* module, void* user_data) { Context* ctx = user_data; ctx->function_header_offsets = realloc( ctx->function_header_offsets, module->functions.size * sizeof(uint32_t)); int i; uint32_t offset = FUNC_HEADERS_OFFSET(module->globals.size); /* skip past the import headers */ for (i = 0; i < module->imports.size; ++i) offset += FUNC_HEADER_SIZE(module->imports.data[i].args.size); for (i = 0; i < module->functions.size; ++i) { WasmFunction* function = &module->functions.data[i]; ctx->function_header_offsets[i] = offset; offset += FUNC_HEADER_SIZE(function->num_args); } ctx->segment_header_offsets = realloc( ctx->segment_header_offsets, module->segments.size * sizeof(uint32_t)); for (i = 0; i < module->segments.size; ++i) { ctx->segment_header_offsets[i] = offset; offset += SEGMENT_HEADER_SIZE; } ctx->module = module; init_output_buffer(&ctx->buf, INITIAL_OUTPUT_BUFFER_CAPACITY); out_module_header(ctx, module); }
//---------------------------------------------------------------------- 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 }
//---------------------------------------------------------------------- void term_prompted_output(void) { init_output_buffer(NULL, 0); g_bufbeg = NULL; g_bufsize = 0; maxpos = 0; curpos = -1; }
static WasmParserCookie before_assert_return_nan(WasmSourceLocation loc, void* user_data) { Context* ctx = user_data; ctx->in_assert = 1; if (g_verbose) printf("; before assert_return_nan_%d\n", ctx->assert_return_nan_count); init_output_buffer(&ctx->buf, INITIAL_OUTPUT_BUFFER_CAPACITY); out_opcode(&ctx->buf, WASM_OPCODE_SET_LOCAL); out_u8(&ctx->buf, 0, "remapped local index"); return 0; }
static WasmParserCookie before_assert_return(WasmSourceLocation loc, void* user_data) { Context* ctx = user_data; ctx->in_assert = 1; if (g_verbose) printf("; before assert_return_%d\n", ctx->assert_return_count); init_output_buffer(&ctx->buf, INITIAL_OUTPUT_BUFFER_CAPACITY); WasmParserCookie cookie = (WasmParserCookie)ctx->buf.size; out_opcode(&ctx->buf, WASM_OPCODE_I32_EQ); return cookie; }
//---------------------------------------------------------------------- bool change_line(bool main) { *set_output_ptr(bufbeg) = '\0'; outcnt = 0; uchar sv = inf.indent; inf.indent = (uchar)curpos; bool res = MakeLine(bufbeg, main ? -1 : curpos); inf.indent = sv; init_output_buffer(bufbeg, bufsize); // for autocomment with call fmtName return res; }
//---------------------------------------------------------------------- // 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); }
/* #<pydoc> def init_output_buffer(size = MAXSTR): """ This function initialize an output buffer with the given size. It should be called before using any out_xxxx() functions. @return: It returns a string. This string should then be passed to MakeLine(). This function could return None if it failed to create a buffer with the given size. """ pass #</pydoc> */ PyObject *py_init_output_buffer(size_t size = MAXSTR) { PYW_GIL_CHECK_LOCKED_SCOPE(); // Let Python allocate a writable string buffer for us PyObject *py_str = PyString_FromStringAndSize(NULL, size); if ( py_str == NULL ) Py_RETURN_NONE; init_output_buffer(PyString_AsString(py_str), size); return py_str; }
//---------------------------------------------------------------------- void init_prompted_output(char str[MAXSTR*2], uchar pos) { maxpos = inf.margin; // if ( maxpos < 32 ) maxpos = 32; // if ( maxpos > MAXSTR - 4 ) maxpos = MAXSTR - 4; #ifdef __debug__ if ( debugmode == (uchar )-1 && inf.s_showpref && inf.margin == 77 && !inf.binSize) maxpos -= gl_psize; #endif init_output_buffer(bufbeg = str, bufsize = (MAXSTR*2)-STR_PRESERVED); curpos = pos; outcnt = 0; }
//---------------------------------------------------------------------- bool change_line(bool main) { out_zero(); bool overflow = false; if ( g_bufbeg != NULL ) { outcnt = 0; uchar sv = inf.indent; inf.indent = (uchar)curpos; overflow = MakeLine(g_bufbeg, main ? -1 : curpos); inf.indent = sv; init_output_buffer(g_bufbeg, g_bufsize); // for autocomment with call fmtName } return overflow; }
void write_res_file( const char *name ) { lan_blk_t *lbp; int i, j; init_output_buffer(); put_dword( 0 ); /* ResSize */ put_dword( 32 ); /* HeaderSize */ put_word( 0xffff ); /* ResType */ put_word( 0x0000 ); put_word( 0xffff ); /* ResName */ put_word( 0x0000 ); put_dword( 0 ); /* DataVersion */ put_word( 0 ); /* Memory options */ put_word( 0 ); /* Language */ put_dword( 0 ); /* Version */ put_dword( 0 ); /* Characteristics */ for (lbp = lanblockhead; lbp; lbp = lbp->next) { unsigned int data_size = 4 * (lbp->nblk * 3 + 1); unsigned int header_size = 5 * sizeof(unsigned int) + 6 * sizeof(unsigned short); for (i = 0; i < lbp->nblk; i++) { block_t *blk = &lbp->blks[i]; for (j = 0; j < blk->nmsg; j++) data_size += 4 + ((blk->msgs[j]->len * 2 + 3) & ~3); } put_dword( data_size ); /* ResSize */ put_dword( header_size ); /* HeaderSize */ put_word( 0xffff ); /* ResType */ put_word( 0x000b /*RT_MESSAGETABLE*/ ); put_word( 0xffff ); /* ResName */ put_word( 0x0001 ); align_output( 4 ); put_dword( 0 ); /* DataVersion */ put_word( 0x30 ); /* Memory options */ put_word( lbp->lan ); /* Language */ put_dword( lbp->version ); /* Version */ put_dword( 0 ); /* Characteristics */ output_bin_data( lbp ); } flush_output_buffer( name ); }
//---------------------------------------------------------------------- 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 WasmParserCookie before_invoke(WasmSourceLocation loc, const char* invoke_name, int invoke_function_index, void* user_data) { Context* ctx = user_data; if (!ctx->in_assert) { if (g_verbose) printf("; before invoke_%d\n", ctx->invoke_count); init_output_buffer(&ctx->buf, INITIAL_OUTPUT_BUFFER_CAPACITY); } out_opcode(&ctx->buf, WASM_OPCODE_CALL); /* defined functions are always after all imports */ out_leb128(&ctx->buf, ctx->module->imports.size + invoke_function_index, "invoke func index"); return (WasmParserCookie)invoke_function_index; }
//---------------------------------------------------------------------- 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); }