//------------------------------------------------------------------------- idarpc_stream_t *init_client_irs(const char *hostname, int port_number) { if ( hostname[0] == '\0' ) { warning("AUTOHIDE NONE\n" "Please specify the hostname in Debugger, Process options"); return NULL; } if ( !init_irs_layer() ) { warning("AUTOHIDE NONE\n" "Could not initialize sockets: %s", winerr(get_network_error())); return NULL; } struct addrinfo ai, *res, *e; char port[33]; // try to enumerate all possible addresses memset(&ai,0, sizeof(ai)); ai.ai_flags = AI_CANONNAME; ai.ai_family = PF_UNSPEC; ai.ai_socktype = SOCK_STREAM; qsnprintf(port, sizeof(port), "%d", port_number); bool ok = false; const char *errstr = NULL; SOCKET sock = INVALID_SOCKET; int code = getaddrinfo(hostname, port, &ai, &res); if ( code != 0 ) { // failed to resolve the name errstr = gai_strerror(code); } else { for ( e = res; !ok && e != NULL; e = e->ai_next ) { char uaddr[INET6_ADDRSTRLEN+1]; char uport[33]; if ( getnameinfo(e->ai_addr, e->ai_addrlen, uaddr, sizeof(uaddr), uport, sizeof(uport), NI_NUMERICHOST | NI_NUMERICSERV) != 0 ) { NETERR: errstr = winerr(get_network_error()); continue; } sock = socket(e->ai_family, e->ai_socktype, e->ai_protocol); if ( sock == INVALID_SOCKET ) goto NETERR; setup_irs((idarpc_stream_t*)sock); if ( connect(sock, e->ai_addr, e->ai_addrlen) == SOCKET_ERROR ) { errstr = winerr(get_network_error()); closesocket(sock); continue; } ok = true; } freeaddrinfo(res); } if ( !ok ) { msg("Could not connect to %s: %s\n", hostname, errstr); return NULL; } return (idarpc_stream_t*)sock; }
static bool write_xbm_image(const QImage &sourceImage, QIODevice *device, const QString &fileName) { QImage image = sourceImage; int w = image.width(); int h = image.height(); int i; QString s = fileName; // get file base name int msize = s.length() + 100; char *buf = new char[msize]; qsnprintf(buf, msize, "#define %s_width %d\n", s.toAscii().data(), w); device->write(buf, qstrlen(buf)); qsnprintf(buf, msize, "#define %s_height %d\n", s.toAscii().data(), h); device->write(buf, qstrlen(buf)); qsnprintf(buf, msize, "static char %s_bits[] = {\n ", s.toAscii().data()); device->write(buf, qstrlen(buf)); if (image.format() != QImage::Format_MonoLSB) image = image.convertToFormat(QImage::Format_MonoLSB); bool invert = qGray(image.color(0)) < qGray(image.color(1)); char hexrep[16]; for (i=0; i<10; i++) hexrep[i] = '0' + i; for (i=10; i<16; i++) hexrep[i] = 'a' -10 + i; if (invert) { char t; for (i=0; i<8; i++) { t = hexrep[15-i]; hexrep[15-i] = hexrep[i]; hexrep[i] = t; } } int bcnt = 0; register char *p = buf; int bpl = (w+7)/8; for (int y = 0; y < h; ++y) { uchar *b = image.scanLine(y); for (i = 0; i < bpl; ++i) { *p++ = '0'; *p++ = 'x'; *p++ = hexrep[*b >> 4]; *p++ = hexrep[*b++ & 0xf]; if (i < bpl - 1 || y < h - 1) { *p++ = ','; if (++bcnt > 14) { *p++ = '\n'; *p++ = ' '; *p = '\0'; if ((int)qstrlen(buf) != device->write(buf, qstrlen(buf))) { delete [] buf; return false; } p = buf; bcnt = 0; } } } } #if defined(_MSC_VER) && _MSC_VER >= 1400 strcpy_s(p, sizeof(" };\n"), " };\n"); #else strcpy(p, " };\n"); #endif if ((int)qstrlen(buf) != device->write(buf, qstrlen(buf))) { delete [] buf; return false; } delete [] buf; return true; }
char * ctree_dumper_t::parse_ctree_item(citem_t *item, char *buf, int bufsize) const { char *ptr = buf; char *endp = buf + bufsize; // Each node will have the element type at the first line APPEND(ptr, endp, get_ctype_name(item->op)); const cexpr_t *e = (const cexpr_t *)item; const cinsn_t *i = (const cinsn_t *)item; // For some item types, display additional information switch (item->op) { case cot_call: char buf[MAXSTR]; if (e->x->op == cot_obj) { if (get_func_name(e->x->obj_ea, buf, sizeof(buf)) == NULL) ptr += qsnprintf(ptr, endp - ptr, " sub_%a", e->x->obj_ea); else ptr += qsnprintf(ptr, endp - ptr, " %s", buf); } break; case cot_ptr: // *x case cot_memptr: // x->m // Display access size for pointers ptr += qsnprintf(ptr, endp - ptr, ".%d", e->ptrsize); if (item->op == cot_ptr) break; case cot_memref: // x.m // Display member offset for structure fields ptr += qsnprintf(ptr, endp - ptr, " (m=%d)", e->m); break; case cot_obj: // v case cot_var: // l // Display object size for local variables and global data ptr += qsnprintf(ptr, endp - ptr, ".%d", e->refwidth); case cot_num: // n case cot_helper: // arbitrary name case cot_str: // string constant // Display helper names and number values APPCHAR(ptr, endp, ' '); e->print1(ptr, endp - ptr, NULL); tag_remove(ptr, ptr, 0); ptr = tail(ptr); break; case cit_goto: // Display target label number for gotos ptr += qsnprintf(ptr, endp - ptr, " LABEL_%d", i->cgoto->label_num); break; case cit_asm: // Display instruction block address and size for asm-statements ptr += qsnprintf(ptr, endp - ptr, " %a.%" FMT_Z, *i->casm->begin(), i->casm->size()); break; default: break; } // The second line of the node contains the item address ptr += qsnprintf(ptr, endp - ptr, ";ea->%a", item->ea); if ( item->is_expr() && !e->type.empty() ) { // For typed expressions, the third line will have // the expression type in human readable form APPCHAR(ptr, endp, ';'); qstring out; if (e->type.print(&out)) { APPEND(ptr, endp, out.c_str()); } else { // could not print the type? APPCHAR(ptr, endp, '?'); APPZERO(ptr, endp); } if(e->type.is_ptr()) { tinfo_t ptr_rem = ::remove_pointer(e->type); if(ptr_rem.is_struct()) { qstring typenm; ptr_rem.print(&typenm, "prefix ", 0, 0, PRTYPE_MULTI | PRTYPE_TYPE | PRTYPE_SEMI); } } } return buf; }
static void op_emu(op_t& x, int fIsLoad) { char szLabel[128]; cref_t ftype; ea_t ea; switch (x.type) { case o_reg: case o_phrase: return; case o_imm: if (!fIsLoad) break; op_imm(cmd.ea); return; case o_displ: case o_mem: switch (cmd.itype) { case M8B_IORD: case M8B_IOWR: case M8B_IOWX: case M8B_IPRET: ea = toIOP(x.addr); if (ea != BADADDR) { ua_dodata2(x.offb, ea, x.dtyp); if (!fIsLoad) doVar(ea); ua_add_dref(x.offb, ea, cmd.itype == M8B_IORD ? dr_R : dr_W); } break; default: ea = toRAM(x.addr); if (ea != BADADDR) { if (!has_any_name(get_flags_novalue(ea))) { qsnprintf(szLabel, sizeof(szLabel), "ram_%0.2X", x.addr); set_name(ea, szLabel, SN_NOWARN); } ua_dodata2(x.offb, ea, x.dtyp); if (!fIsLoad) doVar(ea); ua_add_dref(x.offb, ea, cmd.itype == M8B_IORD ? dr_R : dr_W); } } return; case o_near: ea = toROM(x.addr); if (ea != BADADDR) { switch (cmd.itype) { case M8B_INDEX: if (!has_any_name(get_flags_novalue(ea))) { qsnprintf(szLabel, sizeof(szLabel), "tbl_%0.4X", x.addr); set_name(ea, szLabel, SN_NOWARN); } ua_add_dref(x.offb, ea, dr_R); break; default: ftype = fl_JN; if (InstrIsSet(cmd.itype, CF_CALL)) { if (!func_does_return(ea)) fFlow = false; ftype = fl_CN; } ua_add_cref(x.offb, ea, ftype); } } return; } warning("%a: %s,%d: bad optype %d", cmd.ea, cmd.get_canon_mnem(), x.n, x.type); }
// Display a graph node. Feel free to modify this function to fine tune the node display. char * idaapi cfunc_graph_t::get_node_label(int n, char *buf, int bufsize) { char *ptr = buf; char *endp = buf + bufsize; // Get the corresponding ctree item const citem_t *item = items[n]; // Each node will have the element type at the first line APPEND(ptr, endp, get_ctype_name(item->op)); const cexpr_t *e = (const cexpr_t *)item; const cinsn_t *i = (const cinsn_t *)item; // For some item types, display additional information switch ( item->op ) { case cot_ptr : // *x case cot_memptr : // x->m // Display access size for pointers ptr += qsnprintf(ptr, endp-ptr, ".%d", e->ptrsize); if ( item->op == cot_ptr ) break; case cot_memref : // x.m // Display member offset for structure fields ptr += qsnprintf(ptr, endp-ptr, " (m=%d)", e->m); break; case cot_obj : // v case cot_var : // l // Display object size for local variables and global data ptr += qsnprintf(ptr, endp-ptr, ".%d", e->refwidth); case cot_num : // n case cot_helper : // arbitrary name case cot_str : // string constant // Display helper names and number values APPCHAR(ptr, endp, ' '); e->print1(ptr, endp-ptr, NULL); tag_remove(ptr, ptr, 0); ptr = tail(ptr); break; case cit_goto: // Display target label number for gotos ptr += qsnprintf(ptr, endp-ptr, " LABEL_%d", i->cgoto->label_num); break; case cit_asm: // Display instruction block address and size for asm-statements ptr += qsnprintf(ptr, endp-ptr, " %a.%"FMT_Z, *i->casm->begin(), i->casm->size()); break; default: break; } // The second line of the node contains the item address ptr += qsnprintf(ptr, endp-ptr, "\nea: %a", item->ea); if ( item->is_expr() && !e->type.empty() ) { // For typed expressions, the third line will have // the expression type in human readable form APPCHAR(ptr, endp, '\n'); if ( print_type_to_one_line(ptr, endp-ptr, idati, e->type.u_str()) != T_NORMAL ) { // could not print the type? APPCHAR(ptr, endp, '?'); APPZERO(ptr, endp); } if(e->type.is_ptr()) { typestring ptr_rem = remove_pointer(e->type); if(ptr_rem.is_struct()) { qstring typenm; print_type_to_qstring(&typenm, "prefix ", 0,0, PRTYPE_MULTI | PRTYPE_TYPE | PRTYPE_SEMI, idati, ptr_rem.u_str()); // print_type_to_one_line(ptr, endp-ptr, idati, ptr_rem.u_str()); } } } return buf; }
//------------------------------------------------------------------------- // Converts a Python variable into an IDC variable // This function returns on one CIP_XXXX int pyvar_to_idcvar( const ref_t &py_var, idc_value_t *idc_var, int *gvar_sn) { PYW_GIL_CHECK_LOCKED_SCOPE(); // None / NULL if ( py_var == NULL || py_var.o == Py_None ) { idc_var->set_long(0); } // Numbers? else if ( PyW_GetNumberAsIDC(py_var.o, idc_var) ) { return CIP_OK; } // String else if ( PyString_Check(py_var.o) ) { idc_var->_set_string(PyString_AsString(py_var.o), PyString_Size(py_var.o)); } // Boolean else if ( PyBool_Check(py_var.o) ) { idc_var->set_long(py_var.o == Py_True ? 1 : 0); } // Float else if ( PyFloat_Check(py_var.o) ) { double dresult = PyFloat_AsDouble(py_var.o); ieee_realcvt((void *)&dresult, idc_var->e, 3); idc_var->vtype = VT_FLOAT; } // void* else if ( PyCObject_Check(py_var.o) ) { idc_var->set_pvoid(PyCObject_AsVoidPtr(py_var.o)); } // Python list? else if ( PyList_CheckExact(py_var.o) || PyW_IsSequenceType(py_var.o) ) { // Create the object VarObject(idc_var); // Determine list size and type bool is_seq = !PyList_CheckExact(py_var.o); Py_ssize_t size = is_seq ? PySequence_Size(py_var.o) : PyList_Size(py_var.o); bool ok = true; qstring attr_name; // Convert each item for ( Py_ssize_t i=0; i<size; i++ ) { // Get the item ref_t py_item; if ( is_seq ) py_item = newref_t(PySequence_GetItem(py_var.o, i)); else py_item = borref_t(PyList_GetItem(py_var.o, i)); // Convert the item into an IDC variable idc_value_t v; ok = pyvar_to_idcvar(py_item, &v, gvar_sn) >= CIP_OK; if ( ok ) { // Form the attribute name newref_t py_int(PyInt_FromSsize_t(i)); ok = PyW_ObjectToString(py_int.o, &attr_name); if ( !ok ) break; // Store the attribute VarSetAttr(idc_var, attr_name.c_str(), &v); } if ( !ok ) break; } return ok ? CIP_OK : CIP_FAILED; } // Dictionary: we convert to an IDC object else if ( PyDict_Check(py_var.o) ) { // Create an empty IDC object VarObject(idc_var); // Get the dict.items() list newref_t py_items(PyDict_Items(py_var.o)); // Get the size of the list qstring key_name; bool ok = true; Py_ssize_t size = PySequence_Size(py_items.o); for ( Py_ssize_t i=0; i<size; i++ ) { // Get item[i] -> (key, value) PyObject *py_item = PyList_GetItem(py_items.o, i); // Extract key/value newref_t key(PySequence_GetItem(py_item, 0)); newref_t val(PySequence_GetItem(py_item, 1)); // Get key's string representation PyW_ObjectToString(key.o, &key_name); // Convert the attribute into an IDC value idc_value_t v; ok = pyvar_to_idcvar(val, &v, gvar_sn) >= CIP_OK; if ( ok ) { // Store the attribute VarSetAttr(idc_var, key_name.c_str(), &v); } if ( !ok ) break; } return ok ? CIP_OK : CIP_FAILED; } // Possible function? else if ( PyCallable_Check(py_var.o) ) { idc_var->clear(); idc_var->vtype = VT_FUNC; idc_var->funcidx = -1; // Does not apply return CIP_OK; } // Objects: // - pyidc_cvt objects: int64, byref, opaque // - other python objects else { // Get the type int cvt_id = get_pyidc_cvt_type(py_var.o); switch ( cvt_id ) { // // INT64 // case PY_ICID_INT64: { // Get the value attribute ref_t attr(PyW_TryGetAttrString(py_var.o, S_PY_IDCCVT_VALUE_ATTR)); if ( attr == NULL ) return false; idc_var->set_int64(PyLong_AsLongLong(attr.o)); return CIP_OK; } // // BYREF // case PY_ICID_BYREF: { // BYREF always require this parameter if ( gvar_sn == NULL ) return CIP_FAILED; // Get the value attribute ref_t attr(PyW_TryGetAttrString(py_var.o, S_PY_IDCCVT_VALUE_ATTR)); if ( attr == NULL ) return CIP_FAILED; // Create a global variable char buf[MAXSTR]; qsnprintf(buf, sizeof(buf), S_PY_IDC_GLOBAL_VAR_FMT, *gvar_sn); idc_value_t *gvar = add_idc_gvar(buf); // Convert the python value into the IDC global variable bool ok = pyvar_to_idcvar(attr, gvar, gvar_sn) >= CIP_OK; if ( ok ) { (*gvar_sn)++; // Create a reference to this global variable VarRef(idc_var, gvar); } return ok ? CIP_OK : CIP_FAILED; } // // OPAQUE // case PY_ICID_OPAQUE: { if ( !wrap_PyObject_ptr(py_var, idc_var) ) return CIP_FAILED; return CIP_OK_OPAQUE; } // // Other objects // default: // A normal object? newref_t py_dir(PyObject_Dir(py_var.o)); Py_ssize_t size = PyList_Size(py_dir.o); if ( py_dir == NULL || !PyList_Check(py_dir.o) || size == 0 ) return CIP_FAILED; // Create the IDC object VarObject(idc_var); for ( Py_ssize_t i=0; i<size; i++ ) { borref_t item(PyList_GetItem(py_dir.o, i)); const char *field_name = PyString_AsString(item.o); if ( field_name == NULL ) continue; size_t len = strlen(field_name); // Skip private attributes if ( (len > 2 ) && (strncmp(field_name, "__", 2) == 0 ) && (strncmp(field_name+len-2, "__", 2) == 0) ) { continue; } idc_value_t v; // Get the non-private attribute from the object newref_t attr(PyObject_GetAttrString(py_var.o, field_name)); if (attr == NULL // Convert the attribute into an IDC value || pyvar_to_idcvar(attr, &v, gvar_sn) < CIP_OK) { return CIP_FAILED; } // Store the attribute VarSetAttr(idc_var, field_name, &v); } } } return CIP_OK; }
int idaapi emu() { char szLabel[MAXSTR]; insn_t saved; segment_t* pSegment; ea_t ea, length, offset; flags_t flags; uint32 dwFeature, i; dwFeature = cmd.get_canon_feature(); fFlow = !(dwFeature & CF_STOP); if (dwFeature & CF_USE1) op_emu(cmd.Op1, 1); if (dwFeature & CF_USE2) op_emu(cmd.Op2, 1); if (dwFeature & CF_CHG1) op_emu(cmd.Op1, 0); if (dwFeature & CF_CHG2) op_emu(cmd.Op2, 0); saved = cmd; switch (cmd.itype) { case M8B_MOV: if (!cmd.Op1.is_reg(rPSP)) break; case M8B_SWAP: if (cmd.itype == M8B_SWAP && !cmd.Op2.is_reg(rDSP)) break; for (i = 0; i < 5; ++i) { ea = decode_prev_insn(cmd.ea); if (ea == BADADDR) break; if (cmd.itype == M8B_MOV && cmd.Op1.is_reg(rA) && cmd.Op2.type == o_imm) { ea = toRAM(cmd.Op2.value); if (ea != BADADDR) { qsnprintf(szLabel, sizeof(szLabel), "%s_%0.2X", cmd.itype == M8B_MOV ? "psp" : "dsp", cmd.Op2.value); ua_add_dref(cmd.Op2.offb, ea, dr_O); set_name(ea, szLabel, SN_NOWARN); } break; } } break; case M8B_JACC: pSegment = getseg(cmd.ea); if (!pSegment) break; length = pSegment->endEA - cmd.ea; if (length > 256) length = 256; for (offset = 2; offset < length; offset += 2) { ea = toROM(saved.Op1.addr + offset); if (ea == BADADDR) break; flags = getFlags(ea); if (!hasValue(flags) || (has_any_name(flags) || hasRef(flags)) || !create_insn(ea)) break; switch (cmd.itype) { case M8B_JMP: case M8B_RET: case M8B_RETI: case M8B_IPRET: add_cref(saved.ea, ea, fl_JN); break; default: offset = length; } } break; case M8B_IORD: case M8B_IOWR: case M8B_IOWX: for (i = 0; i < 5; ++i) { ea = (saved.itype == M8B_IORD) ? decode_insn(cmd.ea + cmd.size) : decode_prev_insn(cmd.ea); if (ea == BADADDR) break; if (cmd.Op1.is_reg(rA) && cmd.Op2.type == o_imm) { qsnprintf(szLabel, sizeof(szLabel), "[A=%0.2Xh] ", cmd.Op2.value); if (get_portbits_sym(szLabel + qstrlen(szLabel), saved.Op1.addr, cmd.Op2.value)) set_cmt(saved.ea, szLabel, false); break; } } } cmd = saved; if ((cmd.ea & 0xFF) == 0xFF) { switch (cmd.itype) { case M8B_RET: case M8B_RETI: case M8B_XPAGE: break; default: QueueMark(Q_noValid, cmd.ea); } } if (fFlow) ua_add_cref(0, cmd.ea + cmd.size, fl_F); return 1; }
//-------------------------------------------------------------------------- // Generate text for the current location int ida_export class_place_t__generate( const cp_t *ths, void *ud, char *lines[], int maxsize, int *default_lnnum, color_t *prefix_color, bgcolor_t *bg_color) { strvec_t &sv = *(strvec_t *)ud; uval_t idx = ths->idx; if ( idx > get_last_class_idx() || maxsize <= 0 ) return 0; char name[MAXNAMESIZE]; tid_t tid = get_class_by_idx(idx); if (tid==BADNODE) return 0; switch (ths->section) { case 0: if (get_class_name(tid, name, MAXNAMESIZE)) { char line[MAXSTR]; class_t * clas = get_class(tid); if(!clas) return 0; if (clas->parents_tid.size()) qsnprintf(line, MAXSTR, "class %s: derived from: 0x%p", name, clas->parents_tid.front()); else qsnprintf(line, MAXSTR, "class %s", name ); lines[0] = qstrdup(line); *bg_color = 0xC0C0FF; } break; case 1: { char line[MAXSTR]; class_t * clas = get_class(tid); if(!clas) return 0; if (clas->virt_table_ea != BADADDR) qsnprintf(line, MAXSTR, "vftable: %p", clas->virt_table_ea); else qsnprintf(line, MAXSTR, "no virtual table"); lines[0] = qstrdup(line); *bg_color = 0xC0FFC0; } break; case 2: { char *line; class_t * clas = get_class(tid); if(!clas) return 0; ea_t ea = BADADDR; if (clas->functions_ea.size() && ths->subsection<=clas->functions_ea.size()) ea = clas->functions_ea[ths->subsection]; if (ea!=BADADDR) { qstring tmpline; get_colored_long_name(&tmpline, ea); qtype type; qtype fields; if (!get_tinfo(ea, &type, &fields)) { if (!guess_func_tinfo(get_func(ea), &type, &fields)) goto pokracuj; } line = qstrdup(tmpline.c_str()); print_type_to_one_line(line, MAXSTR, idati, type.c_str(), line, 0, fields.c_str(), 0); pokracuj: ; } else qsnprintf(line, MAXSTR, "bad func"); lines[0] = qstrdup(line); *bg_color = 0xC0FFFF; } break; } //*prefix_color = sv[idx%sv.size()].color; //*bg_color = sv[idx%sv.size()].bgcolor; *default_lnnum = 0; return 1; // generated one line //setup_makeline(-1, ..., save_line_in_array, 0) //finish_makeline(); }
void create_form_name(char (&dst)[len], slist_t *sl, int num) { qsnprintf(dst, len, "IDB%d: %s", num, sl->sigs[0]->name); }
//-------------------------------------------------------------------------- bool win32_debmod_t::get_dll_exports( const images_t &dlls, ea_t imagebase, name_info_t &ni, const char *exported_name) { int i; wince_module_t wm; if ( !find_module(imagebase, &wm) ) return false; common_e32_lite &e32 = get_e32(&wm); petab_t *pexpdir; if ( is_ce500() ) { win500_e32_lite *e32_500 = (win500_e32_lite *)&e32; pexpdir = &e32_500->unit[E32_LITE_EXP]; } else { win420_e32_lite *e32_420 = (win420_e32_lite *)&e32; pexpdir = &e32_420->unit[E32_LITE_EXP]; } petab_t &expdir = *pexpdir; if ( expdir.size <= 0 ) return false; // calculate the export directory address ea_t o32_ptr = (ea_t)get_o32_ptr(&wm); ea_t exp_ea = BADADDR; // no memory or bad object count o32_lite *ao32 = new o32_lite[e32.objcnt]; if ( ao32 == NULL ) return false; if ( myread(o32_ptr, ao32, e32.objcnt * sizeof(o32_lite)) ) { for ( i=0; i < e32.objcnt; i++ ) { o32_lite &o32 = ao32[i]; if ( expdir.rva >= o32.rva && expdir.rva+expdir.size <= o32.rva+o32.vsize ) exp_ea = o32.realaddr + (expdir.rva - o32.rva); } } delete [] ao32; if ( exp_ea == BADADDR ) return false; // read export section uchar *data = new uchar[expdir.size]; if ( data == NULL ) return false; bool ok = false; const uint32 *end = (const uint32 *)(data + expdir.size); if ( myread(exp_ea, data, expdir.size) ) { peexpdir_t &ed = *(peexpdir_t *)data; char *dllname = (char *)data + ed.dllname - expdir.rva; if ( dllname < (char *)data || dllname >= (char*)end ) dllname = ""; char *dot = strrchr(dllname, '.'); if ( dot != NULL ) *dot = '\0'; const uint32 *names = (const uint32 *)(data + ed.namtab - expdir.rva); const uint16 *ords = (const uint16 *)(data + ed.ordtab - expdir.rva); const uint32 *addrs = (const uint32 *)(data + ed.adrtab - expdir.rva); if ( names < end && (uint32*)ords < end && addrs < end ) { // ordinals -> names typedef std::map<int, qstring> expfunc_t; expfunc_t funcs; for ( i=0; i < ed.nnames; i++ ) { const char *name = (char*)data + names[i] - expdir.rva; if ( name >= (char*)data && name < (char*)end ) funcs.insert(make_pair(ed.ordbase + ords[i], qstring(name))); } for ( i=0; i < ed.naddrs; i++ ) { char buf[MAXSTR]; uint32 adr = addrs[i]; if ( adr == 0 ) continue; int ord = ed.ordbase + i; ea_t fulladdr = imagebase + adr; expfunc_t::iterator p = funcs.find(ord); if ( p != funcs.end() ) qsnprintf(buf, sizeof(buf), "%s_%s", dllname, p->second.c_str()); else qsnprintf(buf, sizeof(buf), "%s_%d", dllname, ord); ni.addrs.push_back(fulladdr); ni.names.push_back(qstrdup(buf)); ok = true; } } } delete [] data; return ok; }
//-------------------------------------------------------------------------- // Short information about the current location. // It will be displayed in the status line void ida_export class_place_t__print(const cp_t *ths, void *,char *buf, size_t bufsize) { qsnprintf(buf, bufsize, "%d::%d+%d:%d", ths->lnnum, ths->idx, ths->section, ths->subsection); }
void VideoWriter::initialize(QString filename) { filename = filename + QString(".mp4"); qDebug() << "Initializing writing to " << filename; vFilename = &filename; if ((width == -1) || (height == -1)) { // Haven't received any frames yet, so we don't know what size they are... waitingToInitialize = true; } else { //qDebug() << "Thread for initialize: " << QThread::currentThreadId(); // Write header here // FFMPEG initialization av_register_all(); // initialize libavcodec, and register all codecs and formats fmt = av_guess_format("mp4", NULL, NULL); if (!fmt) { qCritical() << "Error initializing fmt."; } fmt->video_codec = (AVCodecID) videoEncoder->currentData().value<unsigned int>(); /* allocate the output media context */ oc = avformat_alloc_context(); if (!oc) qCritical() << "Error allocating output media context."; qDebug() << "Output context allocated"; oc->oformat = fmt; qsnprintf(oc->filename, sizeof(oc->filename), "%s", vFilename->toLocal8Bit().data()); /* add the video stream to the container and initialize the codecs */ video_st = NULL; AVCodec *codec = avcodec_find_encoder(fmt->video_codec); // should add error checking video_st = avformat_new_stream(oc, codec); // should add error checking AVCodecContext *c = video_st->codec; c->codec_id = fmt->video_codec; c->codec_type = AVMEDIA_TYPE_VIDEO; /* put sample parameters */ c->width = width; c->height = height; // resolution must be a multiple of two c->pix_fmt = PIX_FMT_YUV420P; c->time_base = timeBase; // frames per second // Stuff to try to force high quality encoding if (c->codec_id == AV_CODEC_ID_MPEG2VIDEO) { c->qmin = 1; // low is better, so frame-by-frame force high quality c->qmax = 2; // set this to 1 for highest quality /* just for testing, we also get rid of B frames */ //c->max_b_frames = 0; } else if (c->codec_id == AV_CODEC_ID_H264) { av_opt_set(c->priv_data, "preset", "veryfast",0); // ultrafast and superfast also work //c->qmax = 18; //c->qmin = 18; } // some formats want stream headers to be seperate if (oc->oformat->flags & AVFMT_GLOBALHEADER) c->flags |= CODEC_FLAG_GLOBAL_HEADER; //av_dump_format(oc, 0, vFilename->toLocal8Bit().data(), 1); /* now that all the parameters are set, we can open the video codec and allocate the necessary encode buffers */ /* open the codec */ int err = avcodec_open2(c, codec, NULL); // should error check video_outbuf = NULL; if (!(oc->oformat->flags & AVFMT_RAWPICTURE)) { /* allocate output buffer */ video_outbuf_size = 1000000; video_outbuf = (uint8_t*)malloc(video_outbuf_size); } picture = avcodec_alloc_frame(); // should error check if (!picture) { qCritical() << "Error allocating picture frame."; } int size = avpicture_get_size(c->pix_fmt, width, height); picture_buf = (uint8_t*)av_malloc(size); // should error check if (picture_buf == NULL) { qCritical() << "Error allocating memory for picture buffer."; } avpicture_fill((AVPicture *)picture, picture_buf, c->pix_fmt, width, height); /* open the output file, if needed */ if (avio_open(&oc->pb, vFilename->toLocal8Bit().data(), AVIO_FLAG_WRITE) < 0) { qDebug() << "Could not open " << vFilename; } /* write the stream header, if any */ avformat_write_header(oc, NULL); // Open subtitles here // Set up frame conversion from RGB24 to YUV420P sws_ctx = sws_getContext(c->width, c->height, PIX_FMT_RGB24, c->width, c->height, c->pix_fmt, SWS_FAST_BILINEAR | SWS_CPU_CAPS_SSE2 | SWS_CPU_CAPS_MMX2, NULL, NULL, NULL); if (!sws_ctx) { qCritical() << "Error allocating SWS context."; } tmp_picture = avcodec_alloc_frame(); if (!tmp_picture) { qCritical() << "Error allocating tmp_picture frame."; } waitingToInitialize = false; qDebug() << "Video Initialized emitted"; // Should check here for errors above } }
void IDAconnector::server_connect (void) { hostent *he; sockaddr_in sin; in_addr addr; WSADATA wsa_data; char buf [512]; char message [128]; char password [64]; char project [64]; char server_addr [128]; char username [64]; int code; int len; int port = 5041; const char dialog_format[] = "STARTITEM 0\n" PLUGIN_NAME"\n" "Connect to IDA Sync server.\n\n" "Server / Port: \n<:A:512:30::> <:D:5:5::>\n" "Username: \n<:A:128:40::>\n" "Password: \n<:A:128:40::>\n" "Project Name: \n<:A:128:40::>\n\n"; memset(buf, 0, sizeof(buf)); memset(message, 0, sizeof(message)); memset(password, 0, sizeof(password)); memset(project, 0, sizeof(project)); memset(server_addr, 0, sizeof(server_addr)); memset(username, 0, sizeof(username)); // if we are already connected then do nothing. if (connected) return; // prompt the user for server connection information.. if (!AskUsingForm_c(dialog_format, server_addr, &port, username, password, project)) { msg("[!] "PLUGIN_NAME"> Connection cancelled.\n"); return; } // initialize winsock. if (WSAStartup(MAKEWORD(2, 2), &wsa_data) != 0) { msg("[!] "PLUGIN_NAME"> WSAStartup() failed.\n"); return; } // confirm that the requested winsock version is supported. if (LOBYTE(wsa_data.wVersion) != 2 || HIBYTE(wsa_data.wVersion) != 2) { WSACleanup(); msg("[!] "PLUGIN_NAME"> Winsock version 2.2 not found.\n"); return; } // check if a valid IP address was provided, if not try to do gethostbyname(). addr.s_addr = inet_addr(server_addr); if( addr.s_addr == INADDR_NONE ) { if ((he = gethostbyname(server_addr)) == NULL) { msg("[!] "PLUGIN_NAME"> Unable to resolve name: %s\n", server_addr); return; } } // otherwise, use the numeric IP address with gethostbyaddr() else { if ((he = gethostbyaddr((char *)&addr, sizeof(struct in_addr), AF_INET)) == NULL) { msg("[!] "PLUGIN_NAME"> Unable to resolve address\n"); return; } } // create a socket. if ((connection = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) { WSACleanup(); msg("[!] "PLUGIN_NAME"> Failed to create socket.\n"); return; } // connect to the server. sin.sin_family = AF_INET; sin.sin_addr = *((LPIN_ADDR)*he->h_addr_list); sin.sin_port = htons(port); if (connect(connection, (SOCKADDR *) &sin, sizeof(sin)) == SOCKET_ERROR) { WSACleanup(); msg("[!] "PLUGIN_NAME"> Failed to connect to server.\n"); return; } // connection to server successful. // register the plugin with the console. qsnprintf(buf, sizeof(buf) - 1, PLUGIN_NAME":::%s:::%s:::%s", project, username, password); len = strlen(buf); // send the registration request. if (send(connection, buf, len, 0) != len) { closesocket(connection); WSACleanup(); msg("[!] "PLUGIN_NAME"> Failed to register with server.\n"); return; } // receive the registration confirmation. len = recv(connection, buf, sizeof(buf) - 1, 0); // connection closed. if (len == 0 || len == SOCKET_ERROR) { closesocket(connection); WSACleanup(); msg("[!] "PLUGIN_NAME"> Failed to read registration response from server.\n"); return; } // null terminate the received buffer. buf[len] = 0; // parse the server message. format: code:::message. // if we can't understand the response, then quit. if (sscanf(buf, "%d:::%127[^\0]", &code, message) != 2) { closesocket(connection); WSACleanup(); msg("[!] "PLUGIN_NAME"> Registration failed.\n"); return; } // registration failed. print why. if (code == 0) { closesocket(connection); WSACleanup(); msg("[!] "PLUGIN_NAME"> Registration failed: %s\n", message); return; } // create an invisble window for hooking messages received by our socket. if ((socket_hwnd = CreateWindowEx(0, "STATIC", PLUGIN_NAME, 0, 0, 0, 0, 0, 0, 0, 0, 0)) == NULL) { closesocket(connection); WSACleanup(); msg("[!] "PLUGIN_NAME"> CreateWindowEx() failed.\n"); return; } // register the callback function for our invisible window. if (SetWindowLong(socket_hwnd, GWL_WNDPROC, (long) socket_proc_wrapper) == 0) { closesocket(connection); WSACleanup(); DestroyWindow(socket_hwnd); msg("[!] "PLUGIN_NAME"> SetWindowLong() failed.\n"); return; } // make the socket a non-blocking asynchronous socket hooked with our socket_proc handler. if (WSAAsyncSelect(connection, socket_hwnd, SOCKET_MSG, FD_READ | FD_CLOSE) == SOCKET_ERROR) { closesocket(connection); WSACleanup(); DestroyWindow(socket_hwnd); msg("[!] "PLUGIN_NAME"> Failed to create asynchronous connection to server.\n"); return; } // asynchronous connection to server established. raise the connected flag. msg("[*] "PLUGIN_NAME"> Successfully registered project '%s' with server as '%s'\n", project, username); connected = true; }
void QXunitTestLogger::addIncident(IncidentTypes type, const char *description, const char *file, int line) { const char *typeBuf = 0; char buf[100]; switch (type) { case QAbstractTestLogger::XPass: ++failureCounter; typeBuf = "xpass"; break; case QAbstractTestLogger::Pass: typeBuf = "pass"; break; case QAbstractTestLogger::XFail: typeBuf = "xfail"; break; case QAbstractTestLogger::Fail: ++failureCounter; typeBuf = "fail"; break; default: typeBuf = "??????"; break; } if (type == QAbstractTestLogger::Fail || type == QAbstractTestLogger::XPass) { QTestElement *failureElement = new QTestElement(QTest::LET_Failure); failureElement->addAttribute(QTest::AI_Result, typeBuf); if (file) failureElement->addAttribute(QTest::AI_File, file); else failureElement->addAttribute(QTest::AI_File, ""); qsnprintf(buf, sizeof(buf), "%i", line); failureElement->addAttribute(QTest::AI_Line, buf); failureElement->addAttribute(QTest::AI_Description, description); addTag(failureElement); currentLogElement->addLogElement(failureElement); } /* Only one result can be shown for the whole testfunction. Check if we currently have a result, and if so, overwrite it iff the new result is worse. */ QTestElementAttribute* resultAttr = const_cast<QTestElementAttribute*>(currentLogElement->attribute(QTest::AI_Result)); if (resultAttr) { const char* oldResult = resultAttr->value(); bool overwrite = false; if (!strcmp(oldResult, "pass")) { overwrite = true; } else if (!strcmp(oldResult, "xfail")) { overwrite = (type == QAbstractTestLogger::XPass || type == QAbstractTestLogger::Fail); } else if (!strcmp(oldResult, "xpass")) { overwrite = (type == QAbstractTestLogger::Fail); } if (overwrite) { resultAttr->setPair(QTest::AI_Result, typeBuf); } } else { currentLogElement->addAttribute(QTest::AI_Result, typeBuf); } if (file) currentLogElement->addAttribute(QTest::AI_File, file); else currentLogElement->addAttribute(QTest::AI_File, ""); qsnprintf(buf, sizeof(buf), "%i", line); currentLogElement->addAttribute(QTest::AI_Line, buf); /* Since XFAIL does not add a failure to the testlog in xunitxml, add a message, so we still have some information about the expected failure. */ if (type == QAbstractTestLogger::XFail) { QXunitTestLogger::addMessage(QAbstractTestLogger::Info, description, file, line); } }
//-------------------------------------------------------------------------- void segstart(ea_t ea) { char buf[MAXSTR]; char *const end = buf + sizeof(buf); segment_t *Sarea = getseg(ea); if ( is_spec_segm(Sarea->type) ) return; const char *align; switch ( Sarea->align ) { case saAbs: align = "at: "; break; case saRelByte: align = "byte"; break; case saRelWord: align = "word"; break; case saRelPara: align = "para"; break; case saRelPage: align = "page"; break; case saRel4K: align = "4k"; break; case saRel64Bytes: align = "64"; break; default: align = NULL; break; } if ( align == NULL ) { gen_cmt_line("Segment alignment '%s' can not be represented in assembly", get_segment_alignment(Sarea->align)); align = ""; } char sname[MAXNAMELEN]; char sclas[MAXNAMELEN]; get_true_segm_name(Sarea, sname, sizeof(sname)); get_segm_class(Sarea, sclas, sizeof(sclas)); char *ptr = buf + qsnprintf(buf, sizeof(buf), SCOLOR_ON SCOLOR_ASMDIR "%-*s segment %s ", inf.indent-1, sname, align); if ( Sarea->align == saAbs ) { ea_t absbase = get_segm_base(Sarea); ptr += btoa(ptr, end-ptr, absbase); APPCHAR(ptr, end, ' '); } const char *comb; switch ( Sarea->comb ) { case scPub: case scPub2: case scPub3: comb = ""; break; case scCommon: comb = "common"; break; default: comb = NULL; break; } if ( comb == NULL ) { gen_cmt_line("Segment combination '%s' can not be represented in assembly", get_segment_combination(Sarea->comb)); comb = ""; } ptr += qsnprintf(ptr, end-ptr, "%s '%s'", comb, sclas); tag_off(ptr, end, COLOR_ASMDIR); MakeLine(buf, 0); }
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; }
static void parseAttributeValues(sdp_data_t *data, int indentation, QByteArray &xmlOutput) { if (!data) return; const int length = indentation*2 + 1; QByteArray indentString(length, ' '); char snBuffer[BUFFER_SIZE]; xmlOutput.append(indentString); // deal with every dtd type switch (data->dtd) { case SDP_DATA_NIL: xmlOutput.append("<nil/>\n"); break; case SDP_UINT8: qsnprintf(snBuffer, BUFFER_SIZE, "<uint8 value=\"0x%02x\"/>\n", data->val.uint8); xmlOutput.append(snBuffer); break; case SDP_UINT16: qsnprintf(snBuffer, BUFFER_SIZE, "<uint16 value=\"0x%04x\"/>\n", data->val.uint16); xmlOutput.append(snBuffer); break; case SDP_UINT32: qsnprintf(snBuffer, BUFFER_SIZE, "<uint32 value=\"0x%08x\"/>\n", data->val.uint32); xmlOutput.append(snBuffer); break; case SDP_UINT64: qsnprintf(snBuffer, BUFFER_SIZE, "<uint64 value=\"0x%016x\"/>\n", data->val.uint64); xmlOutput.append(snBuffer); break; case SDP_UINT128: xmlOutput.append("<uint128 value=\"0x"); for (int i = 0; i < 16; i++) ::sprintf(&snBuffer[i * 2], "%02x", data->val.uint128.data[i]); xmlOutput.append(snBuffer); xmlOutput.append("\"/>\n"); break; case SDP_INT8: qsnprintf(snBuffer, BUFFER_SIZE, "<int8 value=\"%d\"/>/n", data->val.int8); xmlOutput.append(snBuffer); break; case SDP_INT16: qsnprintf(snBuffer, BUFFER_SIZE, "<int16 value=\"%d\"/>/n", data->val.int16); xmlOutput.append(snBuffer); break; case SDP_INT32: qsnprintf(snBuffer, BUFFER_SIZE, "<int32 value=\"%d\"/>/n", data->val.int32); xmlOutput.append(snBuffer); break; case SDP_INT64: qsnprintf(snBuffer, BUFFER_SIZE, "<int64 value=\"%d\"/>/n", data->val.int64); xmlOutput.append(snBuffer); break; case SDP_INT128: xmlOutput.append("<int128 value=\"0x"); for (int i = 0; i < 16; i++) ::sprintf(&snBuffer[i * 2], "%02x", data->val.int128.data[i]); xmlOutput.append(snBuffer); xmlOutput.append("\"/>\n"); break; case SDP_UUID_UNSPEC: break; case SDP_UUID16: case SDP_UUID32: xmlOutput.append("<uuid value=\"0x"); sdp_uuid2strn(&(data->val.uuid), snBuffer, BUFFER_SIZE); xmlOutput.append(snBuffer); xmlOutput.append("\"/>\n"); break; case SDP_UUID128: xmlOutput.append("<uuid value=\""); sdp_uuid2strn(&(data->val.uuid), snBuffer, BUFFER_SIZE); xmlOutput.append(snBuffer); xmlOutput.append("\"/>\n"); break; case SDP_TEXT_STR_UNSPEC: break; case SDP_TEXT_STR8: case SDP_TEXT_STR16: case SDP_TEXT_STR32: { xmlOutput.append("<text "); QByteArray text = QByteArray::fromRawData(data->val.str, data->unitSize); bool hasNonPrintableChar = false; for (int i = 0; i < text.count(); i++) { if (text[i] == '\0') { text.resize(i); // cut trailing content break; } else if (!isprint(text[i])) { hasNonPrintableChar = true; text.resize(text.indexOf('\0')); // cut trailing content break; } } if (hasNonPrintableChar) { xmlOutput.append("encoding=\"hex\" value=\""); xmlOutput.append(text.toHex()); } else { text.replace('&', "&"); text.replace('<', "<"); text.replace('>', ">"); text.replace('"', """); xmlOutput.append("value=\""); xmlOutput.append(text); } xmlOutput.append("\"/>\n"); break; } case SDP_BOOL: if (data->val.uint8) xmlOutput.append("<boolean value=\"true\"/>\n"); else xmlOutput.append("<boolean value=\"false\"/>\n"); break; case SDP_SEQ_UNSPEC: break; case SDP_SEQ8: case SDP_SEQ16: case SDP_SEQ32: xmlOutput.append("<sequence>\n"); parseAttributeValues(data->val.dataseq, indentation + 1, xmlOutput); xmlOutput.append(indentString); xmlOutput.append("</sequence>\n"); break; case SDP_ALT_UNSPEC: break; case SDP_ALT8: case SDP_ALT16: case SDP_ALT32: xmlOutput.append("<alternate>\n"); parseAttributeValues(data->val.dataseq, indentation + 1, xmlOutput); xmlOutput.append(indentString); xmlOutput.append("</alternate>\n"); break; case SDP_URL_STR_UNSPEC: break; case SDP_URL_STR8: case SDP_URL_STR16: case SDP_URL_STR32: strncpy(snBuffer, data->val.str, data->unitSize - 1); xmlOutput.append("<url value=\""); xmlOutput.append(snBuffer); xmlOutput.append("\"/>\n"); break; default: fprintf(stderr, "Unknown dtd type\n"); } parseAttributeValues(data->next, indentation, xmlOutput); }
//---------------------------------------------------------------------- int upgrade_db_format(int ver, netnode constnode) { if(askyn_c(1, "AUTOHIDE REGISTRY\nHIDECANCEL\n" "The database has an old java data format.\n" "Do you want to upgrade it?") <= 0) qexit(1); switch ( ver ) { default: INTERNAL("upgrade::ver"); case IDP_JDK12: break; } // change format: jdk-version if ( curClass.MinVers > 0x8000u ) { badbase: return(0); } curClass.MajVers = JDK_MIN_MAJOR; if ( curClass.MinVers >= 0x8000 ) { curClass.MinVers &= ~0; ++curClass.MajVers; curClass.JDKsubver = 2; } else if ( curClass.MinVers >= JDK_1_1_MINOR ) ++curClass.JDKsubver; // change format: This #ifdef __BORLANDC__ #if offsetof(ClassInfo, This.Ref) != offsetof(ClassInfo, This.Name) || \ offsetof(ClassInfo, This.Dscr) != offsetof(ClassInfo, This.Name) + 2 #error #endif #endif curClass.This.Ref = (curClass.This.Ref << 16) | curClass.This.Dscr; if ( !curClass.This.Name ) goto badbase; // change format: Super #ifdef __BORLANDC__ #if offsetof(ClassInfo, super.Ref) != offsetof(ClassInfo, super.Name) || \ offsetof(ClassInfo, super.Dscr) != offsetof(ClassInfo, super.Name) + 2 #error #endif #endif switch ( curClass.super.Name ) { case 0: // absent curClass.super.Ref &= 0; break; case 0xFFFF: // bad index ++curClass.super.Name; break; default: // reverse order curClass.super.Ref = (curClass.super.Ref << 16) | curClass.super.Dscr; break; } // validate: impNode if ( curClass.impNode && !netnode(curClass.impNode).altval(0) ) goto badbase; // change variable 'errload' in previous version if ( curClass.maxSMsize ) { curClass.extflg |= XFL_C_ERRLOAD; curClass.maxSMsize &= 0; } // set segments type type for special segments segment_t *S; if ( (S = getseg(curClass.startEA)) == NULL ) goto badbase; S->set_hidden_segtype(true); S->update(); if ( curClass.xtrnCnt ) { if ( (S = getseg(curClass.xtrnEA)) == NULL ) goto badbase; S->set_hidden_segtype(true); S->update(); } curClass.extflg |= XFL_C_DONE; // do not repeat datalabel destroyer :) // change: method/fields format #define SGEXPSZ (sizeof(SegInfo) - offsetof(SegInfo, varNode)) #define FMEXPSZ (sizeof(_FMid_) - offsetof(_FMid_, _UNUSED_ALING)) #define FLEXPSZ (sizeof(FieldInfo) - offsetof(FieldInfo, annNodes)) uval_t oldsize = sizeof(SegInfo) - FMEXPSZ - SGEXPSZ; for(int pos=-(int)curClass.MethodCnt; pos<=(int)curClass.FieldCnt; pos++) { union { SegInfo s; FieldInfo f; _FMid_ id; uchar _space[qmax(sizeof(SegInfo), sizeof(FieldInfo)) + 1]; }u; if ( !pos ) { // class node oldsize += (sizeof(FieldInfo) - FLEXPSZ) - (sizeof(SegInfo) - SGEXPSZ); continue; } if ( ClassNode.supval(pos, &u, sizeof(u)) != oldsize ) goto badbase; memmove((uchar *)&u.id + sizeof(u.id), &u.id._UNUSED_ALING, (size_t)oldsize - offsetof(_FMid_, _UNUSED_ALING)); u.id._UNUSED_ALING = 0; u.id.utsign = 0; if ( u.id.extflg & ~EFL__MASK ) goto badbase; u.id.extflg &= (EFL_NAMETYPE); if ( pos > 0 ) { // fields memset(&u.f.annNodes, 0, sizeof(u.f)-offsetof(FieldInfo, annNodes)); ClassNode.supset(pos, &u.f, sizeof(u.f)); continue; } // segments memset(&u.s.varNode, 0, sizeof(u.s) - offsetof(SegInfo, varNode)); if ( u.s.thrNode && !netnode(u.s.thrNode).altval(0) ) { netnode(u.s.thrNode).kill(); // empty node (old format) u.s.thrNode = 0; } // have locvars? if ( u.s.DataSize ) { if ( (S = getseg(u.s.DataBase)) == NULL ) goto badbase; S->type = SEG_BSS; S->set_hidden_segtype(true); S->update(); } // change: Exception format if ( u.s.excNode ) { register ushort i, j; netnode enode(u.s.excNode); if ( (j = (ushort)enode.altval(0)) == 0 ) goto badbase; ea_t ea = u.s.startEA + u.s.CodeSize; i = 1; do { Exception exc; if ( enode.supval(i, &exc, sizeof(exc)) != sizeof(exc) ) goto badbase; #ifdef __BORLANDC__ #if offsetof(Exception, filter.Ref) != offsetof(Exception, filter.Name) || \ offsetof(Exception, filter.Dscr) != offsetof(Exception, filter.Name) + 2 #error #endif #endif if ( !exc.filter.Name != !exc.filter.Dscr ) goto badbase; exc.filter.Ref = (exc.filter.Ref << 16) | exc.filter.Dscr; // was reverse order if ( exc.filter.Name == 0xFFFF ) ++exc.filter.Name; enode.supset(i, &exc, sizeof(exc)); set_exception_xref(&u.s, exc, ea); }while ( ++i <= j ); } ClassNode.supset(pos, &u.s, sizeof(u.s)); //rename local variables (for references) if ( u.s.DataSize ) { int i = u.s.DataSize; ea_t ea = u.s.DataBase + i; do { char str[MAXNAMELEN]; qsnprintf(str, sizeof(str), "met%03u_slot%03u", u.s.id.Number, --i); --ea; if ( do_name_anyway(ea, str)) make_name_auto(ea ); else hide_name(ea); }while ( i ); coagulate_unused_data(&u.s); } } // for //change format of string presentation in constant pool for(int pos = 0; (ushort)pos <= curClass.maxCPindex; pos++) { ConstOpis co; if ( constnode.supval(pos, &co, sizeof(co)) != sizeof(co) ) goto badbase; switch ( co.type ) { default: continue; case CONSTANT_Unicode: error("Base contain CONSTANT_Unicode, but it is removed from " "the standard in 1996 year and never normal loaded in IDA"); case CONSTANT_Utf8: break; } uint32 v, n, i = pos << 16; if( ((n = (uint32)constnode.altval(i)) & UPG12_BADMASK) || (v = n & ~UPG12_CLRMASK) == 0) goto badbase; if ( n & UPG12_EXTMASK ) v |= UPG12_EXTSET; if ( (n = (ushort)v) != 0 ) { register uchar *po = (uchar*)append_tmp_buffer(v); n *= sizeof(ushort); uint32 pos = 0; do { uint32 sz = n - pos; if ( sz > MAXSPECSIZE ) sz = MAXSPECSIZE; if ( constnode.supval(++i, &po[pos], sz) != sz ) goto badbase; constnode.supdel(i); pos += sz; }while ( pos < n ); constnode.setblob(po, n, i & ~0xFFFF, BLOB_TAG); if ( !(v & UPG12_EXTSET) ) do { #ifdef __BORLANDC__ #if ( sizeof(ushort) % 2) || (MAXSPECSIZE % 2 ) #error #endif #endif ushort cw = *(ushort *)&po[pos]; if ( cw >= CHP_MAX ) { if ( !javaIdent(cw) ) goto extchar; } else if ( (uchar)cw <= CHP_MIN ) { extchar: v |= UPG12_EXTSET; break; } }while ( (pos -= sizeof(ushort)) != 0 ); v = upgrade_ResW(v); } constnode.altset(i, v); co._Sopstr = v; // my be not needed? (next also) constnode.supset(pos, &co, sizeof(co)); } // rename 'import' variables for refernces for(unsigned ip = 1; (ushort)ip <= curClass.xtrnCnt; ip++) { ConstOpis co; { register unsigned j; if( (j = (unsigned)XtrnNode.altval(ip)) == 0 || !LoadOpis((ushort)j, 0, &co)) goto badbase; } switch ( co.type ) { default: goto badbase; case CONSTANT_Class: if ( !(co.flag & HAS_CLSNAME) ) continue; break; case CONSTANT_InterfaceMethodref: case CONSTANT_Methodref: if ( (co.flag & NORM_METOD) != NORM_METOD ) continue; break; case CONSTANT_Fieldref: if ( (co.flag & NORM_FIELD) != NORM_FIELD ) continue; break; } make_new_name(co._name, co._subnam, co.type != CONSTANT_Class, ip); } if ( curClass.This.Dscr ) make_new_name(curClass.This.Name, 0, (uchar)-1, (unsigned)curClass.startEA); return(_TO_VERSION); }