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 . """ # we need an int memory_address = args.addr # get the memory handler adequate for the type requested memory_handler = _get_memory_handler(args) # print output on stdout rtype = _get_output_style(args) # check the validity of the address heap = memory_handler.is_valid_address_value(memory_address) if not heap: log.error("the address is not accessible in the memoryMap") raise ValueError("the address is not accessible in the memoryMap") # get the structure name modulename, sep, classname = args.struct_name.rpartition('.') module = memory_handler.get_model().import_module(modulename) struct_type = getattr(module, classname) # load the record result = api.load_record(memory_handler, struct_type, memory_address) results = [result] if args.validate: my_constraints = None if args.constraints_file: handler = constraints.ConstraintsConfigHandler() my_constraints = handler.read(args.constraints_file.name) validation = api.validate_record(memory_handler, result[0], my_constraints) if args.interactive: import code code.interact(local=locals()) # output handling ret = None if rtype == 'string': ret = api.output_to_string(memory_handler, results) elif rtype == 'python': ret = api.output_to_python(memory_handler, results) elif rtype == 'json': ret = api.output_to_json(memory_handler, results) elif rtype == 'pickled': ret = api.output_to_pickle(memory_handler, results) else: raise ValueError('unknown output format') print ret if args.validate: print 'Validated', validation return
def show_cmdline(args): """Cast the bytes at this address into a record_type. """ # we need an int memory_address = args.address # get the memory handler adequate for the type requested memory_handler = get_memory_handler(args) # check the validity of the address heap = memory_handler.is_valid_address_value(memory_address) if not heap: log.error("the address is not accessible in the memoryMap") raise ValueError("the address is not accessible in the memoryMap") # get the structure name modulename, sep, classname = args.record_type_name.rpartition('.') module = None try: module = memory_handler.get_model().import_module(modulename) except ImportError as e: log.error('sys.path is %s', sys.path) raise e record_type = getattr(module, classname) # load the record result = api.load_record(memory_handler, record_type, memory_address) results = [result] # validate if required validation = None if args.constraints_file: handler = constraints.ConstraintsConfigHandler() my_constraints = handler.read(args.constraints_file.name) validation = api.validate_record(memory_handler, result[0], my_constraints) # output handling ret = None try: ret = get_output(memory_handler, results, args.output) # print output on stdout print ret if args.constraints_file: print 'Validated', validation except Exception as e: log.error(e) finally: if args.interactive: print 'results are local variable "results"' import code code.interact(local=locals()) return