Repository navigation
feat(ghidra): select an existing-project program inside a project folder - #3817
whalemenace wants to merge 1 commit into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Low impact] The new folder-selection changes appear safe to merge, with two earlier non-blocking findings still outstanding. FindingsFix with agent prompt### Issue 1
src/config/ghidraPersistentProject.ts:86-90
On POSIX, a project basename containing a backslash passes validation but changes before launch. For example, `/work/prefix\Game.gpr` becomes project location `/work` and project name `Game`. The launcher then opens a different project or fails to find it.
Reject basenames that cannot be passed unchanged, including after `realpath`, rather than dropping part of the selected name.
### Issue 2
bridge/ghidra/ReaGhidraBridge.java:229-235
The persistent digest check runs after the old raw-import preparation check. If the selected target is an admitted PE or ELF but `REA_GHIDRA_PROGRAM` points to an ordinary raw-imported Program, the bridge throws for a missing REA preparation marker before reaching this branch. The caller gets a generic startup failure instead of `unsupported_target` naming both digests.
Run the persistent identity path before import-only checks, and keep those checks out of persistent startup.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryBuilds on existing-project reuse already merged in #7236. The current diff adds
No new actionable findings were established. Review was source-based; no tests or real Ghidra session were run. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Project, Program and optional folder] --> B[Validate selection]
B --> C[Commit folder and project fingerprint]
C --> D[Check configuration against profile]
D --> E[Copy and verify whole project]
E --> F[Open copied project and folder]
F --> G[Process one Program read-only]
Reviews (2) · Last reviewed commit: "feat(ghidra): select an existing-project..." · Reviewed by Greptile |
| projectLocation: path.dirname(project.projectFile), | ||
| projectName: finalComponent(project.projectFile).slice( | ||
| 0, | ||
| -GHIDRA_PROJECT_FILE_SUFFIX.length, | ||
| ), |
There was a problem hiding this comment.
On POSIX, a project basename containing a backslash passes validation but changes before launch. For example, /work/prefix\Game.gpr becomes project location /work and project name Game. The launcher then opens a different project or fails to find it.
Reject basenames that cannot be passed unchanged, including after realpath, rather than dropping part of the selected name.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/config/ghidraPersistentProject.ts
Line: 86-90
Comment:
**Selected project names change**
On POSIX, a project basename containing a backslash passes validation but changes before launch. For example, `/work/prefix\Game.gpr` becomes project location `/work` and project name `Game`. The launcher then opens a different project or fails to find it.
Reject basenames that cannot be passed unchanged, including after `realpath`, rather than dropping part of the selected name.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
@whalemenace I independently checked this at head 916a2f9d7 using an actual Linux temporary file named prefix\\Game.gpr. POSIX realpath preserves the backslash as part of the filename, but the current acceptance predicate treats it as a separator, and ghidraPersistentProjectLocation produces projectName: "Game" instead of the selected filename's stem.
This was an isolated Node reproduction of the relevant source logic, not REA's Zod/Vitest suite or a real Ghidra launch. A focused regression could create that filename, pass it through ghidraProjectFileSchema and resolved-path handling, then assert either an actionable early rejection or exact preservation of the requested project name. I’m adding the confirmation to this existing thread rather than repeating the finding as a new top-level report. Happy to contribute the regression to your branch.
There was a problem hiding this comment.
Confirmed — this reproduces a real correctness bug. On POSIX, \ is a valid filename character, but finalComponent() treats it as a separator, so ghidraPersistentProjectLocation() can launch with a truncated projectName rather than the caller-selected project.
The safest fix is to reject \ in the .gpr basename during schema validation, matching analyzeHeadless’s cross-platform argument handling, and add the focused regression you described. Thanks for independently validating it; a regression test covering early rejection or exact preservation would be welcome.
Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.
There was a problem hiding this comment.
@whalemenace, following up with a tested correction for this existing review finding, based on your current PR head 916a2f9d7696f3679ed6074638875a320c3e6399.
My isolated fork branch contains a focused path regression and a small fix: use the platform's path parser for project basename extraction, reject backslash-bearing POSIX project paths before launch, and revalidate the resolved realpath so a safe-looking symlink cannot select an unsafe marker. A normal Fixture.gpr project + nested Program selection remains accepted. The test and source-fix commits are separate from the fork-only CI workflow.
The original PR code failed the two new unsafe-path cases (and passed the ordinary-path control): failing run. The corrected branch passed 72 focused tests (4 Windows-only skips) spanning this regression, existing GhidraPersistentProject and launcher tests, plus test discovery, docs checks and fresh typecheck/lint with zero cached static tasks: verified run.
These are genuine Node/REA boundary tests on Ubuntu 24.04 / Node 24.18.0, not a real Ghidra execution or Windows-native test. The path fix is deliberately limited to the existing review finding and does not address your separate seed-metadata issue.
If it fits your approach, feel free to incorporate it; I'm happy to adjust the tests to your preferred owning boundary. No competing PR was opened.
There was a problem hiding this comment.
Thanks for the tested correction. I rechecked the current implementation: finalComponent() unconditionally treats both separators as delimiters, so a POSIX .gpr basename containing \\ is indeed truncated before analyzeHeadless is invoked. The symlink case is also relevant when the resolved marker path is what gets launched: validating only the lexical path can allow the resolved basename to violate the same argument boundary.
The proposed fix—use the selected platform parser for basename extraction, reject backslashes in POSIX project-marker names before launch, and revalidate the resolved realpath—addresses the finding while preserving ordinary and nested Program paths. The focused regression and reported 72-test verification provide appropriate coverage. Please incorporate the source and regression changes, without requiring the fork-only workflow; I’ll consider the original finding resolved once they are on the PR head.
| if (persistentProject(descriptor)) { | ||
| // A caller-selected project may hold another artifact. Serve only the | ||
| // handshake so REA can report both digests, and refuse every analysis. | ||
| persistentProgramSha256 = importedSha256 != null && | ||
| importedSha256.toLowerCase(Locale.ROOT).matches("[0-9a-f]{64}") | ||
| ? importedSha256.toLowerCase(Locale.ROOT) : null; | ||
| persistentIdentityRefused = !identityMatches; |
There was a problem hiding this comment.
Raw Programs hide digest errors
The persistent digest check runs after the old raw-import preparation check. If the selected target is an admitted PE or ELF but REA_GHIDRA_PROGRAM points to an ordinary raw-imported Program, the bridge throws for a missing REA preparation marker before reaching this branch. The caller gets a generic startup failure instead of unsupported_target naming both digests.
Run the persistent identity path before import-only checks, and keep those checks out of persistent startup.
Knowledge Base Used: Ghidra integration
Prompt To Fix With AI
This is a comment left during a code review.
Path: bridge/ghidra/ReaGhidraBridge.java
Line: 229-235
Comment:
**Raw Programs hide digest errors**
The persistent digest check runs after the old raw-import preparation check. If the selected target is an admitted PE or ELF but `REA_GHIDRA_PROGRAM` points to an ordinary raw-imported Program, the bridge throws for a missing REA preparation marker before reaching this branch. The caller gets a generic startup failure instead of `unsupported_target` naming both digests.
Run the persistent identity path before import-only checks, and keep those checks out of persistent startup.
**Knowledge Base Used:** [Ghidra integration](https://app.greptile.com/pre/-/custom-context/knowledge-base/morluto/rea/-/docs/ghidra-integration.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.|
TL;DR: Thanks, whalemenace, for this work. Both test files, the typecheck and the real Ghidra 12.1.4 script pass on Linux. Opening the project changed two backup files, and the script does not check those. ResultsThe 2 test files are the unit file and the launcher file (names in the Commands fold). The 4 skipped launcher tests are Windows-only, and main skips them too. "Main" is c7f6b8b (#4179). "Merged" is main plus this pull request (head 916a2f9), joined with a 3-way merge of 19 changed files and 5 new files. Every file merged with no conflict. This is a new feature, so there is no before and after on main.
What the real script checkedWhat the real script showed:
Note for the authorThe script reports that opening the project changed two files: Not run
No test in these files makes a network call. The script starts only local processes: Ghidra headless and REA's own server. Thanks, whalemenace, for the clear tests and the script. Commandsgit -C ~/code/rea-mirror/rea.git fetch origin
# main c7f6b8bad extracted to a scratch folder; for each file the pull request changes:
git merge-file -p <main-version> <merge-base-version> <head-version>
npm ci && npm run build && npm run test:prepare
npm run typecheck
npm run test:focused -- src/ghidra/GhidraPersistentProject.test.ts tests/boundary/providers/ghidra/ghidraLauncher.test.ts
npm run build
GHIDRA_INSTALL_DIR=~/.local/opt/ghidra_12.1.4_PUBLIC JAVA_HOME=~/.local/opt/jdk-21.0.12.1+1 \
systemd-run --user --scope -p MemoryMax=8G -- node scripts/verify-real-ghidra-persistent.mjsRaw output"ghidra_version": "12.1.4",
"project_analysis_ms": 7149,
"rea_open_and_first_decompile_ms": 5796,
"import_mode": "persistent-project-read-only",
"annotation_refusal": "capability_unavailable",
"mismatch_refusal": "unsupported_target",
"project_files_changed_by_open": [
"Fixture.rep/idata/~index.bak",
"Fixture.rep/idata/~journal.bak"
],
"cleanup": "complete"Test setup
🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
|
Thank you for the real-project investigation and verification. #7236 now reuses a caller-selected project through a verified read-only copy, with the original project left unchanged. Your PR also proposes selecting a program inside a project folder and opening the original project directly; the merged mode selects a root program and deliberately uses a copy. I am keeping this open for that distinct scope. If you would like to continue, could you focus on the folder-selection use case and assess it against the existing copy/identity owner? I did not rerun Ghidra in this pass. |
REA_GHIDRA_PROGRAM_FOLDER selects a non-root project folder for the program named by REA_GHIDRA_PROGRAM_NAME. The selection goes through the existing verified-copy owner: the folder is committed in the project profile (absent for the root, so root profiles keep their digest), the whole selected project is still fingerprinted, copied and re-verified, and the owned copy is opened as <project>/<folder> with -process naming one program. Malformed folders are refused at configuration and again before the headless arguments are built; a profile resolved for one folder does not open under another. Co-Authored-By: Claude Opus 5.5 <[email protected]>
916a2f9 to
f8abf28
Compare
|
Thanks for merging #7236, and for keeping this one open for the folder case. I agree the verified copy is the right owner. Cassie's run showed that opening the project in place still rewrote |
|
Real-provider follow-up on exact head I copied a self-owned project, then used separate headless Ghidra scripts to create two programs named One recovery case merits attention when resolving the existing merge conflict: with folder This is one small macOS project and Ghidra version; no Windows provider, folder changes during copying, CLI, unusual folder characters or large-project performance were tested. The root import logged unrelated unrecoverable DWARF expressions; no debug-info completeness claim is made. The selected binary was not executed. |
|
CLI and target-identity follow-up on the same exact head
The selected project and both target-file SHA-256 inventories were unchanged after the calls, and neither binary was executed. These are positive and negative checks of this old PR head, not a test of a future conflict resolution or of other platforms. |
|
I checked the interaction with the newer missing-program recovery in a local exploratory merge, not the PR head or a proposed final conflict resolution. Base was main On the same real macOS/Ghidra 12.1.4 project through MCP:
All sessions closed; target and 12 source-project file content hashes were unchanged. This was one merge resolution, host, project and provider version. It is evidence to inform the eventual conflict resolution, not a claim that this exact merge is ready or that any particular log-parsing technique is safe. A precise recovery should preserve the caller's folder choice and distinguish a missing folder from a missing program where the producer establishes that distinction. |
|
Current-main POSIX follow-up to the earlier exact-head and older-merge tests: I applied PR head With real Ghidra 12.1.4 on macOS arm64, I copied the owned test project and, before the REA calls, created The two recovery gaps from the earlier merge test remain on this resolution:
|
|
Cross-session Evidence handoff on the same locally resolved PR/main experiment described above:
The agent can therefore preserve and compare Evidence across the currently required process restart, but it still must explicitly manage the bundle and inspect the source profiles/mappings. Source inspection shows the current existing-project profile does not supply a common function-coordinate commitment; the conservative ambiguous comparison is expected and should not be “fixed” by equating addresses across arbitrary projects. The target and source-project hashes were unchanged during these REA calls. This test is of the local conflict resolution, not the exact PR head or a merged change. |
|
@whalemenace — I revisited this PR's exact unchanged head
I ran an isolated Node/POSIX filesystem reproduction (4/4 controls passed); the complete REA Vitest suite, formatter/typecheck and real Ghidra were not run on this candidate. The earlier real-host verification in this thread is separate. If this approach fits your narrowed folder-selection PR, please review/incorporate these small hunks on your branch; I'd avoid creating another upstream PR. The other outstanding issue is the existing current-main integration/recovery work that @morluto already reproduced: missing program under a selected folder should not recommend the root, and a nonexistent folder still produces generic guidance. That should be reconciled against current main and fixed at the owning error boundary, not by guessing from Ghidra log strings. I haven't added a speculative recovery parser or altered that behavior. |
|
@whalemenace — qualification follow-up to my earlier #3817 path-validation patch: the formatted source candidate is now Exact-source fork CI passed on a separate, workflow-only validation branch (its source files are byte-identical to
This updates the earlier source-only evidence; the two-line formatter correction is already in the candidate. I've left your branch untouched and haven't opened an upstream replacement. Your current-main missing-folder/missing-program recovery findings remain a separate, unaddressed integration concern. |
|
Hey @whalemenace, thanks for this! The addition looks good. What's left: it has merge conflicts with main in |
Problem
#7236 reuses a caller-selected Ghidra project through a verified read-only copy. Its program selection is limited to the project root:
REA_GHIDRA_PROGRAM_NAMErefuses/, and the launcher passes the bare project name, so-processonly searches/. Projects that keep programs in folders (for example/firmware/v2/app) cannot be reused without first moving the program to the root in Ghidra.Fix
REA_GHIDRA_PROGRAM_FOLDER(requiresREA_GHIDRA_PROJECT_PATH): one absolute, non-root project folder such as/firmware/v2. It refuses/, relative paths, trailing slashes, empty,.and..segments, padded segments,*,?, backslashes and control characters. The root is selected by omitting the setting, so each folder has one spelling.REA_GHIDRA_PROGRAM_NAMEis unchanged and still refuses paths.resolveGhidraProjectcommits the folder asprogram_folderin the existing project commitment. The key is absent for the root, so root profiles and their digests do not change.<project>/<folder>with-process <program>, following analyzeHeadless's<project_name>[/<folder_path>]argument. The folder is checked again before arguments are built.rea setupkeeps the new setting in saved registrations. Installation docs and the skill reference describe it.Assessment against #7236
GhidraProjectSnapshot.tsowns selection and identity.resolveGhidraProjectcommits the configured path, the resolved project directory and name, the program name and a SHA-256 over the whole.gpr/.reppair (fingerprintGhidraProject, sorted 64 KiB streaming reads; symlinks and non-regular entries refused).copyExistingGhidraProjectcopies only that pair into the owned runtime, refuses overlap with the runtime, and re-fingerprints the copy against the committed digest. The launcher runs-process <program> -noanalysis -readOnlyon the copy. The bridge still checks the program's recorded import SHA-256 against the admitted target and blocks database edits..repdatabase, so the copied content, its fingerprint and the import-digest check are the same for every folder. The folder only changes the project argument passed to analyzeHeadless and becomes part of the committed selection.ghidraProjectCommitmentSchemaalready records. Putting it there makes it part of the profile digest (different folders cannot share cached observations) and reuses the copy, verification, cleanup, Windows refusal and import-override refusals unchanged. No second open path is needed.Fixture.rep/idata/~index.bakand~journal.bak, so it could not promise an untouched original. feat(ghidra): reuse existing projects through verified copies #7236's copy does, and it already covers the reuse, identity, read-only and historical-report parts of the original scope.Tested
Run on a Windows x64 host with Node 24.22.1. Existing-project mode is unavailable on Windows, so the launcher tests that copy and launch a project skip on this host.
npm run typecheck: exit 0.node scripts/run-exact-tests.mjs run(thetest:focusedbuild step needs the packaged Windows native addon, which this checkout does not have):tests/boundary/providers/ghidra/ghidraProjectSnapshot.test.ts,tests/boundary/providers/ghidra/ghidraLauncher.test.ts,src/ghidra/GhidraProvider.behavior.test.ts: 232 passed, 12 skipped, 6 failed. The 6 failures are launcher tests that need that native addon (PrivateRuntimeRootUnavailableError). They fail the same way with main's source.src/ghidra,src/config,tests/boundary/providers/ghidra, plus the doctor, startup-policy and project-read-cancellation suites): main 1085 passed / 107 failed / 102 skipped; this branch 1096 passed / 107 failed / 102 skipped. The failing test lists are identical (Windows host and native addon).oxfmt --checkon changed files: clean.oxlinton changed TypeScript files: no new warnings.app.exeat the root and a differentapp.exein/sub/dir. The provider refuses existing projects on Windows, so a small script drove this branch's pieces directly:parseConfigwithREA_GHIDRA_PROGRAM_FOLDER=/sub/dir,resolveGhidraProject,copyExistingGhidraProjectwith the committed SHA-256, andghidraHeadlessArguments(POSIX argument form), then rananalyzeHeadlesson the copy with a probe post-script in place of the bridge. It opened/sub/dir/app.exefrom the copy (the program's executable SHA-256 matched the folder input; functions and decompilation present). With the folder unset it opened/app.exe; with/sub/nope, analyzeHeadless stopped withSpecified project folder not found: /sub/nope. Ghidra rewrote~index.bakand removed~journal.bakin each copy, while every file of the original project, those two included, kept its size, mtime and SHA-256.npm run docs:check(same native-addon build step), a Linux run, and the full provider and bridge on a folder program.