Enhance ghidra backend with existing project feature#3087
Enhance ghidra backend with existing project feature#3087saniyafatima07 wants to merge 14 commits into
Conversation
There was a problem hiding this comment.
Please add bug fixes, new features, breaking changes and anything else you think is worthwhile mentioning to the master (unreleased) section of CHANGELOG.md. If no CHANGELOG update is needed add the following to the PR description: [x] No CHANGELOG update needed
There was a problem hiding this comment.
Code Review
This pull request introduces support for Ghidra projects (.gpr files) by adding utilities to navigate Ghidra project structures and updating the loader to handle project-based analysis. The changes include automatic backend detection for Ghidra projects and updated CLI logic to skip generic file extraction when a project is provided. Review feedback highlights the need for better terminal formatting in error messages, improved resource management to prevent program leaks during exceptions, and the enablement of function filters for the Ghidra backend.
CHANGELOG updated or no update needed, thanks! 😄
|
@mike-hunhoff |
mike-hunhoff
left a comment
There was a problem hiding this comment.
Great work @saniyafatima07 ! I left comments for your review. I'll do some more thinking on how to best handle the .gpr tests in the meantime.
Thank you for the review Mike. |
|
@mike-hunhoff @larchchen @Maijin I have made all the requested changes. |
mike-hunhoff
left a comment
There was a problem hiding this comment.
Thank you @saniyafatima07 ! I've left comments for your review.
|
Thank you for the review @mike-hunhoff . I have addressed all the requested changes. |
mike-hunhoff
left a comment
There was a problem hiding this comment.
Thanks @saniyafatima07 , I've left comments for your review!
|
Done @mike-hunhoff . |
mike-hunhoff
left a comment
There was a problem hiding this comment.
Thanks @saniyafatima07 ! I've left additional comments for your review.
There was a problem hiding this comment.
Let's remove these for now. We can add in a more robust test for this specific feature if it becomes a problem in the future.
031ed53 to
4ba5dd7
Compare
|
Thank you for the review @mike-hunhoff . I have addressed all the requested changes. |
mike-hunhoff
left a comment
There was a problem hiding this comment.
Thank you again for the changes @saniyafatima07 . I think we're almost there, I've left a few comments for your review. Also, please resolve all merge conflicts and close the corresonding .gpr capa-testfiles pull request before requesting another review.
| program, consumer = pyghidra.consume_program(project, program_path) | ||
|
|
||
| # Analyze | ||
| pyghidra.analyze(program, monitor) |
There was a problem hiding this comment.
I noticed that analyzing an existing .gpr project currently takes just as long as running capa on a raw binary file. pyghidra.analyze(program, monitor) is called unconditionally even when loading a .gpr project. This forces Ghidra to re-run auto-analysis on an already-analyzed binary. Skip calling pyghidra.analyze when opening .gpr files:
|
|
||
|
|
||
| def get_sample_path_from_cli(args, backend: str) -> Optional[Path]: | ||
| def get_sample_path_from_cli(args, input_format, backend) -> Optional[Path]: |
There was a problem hiding this comment.
Can we remove input_format and check backend instead?
There was a problem hiding this comment.
Or is there something else that can be done to avoid changing the arguments?
|
|
||
|
|
||
| def get_os_from_cli(args, backend) -> str: | ||
| def get_os_from_cli(args, input_format, backend) -> str: |
There was a problem hiding this comment.
Can we remove input_format and check backend instead?
There was a problem hiding this comment.
Or is there something else that can be done to avoid changing the arguments?
This PR adds support for analyzing existing Ghidra projects directly using
.gprproject input.Users can now provide input in the format:
For multi-program projects:
Motivation & Context
Currently, the Ghidra backend always creates a temporary project and re-imports the binary. This:
This change enables reuse of existing analyzed Ghidra projects while keeping the implementation localized to the Ghidra backend with minimal architecture changes.
Implementation Details
.gprdetection to select the Ghidra backend when a Ghidra project file is provided as input.domain_file.getPathname()to discover programs within the project.CAPA_GHIDRA_PROGRAM_PATHsupport for selecting the target program in multi-program projects.create=Falseconsume_program.gprinput.gprinputs.Tests
Added tests for:
.gprinputCloses #3004
Checklist
Parts of this implementation were assisted using AI tools (Github Copilot, ChatGPT).
AI was used for:
All code was reviewed, modified and tested manually before submission.