def main(options): """ Read the specified memory region and record statistics """ # Initilize our experiment client = MemorySensorPhysical(options.target, cache_timeout=0, use_threading=True) READ_SIZE = int(options.read_size)*85 start_addr = options.startaddr # Read memory offset = 0 read_rates = [] total_read = 0 count = 0 output = open(options.output_file, "w+") output.write("Memory Address,Bytes Read,Time Elapsed,Bytes/Second\n") for addr in xrange(start_addr,2**30, READ_SIZE): try: time_start = time.time() data = client.read(addr, READ_SIZE) time_elapsed = (time.time() - time_start) total_read += len(data) count += 1 rate = (len(data)/time_elapsed) print "Addr: 0x%08X, Read: %d bytes, %f bytes/sec" % (addr, len(data), rate) output.write("0x%08X,%d,%f,%f\n" % (addr, len(data), time_elapsed, rate)) read_rates.append(rate) except: import traceback traceback.print_exc() # Just finish up break output.close()
def main(options): """ Read the specified memory region and record statistics """ # Initilize our experiment client = MemorySensorPhysical(options.target, cache_timeout=0, use_threading=True) READ_SIZE = int(options.read_size) * 85 start_addr = options.startaddr # Read memory offset = 0 read_rates = [] total_read = 0 count = 0 output = open(options.output_file, "w+") output.write("Memory Address,Bytes Read,Time Elapsed,Bytes/Second\n") for addr in xrange(start_addr, 2**30, READ_SIZE): try: time_start = time.time() data = client.read(addr, READ_SIZE) time_elapsed = (time.time() - time_start) total_read += len(data) count += 1 rate = (len(data) / time_elapsed) print "Addr: 0x%08X, Read: %d bytes, %f bytes/sec" % ( addr, len(data), rate) output.write("0x%08X,%d,%f,%f\n" % (addr, len(data), time_elapsed, rate)) read_rates.append(rate) except: import traceback traceback.print_exc() # Just finish up break output.close()
def main(options): if options.replay_file is not None: cap_reader = CaptureReader(options.replay_file) for (ts, data) in cap_reader: print "Time: ", ts, "s" print MemorySensorPacket(data) return if options.sensor_type == G.MACHINE_TYPES.PHYSICAL: client = MemorySensorPhysical(options.target, cache_timeout=0, use_threading=False) else: client = MemorySensorVirtual(options.target) READ_SIZE = int(options.read_size) start_addr = options.startaddr # Create our output file try: os.makedirs(os.path.dirname(options.output)) except: pass try: mcap_writer = None if options.loop_forever == True: logger.debug("Creating capture file.") options.output += ".mcap" mcap_writer = CaptureWriter(options.output) mcap_writer.start() else: logger.debug("Creating dump file.") options.output += ".mfd" output_file = open(options.output, "w+") except: print "ERROR: Could not open output file." sys.exit(0) # Read memory count = 0 start = time.time() sensor_packet = MemorySensorPacket() while True: try: # Get memory from remote system # Read memory data = client.read(start_addr, READ_SIZE) # Write to file? if not options.loop_forever: output_file.write(data) else: sensor_packet.address = start_addr sensor_packet.data = data sensor_packet.length = READ_SIZE mcap_writer.put(sensor_packet) # Just read once? if not options.loop_forever: break else: print "Completed read #%d" % count count += 1 except: # Just finish up break end = time.time() # Do we have an mcap file to close? if mcap_writer is not None: mcap_writer.stop() else: # Close output file output_file.close() print "Memory dump (%d bytes) written to %s. Took %s seconds." % ( len(data), options.output, end - start)
def main(options): if options.replay_file is not None: cap_reader = CaptureReader(options.replay_file) for (ts, data) in cap_reader: print "Time: ", ts, "s" print MemorySensorPacket(data) return if options.sensor_type == G.MACHINE_TYPES.PHYSICAL: client = MemorySensorPhysical(options.target, cache_timeout=0, use_threading=False) else: client = MemorySensorVirtual(options.target) READ_SIZE = int(options.read_size) start_addr = options.startaddr # Create our output file try: os.makedirs(os.path.dirname(options.output)) except: pass try: mcap_writer = None if options.loop_forever == True: logger.debug("Creating capture file.") options.output += ".mcap" mcap_writer = CaptureWriter(options.output) mcap_writer.start() else: logger.debug("Creating dump file.") options.output += ".mfd" output_file = open(options.output, "w+") except: print "ERROR: Could not open output file." sys.exit(0) # Read memory count = 0 start = time.time() sensor_packet = MemorySensorPacket() while True: try: # Get memory from remote system # Read memory data = client.read(start_addr, READ_SIZE) # Write to file? if not options.loop_forever: output_file.write(data) else: sensor_packet.address = start_addr sensor_packet.data = data sensor_packet.length = READ_SIZE mcap_writer.put(sensor_packet) # Just read once? if not options.loop_forever: break else: print "Completed read #%d"%count count += 1 except: # Just finish up break end = time.time() # Do we have an mcap file to close? if mcap_writer is not None: mcap_writer.stop() else: # Close output file output_file.close() print "Memory dump (%d bytes) written to %s. Took %s seconds." % (len(data),options.output,end-start)