def load_dumps(regex=""): """ >>> D = load_dumps() #doctest: +ELLIPSIS Input files: ... >>> D [Dump of test-0xff000000.bin] """ bins, loadaddrs, idcs = GetInputFiles(regex) D = {} for b,a in loadaddrs.iteritems(): D[b] = Dump(bin=b, RAWASM = disasm_dump(b,a)) D[b].loadaddr = a for b in bins: D[b].FUNCS = {} D[b].FUNCENDS = {} D[b].WHICHFUNC = {} D[b].A2N = {} D[b].N2A = {} for b,i in idcs.iteritems(): # this needs cleanup D[b].A2N, D[b].N2A, D[b].FUNCS = cache.access(i, idc.parse) D[b].update_func_indexes() D[b].idc = i for b,a in loadaddrs.iteritems(): D[b]._loadednames = {} D[b]._loadednames.update(D[b].N2A) D[b].ROM, D[b].MNEF, D[b].ARGS, refs, D[b].DISASM = cache.access(b, lambda b: parse_disasm(D[b])) D[b].minaddr = min(D[b].ROM) D[b].maxaddr = max(D[b].ROM) D[b].REFLIST = list(refs.iteritems()) D[b].A2REFS, D[b].REF2AS = cache.access(b, lambda b: index_refs(refs, D[b].ROM)) for b,a in loadaddrs.iteritems(): D[b].STRINGS # compute them remove_autogen_string_names(D[b]) cache.save() if len(D) == 1: print "Auto-selecting dump %s" % D[bins[0]].bin idapy.select_dump(D[bins[0]]) return sorted(D.values(), key=lambda x: x.bin)
def disasm_dump(bin, addr): """ Disassemble a file using arm-elf-objdump; return the output as plain text >>> print disasm_dump("test-0xff000000.bin", 0xff000000) #doctest: +NORMALIZE_WHITESPACE Disassembling test-0xff000000.bin <ff000000>... ok <BLANKLINE> tmp.elf: file format elf32-littlearm <BLANKLINE> <BLANKLINE> Disassembly of section .data: <BLANKLINE> ff000000 <_binary_test_0xff000000_bin_start>: ff000000: e3a01000 mov r1, #0 ; 0x0 ff000004: e59f2001 ldr r2, [pc, #1] ; ff00000d <_binary_test_0xff000000_bin_start+0xd> ff000008: e3a02004 mov r2, #4 ; 0x4 ff00000c: e0810002 add r0, r1, r2 ff000010: eafffffa b ff000000 <_binary_test_0xff000000_bin_start> <BLANKLINE> """ return cache.access((bin,addr), lambda x: disasm_work(*x))
def MakeFunction(dump,start,end=None,name=None): """ >>> d = load_dumps()[0] #doctest: +ELLIPSIS Input files: ... >>> d.MakeFunction(1, 10, "myfun") >>> d.MakeFunction(1, 10, "myfun") Overwriting name myfun """ if end is None: idapy.select_dump(dump) end = cache.access(start, emusym.GuessFunction) if end is None: print "Could not guess end address for function %x => skipping" % start return end += 4 f,e = start,end n = funcname(dump,f) dump.FUNCS[f] = e dump.FUNCENDS[e] = f for a in range(f,e-3): dump.WHICHFUNC[a] = f if name: dump.MakeName(f,name)
def _get_strings(self): #return self._get_strings_work() return cache.access(self.bin, lambda x: self._get_strings_work())
def GetMnem(ea): return GetMnem_w(ea) return cache.access((_d,ea), lambda x: GetMnem_w(ea))
error = 0 access_time = 0 page_fault = 0 # counter for number of times address isn't in cache counter = 0 # index for cache_valid # open the first parameter as a file, reach each line and find its virtual address # simulate using the address by seeing if it is already a valid entry in the cache # keep count of the number of times it isn't within the cache (cache miss) # if it isn't in the cache, which will have a limited size of 16 ways # then give it an entry with open(sys.argv[1], 'r') as cache_file: for line in cache_file: try: x = line.split() rw = x[1] # read/write instruction, USEFUL FOR A WRITE BACK-POLICY va = x[2] # virtual address, CONVERT TO INTEGER dc = str(int( va, 16)) # decimal value of virtual address, USEFUL SOMEHOW? # address is assumed 64-bit, 6 is offset, # of bits = set index, # the rest is the tag page_fault, access_time = access(rw, va, access_time) except IndexError: error += 1 except ValueError: error += 1 # print("~~"*10, "Output", "~~"*10) # print("page fault:", page_fault, "- Total accesses:", access_time) print("Cache miss rate: {:0.2%}".format(page_fault / access_time)) cache_file.close()