我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用idaapi.get_inf_structure()。
def get_arch_dynamic(): """ Determine the execution environments architecture. :return: 'x64' or 'x86' if arch could be determined, else None """ info = idaapi.get_inf_structure() if info.is_64bit(): return 64 elif info.is_32bit(): return 32 else: env = idaapi.dbg_get_registers() if env[17][0] == 'RAX': return 64 elif env[17][0] == 'EAX': return 32 else: return None ############################### # LIB DETECTION FUNCTIONALITY # ###############################
def output_segments(out): """Dump binary segmentation.""" info = idaapi.get_inf_structure() size = "r32" if info.is_32bit else "r64" out.writelines(('(', info.get_proc_name()[1], ' ', size, ' (')) for seg in idautils.Segments(): out.write("\n({} {} {:d} ({:#x} {:d}))".format( idaapi.get_segm_name(seg), "code" if idaapi.segtype(seg) == idaapi.SEG_CODE else "data", idaapi.get_fileregion_offset(seg), seg, idaapi.getseg(seg).size())) out.write("))\n")
def is_x86(): ''' is the currently loaded module 32-bit x86? ''' inf = idaapi.get_inf_structure() return inf.procName == 'metapc' and inf.is_32bit() and not inf.is_64bit()
def is_x64(): ''' is the currently loaded module 64-bit x86? ''' inf = idaapi.get_inf_structure() return inf.procName == 'metapc' and inf.is_32bit() and inf.is_64bit()
def __newprc__(cls, pnum): info = idaapi.get_inf_structure() bits = 64 if info.is_64bit() else 32 if info.is_32bit() else None if bits is None: return typemap.integermap[None] = typemap.integermap[bits/8] typemap.decimalmap[None] = typemap.decimalmap[bits/8] typemap.ptrmap[None] = typemap.ptrmap[bits/8] typemap.stringmap[None] = typemap.stringmap[str]
def __bounds__(cls): info = idaapi.get_inf_structure() return info.minEA, info.maxEA
def get_file_mask(): mask = "*.dd32" if idaapi.get_inf_structure().is_64bit(): mask = "*.dd64" return mask
def create_runtime_ms(): debug('Attempting to find runtime_morestack function for hooking on...') text_seg = get_text_seg() if text_seg is None: debug('Failed to get text segment') return None # Opcodes for "mov large dword ptr ds:1003h, 0", binary search is faster than text search opcodes = 'c7 05 03 10 00 00 00 00 00 00' if idaapi.get_inf_structure().is_64bit(): # Opcodes for "mov qword ptr ds:dword_1000+3, 0" opcodes = '48 c7 04 25 03 10 00 00 00 00 00 00' runtime_ms_end = idaapi.find_binary(text_seg.startEA, text_seg.endEA, opcodes, 0, SEARCH_DOWN) if runtime_ms_end == BADADDR: debug('Failed to find opcodes associated with runtime_morestack: %s' % opcodes) return None runtime_ms = idaapi.get_func(runtime_ms_end) if runtime_ms is None: debug('Failed to get runtime_morestack function from address @ 0x%x' % runtime_ms_end) return None if idc.MakeNameEx(runtime_ms.startEA, "runtime_morestack", SN_PUBLIC): debug('Successfully found runtime_morestack') else: debug('Failed to rename function @ 0x%x to runtime_morestack' % runtime_ms.startEA) return runtime_ms
def create_pointer(addr, force_size=None): if force_size is not 4 and (idaapi.get_inf_structure().is_64bit() or force_size is 8): MakeQword(addr) return Qword(addr), 8 else: MakeDword(addr) return Dword(addr), 4
def refs(self): '''Return the (address, opnum, type) of all the references to this member within the database.''' mid = self.id # calculate the high-byte which is used to determine an address from a structure bits = int(math.ceil(math.log(idaapi.BADADDR)/math.log(2.0))) highbyte = 0xff << (bits-8) # if structure is a frame.. if internal.netnode.name.get(self.__owner.id).startswith('$ '): name, mptr = self.fullname, self.ptr sptr = idaapi.get_sptr(mptr) # get frame, func_t frname, _ = name.split('.', 2) frid = internal.netnode.get(frname) ea = idaapi.get_func_by_frame(frid) f = idaapi.get_func(ea) # now find all xrefs to member within function xl = idaapi.xreflist_t() idaapi.build_stkvar_xrefs(xl, f, mptr) # now we can add it res = [] for xr in xl: ea, opnum = xr.ea, int(xr.opnum) res.append( interface.OREF(ea, opnum, interface.ref_t(xr.type, instruction.op_state(ea, opnum))) ) # FIXME return res # otherwise, it's a structure..which means we need to specify the member to get refs for x = idaapi.xrefblk_t() ok = x.first_to(mid, 0) if not ok: return [] # collect all references available refs = [(x.frm,x.iscode,x.type)] while x.next_to(): refs.append((x.frm,x.iscode,x.type)) # now figure out which operand has the structure member applied to it res = [] for ea,_,t in refs: ops = ((idx, internal.netnode.sup.get(ea, 0xf+idx)) for idx in range(idaapi.UA_MAXOP) if internal.netnode.sup.get(ea, 0xf+idx) is not None) ops = ((idx, interface.node.sup_opstruct(val, idaapi.get_inf_structure().is_64bit())) for idx, val in ops) ops = (idx for idx, ids in ops if self.__owner.id in ids) # sanity res.extend( interface.OREF(ea, int(op), interface.ref_t.of(t)) for op in ops) return res #strpath_t #op_stroff(ea, n, tid_t* path, int path_len, adiff_t delta) #get_stroff_path(ea, n, tid_t* path, adiff_t delta)