You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add PyGhidra bridge launcher for headless script execution
Fix indentation and logic errors in string resolution method
Add defensive null checks for TaskMonitor initialization
Improve debug output with startup and completion messages
Initialize old_value variable to prevent potential AttributeError
Diagram Walkthrough
flowchart LR
A["Script Entry Point"] -->|"currentProgram is None"| B["PyGhidra Bridge Launcher"]
A -->|"currentProgram exists"| C["Main Analysis"]
B -->|"Load project & binary"| D["Run Script via Bridge"]
D --> C
C -->|"Process registry data"| E["Output Results"]
Loading
File Walkthrough
Relevant files
Enhancement, bug fix, error handling
RegistryKeyBitfieldReport.py
Add PyGhidra bridge and fix code quality issues
RegistryKeyBitfieldReport.py
Add os module import for environment variable access
Implement _launch_via_pyghidra_bridge() function to enable headless execution via PyGhidra
Fix indentation bug in _resolve_string_at_address() method (incorrect nested if statement)
Add try-except blocks around TaskMonitor attribute access in _resolve_dummy_monitor()
Initialize old_value = None before conditional assignment to prevent AttributeError
Add defensive null check old_value is not None before accessing tainted property
Move mode extraction earlier in main() and add startup/completion debug output
Update __main__ block to conditionally launch via PyGhidra bridge when currentProgram is None
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.
Below is a summary of compliance checks for this PR:
Security Compliance
⚪
Untrusted script path usage
Description: The headless launcher uses file when calling gh.run_script(file, args=kv_args), which can be attacker-controlled in some environments and may lead to loading an unintended script path if the working directory or module path is manipulated; resolve the absolute, trusted path (e.g., via importlib.resources or os.path.abspath with validation) instead of relying on file. RegistryKeyBitfieldReport.py [1751-1761]
Referred Code
ifnotproject_pathornotproject_nameornottarget_binary:
print(
"[error] When running outside Ghidra, set GHIDRA_PROJECT_PATH, GHIDRA_PROJECT_NAME, and GHIDRA_TARGET_BINARY.",
file=sys.stderr,
)
sys.exit(1)
kv_args=_filter_kv_args(_SYS_RAW_ARGS)
withopen_project(project_path, project_name) asproj:
withghidra_script(proj, target_binary) asgh:
gh.run_script(__file__, args=kv_args)
Ticket Compliance
⚪
🎫 No ticket provided
Create ticket/issue
Codebase Duplication Compliance
⚪
Codebase context is not defined
Follow the guide to enable codebase context checks.
Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code
Objective: Ensure all identifiers clearly express their purpose and intent, making code self-documenting
Objective: To prevent the leakage of sensitive system information through error messages while providing sufficient detail for internal debugging.
Status: Detailed Exceptions: User-visible error messages print raw exception representations to stderr (e.g., importing pyghidra), which can expose internal details in headless contexts.
Referred Code
try:
frompyghidraimportopen_project, ghidra_scriptexceptExceptionasexc: # pragma: no cover - bridge onlyprint(
f"[error] pyghidra is required to launch this script headlessly: {exc!r}",
file=sys.stderr,
)
sys.exit(1)
Objective: To create a detailed and reliable record of critical system actions for security analysis and compliance.
Status: Limited Audit Logs: The new headless launcher and analysis flow print and log some status messages but do not record user IDs or structured audit entries for critical actions like project/binary opening and script execution.
Objective: To ensure logs are useful for debugging and auditing without exposing sensitive information like PII, PHI, or cardholder data.
Status: Unstructured Logs: New prints and log statements emit unstructured text (stderr prints) rather than structured logs, and may include environment-derived paths or binary names, requiring review for sensitive data exposure.
Refactor the environment variable fetching logic into a helper function to reduce code duplication. Also, improve the error message to specify which environment variables are missing.
-project_path = (- os.environ.get("GHIDRA_PROJECT_PATH")- or os.environ.get("PYGHIDRA_PROJECT_PATH")- or os.environ.get("GHIDRA_DEFAULT_PROJECT_PATH")-)-project_name = (- os.environ.get("GHIDRA_PROJECT_NAME")- or os.environ.get("PYGHIDRA_PROJECT_NAME")- or os.environ.get("GHIDRA_DEFAULT_PROJECT_NAME")-)-target_binary = (- os.environ.get("GHIDRA_TARGET_BINARY")- or os.environ.get("PYGHIDRA_TARGET_BINARY")- or os.environ.get("GHIDRA_DEFAULT_TARGET")-)+def _get_env_var(names: List[str]) -> Optional[str]:+ for name in names:+ value = os.environ.get(name)+ if value:+ return value+ return None-if not project_path or not project_name or not target_binary:+project_path = _get_env_var(["GHIDRA_PROJECT_PATH", "PYGHIDRA_PROJECT_PATH", "GHIDRA_DEFAULT_PROJECT_PATH"])+project_name = _get_env_var(["GHIDRA_PROJECT_NAME", "PYGHIDRA_PROJECT_NAME", "GHIDRA_DEFAULT_PROJECT_NAME"])+target_binary = _get_env_var(["GHIDRA_TARGET_BINARY", "PYGHIDRA_TARGET_BINARY", "GHIDRA_DEFAULT_TARGET"])++missing_vars = []+if not project_path:+ missing_vars.append("GHIDRA_PROJECT_PATH")+if not project_name:+ missing_vars.append("GHIDRA_PROJECT_NAME")+if not target_binary:+ missing_vars.append("GHIDRA_TARGET_BINARY")++if missing_vars:
print(
- "[error] When running outside Ghidra, set GHIDRA_PROJECT_PATH, GHIDRA_PROJECT_NAME, and GHIDRA_TARGET_BINARY.",+ f"[error] When running outside Ghidra, set the following environment variables: {', '.join(missing_vars)}.",
file=sys.stderr,
)
sys.exit(1)
Apply / Chat
Suggestion importance[1-10]: 6
__
Why: The suggestion correctly identifies repeated logic and proposes a good refactoring that improves maintainability and user experience with a more specific error message.
Low
More
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
Summary
Testing
Codex Task
PR Type
Enhancement, Bug fix
Description
Add PyGhidra bridge launcher for headless script execution
Fix indentation and logic errors in string resolution method
Add defensive null checks for TaskMonitor initialization
Improve debug output with startup and completion messages
Initialize old_value variable to prevent potential AttributeError
Diagram Walkthrough
File Walkthrough
RegistryKeyBitfieldReport.py
Add PyGhidra bridge and fix code quality issuesRegistryKeyBitfieldReport.py
osmodule import for environment variable access_launch_via_pyghidra_bridge()function to enable headlessexecution via PyGhidra
_resolve_string_at_address()method (incorrectnested if statement)
TaskMonitorattribute access in_resolve_dummy_monitor()old_value = Nonebefore conditional assignment to preventAttributeError
old_value is not Nonebefore accessingtainted property
main()and add startup/completiondebug output
__main__block to conditionally launch via PyGhidra bridge whencurrentProgramis None