Skip to content

FunctionID: Add option to disable namespace stripping #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arvi18
Copy link

@arvi18 arvi18 commented Apr 21, 2025

Fixes NationalSecurityAgency#5858

Overview

The linked issue isnt tracked or assigned but it has been getting a lot of attention. I also run into this namespace stripping problem all the time when reversing Rust binaries and using function IDs.

When we create function ID database (.fidb) files, the populate functions strip the function namespaces. This is a well documented limitation/feature of the FID implementation.

The linked issue describes the problem: C++ (and Rust) code often has simple names that clash when you remove the namespace. I added a checkbox under Tools -> Function ID -> Populate FidDb from programs... which can be used to disable namespace stripping. This checkbox is disabled by default so it does not affect the original behavior if left unchecked. Here is the key change in FidServiceLibraryIngest.java at this line:

before:

name = function.getSymbol().getName();

after:

name = function.getSymbol().getName(disableNamespaceStripping);

where function is of type Function which is an interface extending Namespace so this method is available:

	/**
	 * Returns the fully qualified name
	 * @param includeNamespacePath true to include the namespace in the returned name
	 * @return the fully qualified name
	 */
	public String getName(boolean includeNamespacePath);

Using that we get the full symbol names including namespaces. The rest of the changes make sure the checkbox is added to the panel under Tools -> Function ID -> Populate FidDb from programs... and the setting gets passed through the code properly. I also updated CreateMultipleLibraries.java for headless mode.

Testing

Before:

image

Note that the namespaces of drop_slow are stripped.

After:

image

image

Note that the namespaces of drop_slow are not stripped.

Known issue

After running a FID analysis and applying symbols from a .fidb file (containing function names with namespaces), the namespaces end up getting embedded in the function name:

image

This is why I marked this feature as experimental for now. I think this is a small issue compared to the huge gain we can achieve with keeping the namespaces.

I intend to improve/fix this in the future.

Summary by CodeRabbit

  • New Features
    • Added an experimental option to disable namespace stripping when creating or ingesting function ID libraries. This option is available via a new checkbox in the library creation dialog.
  • Documentation
    • Updated help text to document the new namespace stripping option in relevant dialogs and methods.

@arvi18
Copy link
Author

arvi18 commented Apr 21, 2025

There is a simple solution for this known issue actually:

image

Select the function and press L (rename):

image

Do not change anything just click OK.

The namespace is registered:

image

Copy link

coderabbitai bot commented Apr 21, 2025

Warning

Rate limit exceeded

@visz11 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 11 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 2abfd4e and de7cdae.

📒 Files selected for processing (5)
  • Ghidra/Features/FunctionID/ghidra_scripts/CreateMultipleLibraries.java (3 hunks)
  • Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/plugin/IngestTask.java (3 hunks)
  • Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/plugin/PopulateFidDialog.java (3 hunks)
  • Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/service/FidService.java (2 hunks)
  • Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/service/FidServiceLibraryIngest.java (7 hunks)

Walkthrough

A new option to control namespace stripping was introduced throughout the FunctionID library creation workflow in Ghidra. This involved adding a disableNamespaceStripping boolean flag to relevant classes and methods, updating user interfaces to collect this option from users, and ensuring it is passed through all layers of the process—from dialogs and tasks, through service methods, down to the function hashing logic. The parameter is now used to determine whether symbol names are stripped of namespaces during function identification.

Changes

File(s) Change Summary
Ghidra/Features/FunctionID/ghidra_scripts/CreateMultipleLibraries.java Added disableNamespaceStripping field; prompt user for option; pass flag to library creation method.
Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/plugin/IngestTask.java Added disableNamespaceStripping field; updated constructor and method calls to use new flag.
Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/plugin/PopulateFidDialog.java Added checkbox for namespace stripping; new field and accessor; pass option to IngestTask.
Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/service/FidService.java Added disableNamespaceStripping parameter to createNewLibraryFromPrograms; updated Javadoc.
Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/service/FidServiceLibraryIngest.java Added disableNamespaceStripping field; propagated flag through constructors and methods; used flag in function name retrieval.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant PopulateFidDialog
    participant IngestTask
    participant FidService
    participant FidServiceLibraryIngest

    User->>PopulateFidDialog: Open dialog
    PopulateFidDialog->>User: Show "Disable namespace stripping" checkbox
    User->>PopulateFidDialog: Submit selection
    PopulateFidDialog->>IngestTask: Create task with disableNamespaceStripping
    IngestTask->>FidService: createNewLibraryFromPrograms(..., disableNamespaceStripping, ...)
    FidService->>FidServiceLibraryIngest: new(..., disableNamespaceStripping)
    FidServiceLibraryIngest->>FidServiceLibraryIngest: hashAllTheFunctions(..., disableNamespaceStripping)
Loading

Poem

In the warren of code, a new checkbox appears,
"Strip namespaces or not?"—the question now nears.
Through dialogs and tasks, the option hops along,
Down to the functions where names can belong.
Now rabbits can choose, with a whisker of pride,
To keep or to strip namespaces—let users decide!
🐇✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/plugin/PopulateFidDialog.java (1)

153-157: Good UI implementation with clear labeling.

The checkbox is properly added to the panel with a descriptive label that appropriately marks this feature as experimental. Consider adding a tooltip to provide more information about this option.

 panel.add(new GLabel("Disable namespace stripping (experimental)", SwingConstants.RIGHT));
 namespaceStrippingCheckBox = new JCheckBox();
+namespaceStrippingCheckBox.setToolTipText("When enabled, namespaces will be preserved in function names. This helps prevent name clashes in languages like C++ and Rust.");
 namespaceStrippingCheckBox.addActionListener(e -> updateOkEnablement());
 panel.add(namespaceStrippingCheckBox);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2abfd4e and de7cdae.

📒 Files selected for processing (5)
  • Ghidra/Features/FunctionID/ghidra_scripts/CreateMultipleLibraries.java (3 hunks)
  • Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/plugin/IngestTask.java (3 hunks)
  • Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/plugin/PopulateFidDialog.java (3 hunks)
  • Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/service/FidService.java (2 hunks)
  • Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/service/FidServiceLibraryIngest.java (7 hunks)
🔇 Additional comments (20)
Ghidra/Features/FunctionID/ghidra_scripts/CreateMultipleLibraries.java (3)

61-61: Field declaration is appropriately placed.

The new boolean field disableNamespaceStripping is properly declared with the other class-level fields.


374-376: Good user interaction for the new option.

This prompt appropriately asks users for their preference on namespace stripping when running the script in headless mode, ensuring consistency with the GUI option.


282-284: Parameter is correctly passed to the service method.

The disableNamespaceStripping flag is properly passed to the createNewLibraryFromPrograms method, maintaining the correct method signature and parameter ordering.

Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/plugin/PopulateFidDialog.java (3)

66-66: Field declaration is appropriately placed.

The new checkbox field is properly declared with other UI component fields.


100-102: Clean helper method implementation.

Good practice to create a dedicated method for retrieving the checkbox state, making the code more maintainable.


91-92: Parameter is correctly retrieved and passed.

The namespace stripping option is properly retrieved and passed to the IngestTask constructor.

Also applies to: 95-95

Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/plugin/IngestTask.java (3)

48-48: Field declaration is appropriately placed.

The new boolean field is properly declared with other class-level fields.


52-54: Constructor parameter and initialization are correctly implemented.

The constructor signature update and field initialization look good.

Also applies to: 66-66


98-102: Parameter is correctly passed to the service method.

The disableNamespaceStripping flag is properly passed to the fidService.createNewLibraryFromPrograms method.

Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/service/FidService.java (3)

185-185: Good Javadoc update.

The method's Javadoc is properly updated to document the new parameter.


195-196: Method signature update is correct.

The method signature is properly updated to include the new parameter.


199-201: Parameter is correctly passed to the library ingest constructor.

The disableNamespaceStripping flag is properly passed to the FidServiceLibraryIngest constructor, completing the propagation chain from UI to core functionality.

Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/service/FidServiceLibraryIngest.java (8)

52-52: Good addition of the disableNamespaceStripping flag.

This private boolean field properly stores the namespace stripping preference that will be used throughout the class.


180-181: Constructor parameter and documentation looks good.

The constructor has been properly updated to accept the new disableNamespaceStripping parameter with appropriate JavaDoc, and the parameter is correctly assigned to the instance variable.

Also applies to: 185-186, 197-197


247-247: Parameter correctly passed to child method.

The disableNamespaceStripping parameter is properly passed to the populateLibraryFromProgram method, maintaining the user preference throughout the call chain.


268-272: Method signature and documentation properly updated.

The populateLibraryFromProgram method signature has been updated to include the new parameter with appropriate JavaDoc.


279-279: Parameter correctly propagated to hashAllTheFunctions.

The disableNamespaceStripping parameter is properly passed to the next method in the chain, ensuring consistent behavior.


337-343: Method signature and documentation properly updated for hashAllTheFunctions.

The hashAllTheFunctions method has been correctly updated to accept the new parameter with appropriate JavaDoc.


1-661: Overall implementation is cohesive and well-structured.

The changes consistently implement the new feature to optionally disable namespace stripping during FID database creation. The boolean parameter is properly propagated through the call chain from the constructor down to where function names are retrieved, making the feature work seamlessly while maintaining backward compatibility.

As noted in the PR objectives, this addresses issue NationalSecurityAgency#5858 where namespace stripping caused name clashes in languages like C++ and Rust where functions often share simple names but differ by namespace.


362-362:

✅ Verification successful

Core implementation looks correct.

This is the key implementation line where the flag is actually used to determine whether namespace paths should be included in function names. The usage of getName(disableNamespaceStripping) aligns with the PR objectives to optionally disable namespace stripping.

Note that as mentioned in the PR objectives, this is marked as experimental since applying symbols from a .fidb file with namespaces may result in namespaces being embedded directly into function names.


🏁 Script executed:

#!/bin/bash
# Check the Function interface to verify the getName method signature
# that's being used in this implementation

# Find the Function interface definition
fd -t f "Function.java" | xargs grep -A 3 "getName.*boolean"

Length of output: 419


🏁 Script executed:

#!/bin/bash
# Locate Symbol.java files in the repository
echo "Symbol.java files:"
fd -t f "Symbol.java"

# Check for the getName(boolean) signature in each Symbol.java
echo
echo "Checking for 'String getName(boolean' in Symbol.java:"
fd -t f "Symbol.java" | xargs grep -nE "String\s+getName\s*\(\s*boolean"

Length of output: 40802


Verified: Symbol.getName(boolean) signature and semantics match the PR change.

The call

name = function.getSymbol().getName(disableNamespaceStripping);

correctly passes your experimental flag into Symbol.getName(boolean includeNamespace), which exists in ghidra/program/model/symbol/Symbol.java and is overridden in GlobalSymbol and AbstractDBTraceSymbol. This aligns exactly with the PR’s goal to optionally include namespace paths.

@visz11
Copy link
Collaborator

visz11 commented Apr 23, 2025

@coderabbitai full review

Copy link

coderabbitai bot commented Apr 23, 2025

✅ Actions performed

Full review triggered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Function ID registration without stripping namespaces
3 participants