diff --git a/.gitignore b/.gitignore index ae78e5e..d9cce26 100644 --- a/.gitignore +++ b/.gitignore @@ -72,3 +72,9 @@ svg-to-pdf.ps1 ehthumbs.db Thumbs.db +# Logs written by the Binary Ninja console helpers (build / flash / OpenOCD) +openocd.log +flash.log +build.log +build-flash.log + diff --git a/WEEK04/WEEK04-BN.md b/WEEK04/WEEK04-BN.md index 7530dd9..3867acf 100644 --- a/WEEK04/WEEK04-BN.md +++ b/WEEK04/WEEK04-BN.md @@ -403,6 +403,37 @@ BP_ADDR=0x10000234 ./debug-server.sh $env:BP_ADDR="0x10000234"; .\debug-server.ps1 ``` +**Or start it from the Binary Ninja console**, freeing the probe first and launching the server in the background so the console returns immediately: + +**macOS Apple Silicon / Linux x64:** + +```python +import os, subprocess +root = os.path.dirname(os.path.dirname(os.path.dirname(bv.file.original_filename))) # +subprocess.run(["pkill", "-TERM", "-f", "openocd"]) # stop any running server first +log = os.path.join(root, "openocd.log") +p = subprocess.Popen([os.path.join(root, "debug-server.sh")], cwd=root, + env=dict(os.environ, BP_ADDR="0x10000234"), + stdout=open(log, "w"), stderr=subprocess.STDOUT, start_new_session=True) +print("OpenOCD started (pid", p.pid, "); log:", log) +``` + +**Windows x64:** + +```python +import os, subprocess +root = os.path.dirname(os.path.dirname(os.path.dirname(bv.file.original_filename))) # +subprocess.run(["taskkill", "/F", "/IM", "openocd.exe"]) # stop any running server first +log = os.path.join(root, "openocd.log") +p = subprocess.Popen(["powershell", "-ExecutionPolicy", "Bypass", "-File", + os.path.join(root, "debug-server.ps1")], cwd=root, + env=dict(os.environ, BP_ADDR="0x10000234"), + stdout=open(log, "w"), stderr=subprocess.STDOUT) +print("OpenOCD started (pid", p.pid, "); log:", log) +``` + +`Popen` returns in a few milliseconds; the server keeps running in the background. Check `openocd.log` for `Listening on port 3333`, then connect in Step 11. + Wait for: ``` diff --git a/WEEK04/WEEK04-BN.pdf b/WEEK04/WEEK04-BN.pdf index 1870ded..d96c193 100644 Binary files a/WEEK04/WEEK04-BN.pdf and b/WEEK04/WEEK04-BN.pdf differ