Update extract_dispatch.py#7
Merged
Merged
Conversation
fix(ghidra): resolve UnicodeEncodeError in Jython environment
Address a critical crash (UnicodeEncodeError) occurring during the
decompilation of drivers containing non-ASCII characters (e.g., RtsUer.sys).
Because Ghidra's Python 2.7 (Jython) environment defaults to ASCII for
I/O operations, explicit UTF-8 handling has been implemented.
Key Changes:
1. Global Encoding Stability:
- Imported 'io' module to utilize 'io.open', which backports Python 3
encoding support to the Jython 2.7 environment.
- Cleaned up "mojibake" (corrupted characters like ΓÇö) in docstrings
and comments to ensure the script source is valid UTF-8.
2. Robust File I/O:
- Migrated all 'open()' calls to 'io.open(..., encoding="utf-8")' for
consistent handling of decompiled C code across different locales.
- Applied 'unicode()' casting to decompilation buffers before writing.
This is the primary fix to prevent crashes when encountering
characters like u'\uffe0'.
3. Unicode String Literals:
- Prefixed divider strings and UI headers with 'u' (e.g., u"\n\n// =")
to ensure string concatenation remains within the Unicode domain,
preventing implicit ASCII downcasting crashes.
4. JSON Output Integrity:
- Updated 'json.dumps' with 'ensure_ascii=False'. This ensures that
special characters are preserved as actual characters in
'ghidra_result.json' rather than escaped sequences, improving
readability and downstream parsing.
5. Refactored Error Handling:
- Consolidated crash-logging logic to use the centralized
'write_result' function. This prevents a secondary crash from
occurring inside the exception handler when the error message
itself contains non-ASCII traceback data.
Contributor
Author
|
Updated the import order to satisfy the Ruff linter (I001) |
Contributor
Author
|
Fixed all issues using ruff locally. Sry for the inconvinience didnt knew u were u using ruff |
Owner
|
Thanks for the fix @AnubhavDash |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
fix(ghidra): resolve UnicodeEncodeError in Jython environment
Address a critical crash (UnicodeEncodeError) occurring during the decompilation of drivers containing non-ASCII characters (e.g., RtsUer.sys). Because Ghidra's Python 2.7 (Jython) environment defaults to ASCII for I/O operations, explicit UTF-8 handling has been implemented.
Key Changes:
Global Encoding Stability:
Robust File I/O:
Unicode String Literals:
JSON Output Integrity:
Refactored Error Handling: