我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用idaapi.set_processor_type()。
def SetProcessorType (processor, level): """ Change current processor @param processor: name of processor in short form. run 'ida ?' to get list of allowed processor types @param level: the power of request: - SETPROC_COMPAT - search for the processor type in the current module - SETPROC_ALL - search for the processor type in all modules only if there were not calls with SETPROC_USER - SETPROC_USER - search for the processor type in all modules and prohibit level SETPROC_USER - SETPROC_FATAL - can be combined with previous bits. means that if the processor type can't be set, IDA should display an error message and exit. """ return idaapi.set_processor_type(processor, level)
def load_file(li, neflags, format): idaapi.set_processor_type("arm", SETPROC_ALL|SETPROC_FATAL) offs = 0 for s in segments: start = s["start"] length = s["len"] name = s["name"] seg_type = s["type"] li.file2base(offs, start, start+length, True) idaapi.add_segm(0, start, start+length, name, seg_type) offs += length create_modem_hdr_struct() add_modem_hdr_struct(8*4 + segments[0]["start"]) #this might fail unless we carve out a DATA segment from the CODE segment for it. print "Samsung Shannon image loaded." return 1
def SetLongPrm (offset, value): """ """ if offset == INF_PROCNAME: raise NotImplementedError, "Please use idaapi.set_processor_type() to change processor" return _IDC_SetAttr(idaapi.cvar.inf, _INFMAP, offset, value)
def load_file(li, neflags, format): # Select the PC processor module idaapi.set_processor_type("BPF", SETPROC_ALL|SETPROC_FATAL) buf = read_whole_file(li, 8) if not buf: return 0 # Load all shellcode into different segments start = 0x1000 seg = idaapi.segment_t() size = len(buf) end = start + size # Create the segment seg.startEA = start seg.endEA = end seg.bitness = 1 # 32-bit idaapi.add_segm_ex(seg, "bpf_c", "CODE", 0) # Copy the bytes idaapi.mem2base(buf, start, end) # add entry point idaapi.add_entry(start, start, "start", 1) # add comment to beginning of disassembly idaapi.describe(start, True, "BPF bytecode disassembly") # Mark for analysis AutoMark(start, AU_CODE) setup_enums() return 1
def accept_file(li, n): """ Check if the file is of supported format @param li: a file-like object which can be used to access the input data @param n : format number. The function will be called with incrementing number until it returns zero @return: 0 - no more supported formats string "name" - format name to display in the chooser dialog dictionary { 'format': "name", 'options': integer } options: should be 1, possibly ORed with ACCEPT_FIRST (0x8000) to indicate preferred format """ # we support only one format per file if n > 0: return 0 li.seek(0) magic = li.read(2) if struct.unpack('>h',magic)[0] in magics: idaapi.set_processor_type("A29K", SETPROC_ALL) return { 'format': fmt_a29k_coff_big, 'options': 1 } if struct.unpack('<h',magic)[0] in magics: idaapi.set_processor_type("A29K", SETPROC_ALL) return { 'format': fmt_a29k_coff_little, 'options': 1 } # unrecognized format return 0
def load_file(f, neflags, format): f.seek(0) magic = f.read(4); version = struct.unpack("<I", f.read(4))[0]; flags = struct.unpack("<I", f.read(4))[0]; memType = struct.unpack("<I", f.read(4))[0]; serviceType = struct.unpack("<I", f.read(4))[0]; numInstances = struct.unpack("<I", f.read(4))[0]; uuid = struct.unpack("<IIII", f.read(16)); driverId = struct.unpack("<I", f.read(4))[0]; numThreads = struct.unpack("<I", f.read(4))[0]; textVA = struct.unpack("<I", f.read(4))[0]; textLen = struct.unpack("<I", f.read(4))[0]; dataVA = struct.unpack("<I", f.read(4))[0]; dataLen = struct.unpack("<I", f.read(4))[0]; bssLen = struct.unpack("<I", f.read(4))[0]; entry = struct.unpack("<I", f.read(4))[0]; f.seek(MCLF_TEXT_INFO_OFFSET) idaapi.set_processor_type("arm", SETPROC_ALL) # Set VA for .text and add the segment f.file2base(0, textVA, textVA + textLen, True) idaapi.add_segm(0, textVA, textVA + textLen, ".text", "CODE") # Set VA for .data and add the segment f.file2base(MCLF_HEADER_SIZE_V23 + textLen, dataVA, dataVA + dataLen, True) idaapi.add_segm(0, dataVA, dataVA + dataLen, ".data", "DATA") # Add BSS segment after .text and .data idaapi.add_segm(0, dataVA + dataLen, dataVA + dataLen + bssLen, ".bss", "BSS") if entry % 4 == 1: #Thumb address is always +1 to set the T bit idaapi.add_entry(entry-1, entry-1, "_entry", 1) SetRegEx(entry-1, "T", 0x1, SR_user); else: idaapi.add_entry(entry, entry, "_entry", 1) SetRegEx(entry, "T", 0x0, SR_user); MakeDword(tlApiLibEntry) MakeName(tlApiLibEntry,"tlApiLibEntry"); return 1