diff options
Diffstat (limited to 'example/jitter/run_with_linuxenv.py')
| -rw-r--r-- | example/jitter/run_with_linuxenv.py | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/example/jitter/run_with_linuxenv.py b/example/jitter/run_with_linuxenv.py index f4900a96..fda76f9a 100644 --- a/example/jitter/run_with_linuxenv.py +++ b/example/jitter/run_with_linuxenv.py @@ -24,8 +24,8 @@ if args.verbose: syscall.log.setLevel(logging.DEBUG) # Get corresponding interpreter and reloc address -cont_target_tmp = Container.from_stream(open(args.target)) -ld_path = str(cont_target_tmp.executable.getsectionbyname(".interp").content).strip("\x00") +cont_target_tmp = Container.from_stream(open(args.target, 'rb')) +ld_path = bytes(cont_target_tmp.executable.getsectionbyname(".interp").content).strip(b"\x00") if cont_target_tmp.executable.Ehdr.type in [elf_csts.ET_REL, elf_csts.ET_DYN]: elf_base_addr = 0x40000000 elif cont_target_tmp.executable.Ehdr.type == elf_csts.ET_EXEC: @@ -52,29 +52,38 @@ else: # Load the interpreter in memory, applying relocation linux_env = LinuxEnvironment() -linux_env.filesystem.passthrough.append(re.compile(args.passthrough)) +linux_env.filesystem.passthrough.append(re.compile(args.passthrough.encode())) ld_path = linux_env.filesystem.resolve_path(ld_path) -cont_ld = Container.from_stream(open(ld_path), - vm=jitter.vm, - addr=0x80000000, - apply_reloc=True) +cont_ld = Container.from_stream( + open(ld_path, "rb"), + vm=jitter.vm, + addr=0x80000000, + apply_reloc=True +) # Load the target ELF in memory, without applying reloc loc_db = cont_ld.loc_db -cont_target = Container.from_stream(open(args.target), vm=jitter.vm, - loc_db=loc_db, - addr=elf_base_addr, - apply_reloc=False) +cont_target = Container.from_stream( + open(args.target, "rb"), + vm=jitter.vm, + loc_db=loc_db, + addr=elf_base_addr, + apply_reloc=False +) # PHDR containing the PH header -elf_phdr_header = [ph32.ph for ph32 in cont_target.executable.ph - if ph32.ph.type == elf_csts.PT_PHDR][0] +elf_phdr_header = next( + ph32.ph for ph32 in cont_target.executable.ph + if ph32.ph.type == elf_csts.PT_PHDR +) # Prepare the desired environment -argv = [args.target] + args.extra_args +argv = [args.target.encode()] + [arg.encode() for arg in args.extra_args] if args.flags: argv += ["-%s" % args.flags] -envp = {"PATH": "/usr/local/bin", "USER": linux_env.user_name} -auxv = environment.AuxVec(elf_base_addr + elf_phdr_header.vaddr, - cont_target.entry_point, linux_env) +envp = {b"PATH": b"/usr/local/bin", b"USER": linux_env.user_name} +auxv = environment.AuxVec( + elf_base_addr + elf_phdr_header.vaddr, + cont_target.entry_point, linux_env +) prepare_loader(jitter, argv, envp, auxv, linux_env) syscall.enable_syscall_handling(jitter, linux_env, syscall_callbacks) |