def test_args(argv, argv_ex=None): if argv_ex is None: argv_ex = argv p = Popen(args.binary, stdin=PIPE, stdout=PIPE, close_fds=True) engine = Engine(input=p.stdout, output=p.stdin, serial_info=serial_info, macro_hooks=[Exit, build_argv_hook(argv), ArgvTest]) print('testing with ', argv) assert engine.init_marker.file.endswith('argv.c') assert engine.run() == 0 print('received ', argv_) print('expected ', argv_ex) assert argv_ == argv_ex
engine = Engine(input=p.stdout, output=p.stdin, serial_info=serial_info) assert engine.init_marker.file.endswith('write.c') assert engine.init_marker.line == 25 engine.write_byte(b'0') assert engine.read_byte() == b'9' engine.write_int(22) assert engine.read_int() == 44 assert engine.write_string("str") == 3 assert engine.read_string() == "tr" engine.write_int(11) assert engine.read_int() == 33 assert engine.write_string("overflow") == 6 assert engine.read_string() == "erfl" engine.write_int(4) assert engine.read_int() == 16 assert engine.write_memory(b'\x00\x01\x02\x03\x04') == 4 assert engine.read_memory() == b'\x03\x02\x01\x00' assert engine.write_memory(b'1234567890') == 4 assert engine.read_memory() == b'1234' assert engine.run() == 123
help="Include folders for the preprocessor", default=[]) parser.add_argument('-D', '--define', nargs='+', help="Defines for the preprocessor", default=[]) args = parser.parse_args() serial_info = generate(args.binary, args.define, args.include) p = Popen(args.binary, stdin=PIPE, stdout=PIPE, close_fds=True) engine = Engine(input=p.stdout, output=p.stdin, serial_info=serial_info) assert engine.init_marker.file.endswith('read.c') assert engine.init_marker.line == 22 assert engine.read_byte() == b'a' assert engine.read_int() == 42 assert engine.read_string() == "test-string" main_ptr = engine.read_int() - engine.base_pointer assert [sym.address for sym in serial_info.symbols if sym.name == 'main'][0] == main_ptr assert int.from_bytes(engine.read_memory(), engine.endianness) == 42 assert engine.read_int() == 1234 assert engine.run() == 42
parser = argparse.ArgumentParser() parser.add_argument('binary', help='The binary that runs on target') parser.add_argument('-S', '--source-dir', required=True, help='The root of the source directory') parser.add_argument('-I', '--include', nargs='+', help="Include folders for the preprocessor", default=[]) parser.add_argument('-D', '--define', nargs='+', help="Defines for the preprocessor", default=[]) args = parser.parse_args() serial_info = generate(args.binary, args.define, args.include) p = Popen(args.binary, stdin=PIPE, stdout=PIPE, close_fds=True) engine = Engine(input=p.stdout, output=p.stdin, serial_info=serial_info, macro_hooks=[Exit, Unit]) assert engine.init_marker.file.endswith('unit.h') assert engine.run() != 0