Skip to content

Commit

Permalink
use PYTHONBIN across the source
Browse files Browse the repository at this point in the history
  • Loading branch information
theguy147 committed Jul 23, 2021
1 parent 590f2b9 commit a5ddc67
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions gef.py
Expand Up @@ -5960,8 +5960,6 @@ def set_fs(uc, addr): return set_msr(uc, FSMSR, addr)
set_gs(emu, SEGMENT_GS_ADDR)
"""

pythonbin = which("python3")

content = """#!{pythonbin} -i
#
# Emulation script for "{fname}" from {start:#x} to {end:#x}
Expand Down Expand Up @@ -6016,7 +6014,7 @@ def reset():
emu = unicorn.Uc({arch}, {mode})
{context_block}
""".format(pythonbin=pythonbin, fname=fname, start=start_insn_addr, end=end_insn_addr,
""".format(pythonbin=PYTHONBIN, fname=fname, start=start_insn_addr, end=end_insn_addr,
regs=",".join(["'%s': %s" % (k.strip(), unicorn_registers[k]) for k in unicorn_registers]),
verbose="True" if verbose else "False",
syscall_reg=current_arch.syscall_register,
Expand Down Expand Up @@ -6105,8 +6103,7 @@ def emulate(emu, start_addr, end_addr):

ok("Starting emulation: {:#x} {} {:#x}".format(start_insn_addr, RIGHT_ARROW, end_insn_addr))

pythonbin = which("python3")
res = gef_execute_external([pythonbin, tmp_filename], as_list=True)
res = gef_execute_external([PYTHONBIN, tmp_filename], as_list=True)
gef_print("\n".join(res))

if not kwargs.get("to_file", None):
Expand Down Expand Up @@ -10681,11 +10678,11 @@ def __gef_prompt__(current_prompt):
# In order to fix it, from the shell with venv activated we run the python binary,
# take and parse its path, add the path to the current python process using sys.path.extend

pythonbin = which("python3")
PREFIX = gef_pystring(subprocess.check_output([pythonbin, '-c', 'import os, sys;print((sys.prefix))'])).strip("\\n")
PYTHONBIN = which("python3")
PREFIX = gef_pystring(subprocess.check_output([PYTHONBIN, '-c', 'import os, sys;print((sys.prefix))'])).strip("\\n")
if PREFIX != sys.base_prefix:
SITE_PACKAGES_DIRS = subprocess.check_output(
[pythonbin, "-c", "import os, sys;print(os.linesep.join(sys.path).strip())"]).decode("utf-8").split()
[PYTHONBIN, "-c", "import os, sys;print(os.linesep.join(sys.path).strip())"]).decode("utf-8").split()
sys.path.extend(SITE_PACKAGES_DIRS)

# setup prompt
Expand Down

0 comments on commit a5ddc67

Please sign in to comment.