Skip to content

Commit

Permalink
Needed a bit more work to get rid of need to run Binja and PyCharm fr…
Browse files Browse the repository at this point in the history
…om a shell.
  • Loading branch information
jim-carciofini committed Feb 14, 2024
1 parent baff77b commit ba9b658
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
8 changes: 4 additions & 4 deletions pate_binja/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ export PATE_BINJA_MODE=BUILD
Once Binary Ninja is running, you can run PATE from the "Plugins" menu. An open file dialog will open. By defualt it will be looking for a PATE Run Configuration file (*.run-config.json). If you want to run a replay file, select "PATE Replay (*.json)" in the file type drop down menu.


## Developer Notes (macOS with PyCharm Pro)
## Developer Notes (macOS with PyCharm)

You must launch PyCharm Pro from a bash shell because it needs your bash environment. For example, on macOS:
To run demos in tty mode, you need to define an environment variable to point at the clone of the [PATE Binja Demos repo](https://gitlab-ext.galois.com/pate/pate-binja-demos):
```bash
open /Applications/PyCharm.app
export PATE_BINJA_DEMOS=<demos dir>
```

To install the Binja api for completion in PyCharm:
Expand All @@ -57,7 +57,7 @@ To install the Binja api for completion in PyCharm:
- Go to python console (runs within venv)
- python /Applications/Binary\ Ninja.app/Contents/Resources/scripts/install_api.py

To setup debugging:
To set up debugging under Binary Ninja (requires PyCharm Pro):

- See https://docs.binary.ninja/dev/plugins.html#remote-debugging-with-intellij-pycharm
- In Binja settings specify python interpreter and site package dir to point at your Pycharm project venv installs.
Expand Down
14 changes: 5 additions & 9 deletions pate_binja/pate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,17 +1272,13 @@ def run_pate_config(file):


def run_pate(cwd: str, original: str, patched: str, args: list[str]) -> Popen:
if os.getenv('PATE_BINJA_MODE') == 'BUILD':
pate = [os.getenv('PATE') + '/pate.sh']
else:
pate = ['docker', 'run', '--rm', '-i', '-v', '.:/work', '--workdir=/work', 'pate']
bash_cmd = " ".join(pate + ['-o', original, '-p', patched, '--json-toplevel'] + args)
#print("Bash cmd: " + bash_cmd)
# Need -l to make sure user's env is fully setup (e.g. access to docker and ghc tools)
return Popen(['/bin/bash', '-l', '-c', bash_cmd],
# We use a helper script to run logic in the user's shell environment.
script = os.path.join(os.path.dirname(os.path.abspath(__file__)), "run-pate.sh")
# Need -l to make sure user's env is fully setup (e.g. access to docker and ghc tools).
return Popen(['/bin/bash', '-l', script, '-o', original, '-p', patched, '--json-toplevel'] + args,
cwd=cwd,
stdin=PIPE, stdout=PIPE, text=True, encoding='utf-8'
)
)


def run_pate_config_or_replay_file(f: str) -> Popen:
Expand Down
12 changes: 12 additions & 0 deletions pate_binja/run-pate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Shell script used by PATE Binja plugin to run pate.
# This is done with a script so that all is evaluated within the users's shell environment.

if [ "$PATE_BINJA_MODE" = "BUILD" ]
then
pate="$PATE/pate.sh"
else
pate="docker run --rm -i -v .:/work --workdir=/work pate"
fi

$pate "$@"

0 comments on commit ba9b658

Please sign in to comment.