def symlink(engine: Engine): try: existing = engine.read_string() _new = engine.read_string() os_.symlink(existing, _new) engine.write_int(0) except OSError as e: engine.write_int(map_errno(int(str(e)), errno, Flags))
def unlink(engine: Engine): try: name = engine.read_string() os_.unlink(name) engine.write_int(0) except OSError as e: engine.write_int(map_errno(int(str(e)), errno, Flags))
def stat_(engine: Engine): try: file = engine.read_string() st = os_.stat(file) engine.write_int(0) write_stat(engine, st) except OSError as e: engine.write_int(map_errno(int(str(e)), errno, Flags))
def open_full(engine: Engine): try: file = engine.read_string() flags = map_open_flags(engine.read_int(), Flags, os_) mode = map_file_mode(engine.read_int(), Flags, os_) engine.write_int(os_.open(file, flags, mode)) except OSError as e: engine.write_int(-1) engine.write_int(map_errno(int(str(e)), errno, Flags))
def open_unchecked(engine: Engine): file = engine.read_string() try: flags = map_open_flags(engine.read_int(), Flags, os_) mode = map_file_mode(engine.read_int(), Flags, os_) target_fd = engine.read_int() unchecked_map[target_fd] = os_.open(file, flags, mode) except OSError as e: print("Error opening file {} : {}".format(file, e), file=sys.stderr)
stderr=sys.stdout.buffer, close_fds=True) 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'
def invoke(self, engine: Engine, macro_expansion: MacroExpansion): l = engine.read_int() global argv_ argv_ = [engine.read_string() for i in range(l)]
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