def write_full(engine: Engine): try: fd = engine.read_int() dt = engine.read_memory() engine.write_int(os_.write(fd, dt)) except OSError as e: engine.write_int(-1) engine.write_int(map_errno(int(str(e)), errno, Flags))
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
def write_unchecked(engine: Engine): fd = engine.read_int() dt = engine.read_memory() os_.write(fd, dt)
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) 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