fix(idalib): only pass -R when creating new database#2952
fix(idalib): only pass -R when creating new database#2952Young-Lord wants to merge 1 commit intomandiant:masterfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves an issue where the IDA Pro Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request fixes an issue where the -R flag was passed to IDA even when opening an existing database, which is not a valid use of the flag. The change correctly detects if an IDA database already exists and only adds the -R flag when creating a new one. My main feedback is regarding code duplication. The logic for determining the IDA arguments has been added to both capa/loader.py and tests/fixtures.py. I've left comments suggesting to extract this logic into a shared helper function to improve maintainability.
| # `-R` (load resources) is only valid when loading a new input file. | ||
| # if an IDA database already exists, open it without `-R`. | ||
| # ref: https://github.com/mandiant/capa/issues/2950 | ||
| has_existing_database = any( | ||
| input_path.with_name(input_path.name + ext).exists() | ||
| for ext in (".ida", ".i64", ".id0") | ||
| ) | ||
| open_database_args = "-Olumina:host=0.0.0.0 -Osecondary_lumina:host=0.0.0.0" | ||
| if not has_existing_database: | ||
| open_database_args += " -R" |
There was a problem hiding this comment.
This logic for determining the IDA database arguments is duplicated in tests/fixtures.py. To improve maintainability and avoid future inconsistencies, consider extracting this logic into a shared helper function.
For example, you could create a function in this module or a more specific IDA helper module:
IDA_DB_EXTENSIONS = (".ida", ".i64", ".id0")
IDA_LUMINA_ARGS = "-Olumina:host=0.0.0.0 -Osecondary_lumina:host=0.0.0.0"
def get_ida_open_database_args(input_path: Path) -> str:
"""
Get the arguments for opening an IDA database, conditionally adding the `-R` flag.
`-R` (load resources) is only valid when loading a new input file.
If an IDA database already exists, we open it without `-R`.
"""
# ref: https://github.com/mandiant/capa/issues/2950
has_existing_database = any(
input_path.with_name(input_path.name + ext).exists()
for ext in IDA_DB_EXTENSIONS
)
open_database_args = IDA_LUMINA_ARGS
if not has_existing_database:
open_database_args += " -R"
return open_database_argsYou could then call this function here and in tests/fixtures.py to avoid the code duplication. Using constants for the extensions and arguments would also improve readability.
| # `-R` (load resources) is only valid when loading a new input file. | ||
| # if an IDA database already exists, open it without `-R`. | ||
| # ref: https://github.com/mandiant/capa/issues/2950 | ||
| has_existing_database = any( | ||
| path.with_name(path.name + ext).exists() | ||
| for ext in (".ida", ".i64", ".id0") | ||
| ) | ||
| open_database_args = "-Olumina:host=0.0.0.0 -Osecondary_lumina:host=0.0.0.0" | ||
| if not has_existing_database: | ||
| open_database_args += " -R" |
There was a problem hiding this comment.
The test code seems to be duplicated from the source, so I followed the same approach.
closes #2950
Checklist