def refresh(args): """ Default function for the refresh command line option. Try to map a Structure from a specific offset in memory. Returns it in pickled or text format. See the command line --help . """ log.debug(args) addr = int(args.addr, 16) structType = getKlass(args.structName) mappings = MemoryMapper(args).getMappings() finder = StructFinder(mappings) memoryMap = model.is_valid_address_value(addr, finder.mappings) if not memoryMap: log.error("the address is not accessible in the memoryMap") raise ValueError("the address is not accessible in the memoryMap") instance, validated = finder.loadAt(memoryMap, addr, structType) ## if args.interactive: import code code.interact(local=locals()) if validated: if args.human: print '( %s, %s )' % (instance.toString(), validated) else: d = (instance.toPyObject(), validated) if model.findCtypesInPyObj(d[0]): log.error( '=========************======= CTYPES STILL IN pyOBJ !!!! ') if args.json: #jsoned print json.dumps(ret) else: #pickled print pickle.dumps(d) else: if args.human: #Unloaded datastruct, printing safe __str__ print '( %s, %s )' % (instance, validated) else: d = None if args.json: #jsoned print json.dumps(ret) else: #pickled print pickle.dumps(d) return instance, validated
def refresh(args): """ Default function for the refresh command line option. Try to map a Structure from a specific offset in memory. Returns it in pickled or text format. See the command line --help . """ log.debug(args) addr=int(args.addr,16) structType=getKlass(args.structName) mappings = MemoryMapper(args).getMappings() finder = StructFinder(mappings) memoryMap = model.is_valid_address_value(addr, finder.mappings) if not memoryMap: log.error("the address is not accessible in the memoryMap") raise ValueError("the address is not accessible in the memoryMap") instance,validated = finder.loadAt( memoryMap , addr, structType) ## if args.interactive: import code code.interact(local=locals()) if validated: if args.human: print '( %s, %s )'%(instance.toString(),validated) else: d=(instance.toPyObject(),validated) if model.findCtypesInPyObj(d[0]): log.error('=========************======= CTYPES STILL IN pyOBJ !!!! ') if args.json: #jsoned print json.dumps(ret) else: #pickled print pickle.dumps(d) else: if args.human: #Unloaded datastruct, printing safe __str__ print '( %s, %s )'%(instance,validated) else: d=None if args.json: #jsoned print json.dumps(ret) else: #pickled print pickle.dumps(d) return instance,validated
def searchIn(structName, mappings, targetMappings=None, maxNum=-1): """ Search a structure in a specific memory mapping. if targetMappings is not specified, the search will occur in each memory mappings in mappings. @param structName the structure name. @param mappings the memory mappings list. @param targetMappings the list of specific mapping to look into. @param maxNum the maximum number of results expected. -1 for infinite. """ log.debug('searchIn: %s - %s' % (structName, mappings)) structType = getKlass(structName) finder = StructFinder(mappings, targetMappings) # find all possible structType instance outs = finder.find_struct(structType, maxNum=maxNum) # prepare outputs ret = [(ss.toPyObject(), addr) for ss, addr in outs] if len(ret) > 0: log.debug("%s %s" % (ret[0], type(ret[0]))) if model.findCtypesInPyObj(ret): log.error('=========************======= CTYPES STILL IN pyOBJ !!!! ') return ret
def searchIn(structName, mappings, targetMappings=None, maxNum=-1): """ Search a structure in a specific memory mapping. if targetMappings is not specified, the search will occur in each memory mappings in mappings. @param structName the structure name. @param mappings the memory mappings list. @param targetMappings the list of specific mapping to look into. @param maxNum the maximum number of results expected. -1 for infinite. """ log.debug('searchIn: %s - %s'%(structName,mappings)) structType = getKlass(structName) finder = StructFinder(mappings, targetMappings) # find all possible structType instance outs=finder.find_struct( structType, maxNum=maxNum) # prepare outputs ret=[ (ss.toPyObject(),addr) for ss, addr in outs] if len(ret) >0: log.debug("%s %s"%(ret[0], type(ret[0]) ) ) if model.findCtypesInPyObj(ret): log.error('=========************======= CTYPES STILL IN pyOBJ !!!! ') return ret
## debug if args.interactive: import code code.interact(local=locals()) ## if args.human: print '[', for ss, addr in outs: print "# --------------- 0x%lx \n" % addr, ss.toString() pass print ']' else: ret = [(ss.toPyObject(), addr) for ss, addr in outs] if len(ret) > 0: log.debug("%s %s" % (ret[0], type(ret[0]))) if model.findCtypesInPyObj(ret): log.error( '=========************======= CTYPES STILL IN pyOBJ !!!! ') if args.json: #jsoned print json.dumps(ret, default=model.json_encode_pyobj ) #cirular refs kills it check_circular=False, else: #pickled print pickle.dumps(ret) return outs def refresh(args): """ Default function for the refresh command line option. Try to map a Structure from a specific offset in memory. Returns it in pickled or text format.
## debug if args.interactive: import code code.interact(local=locals()) ## if args.human: print '[', for ss, addr in outs: print "# --------------- 0x%lx \n"% addr, ss.toString() pass print ']' else: ret=[ (ss.toPyObject(),addr) for ss, addr in outs] if len(ret) >0: log.debug("%s %s"%(ret[0], type(ret[0]) ) ) if model.findCtypesInPyObj(ret): log.error('=========************======= CTYPES STILL IN pyOBJ !!!! ') if args.json: #jsoned print json.dumps(ret, default=model.json_encode_pyobj ) #cirular refs kills it check_circular=False, else: #pickled print pickle.dumps(ret) return outs def refresh(args): """ Default function for the refresh command line option. Try to map a Structure from a specific offset in memory. Returns it in pickled or text format. See the command line --help .