Skip to content

Update extract_dispatch.py#7

Merged
416rehman merged 3 commits into
416rehman:mainfrom
AnubhavDash:main
Apr 27, 2026
Merged

Update extract_dispatch.py#7
416rehman merged 3 commits into
416rehman:mainfrom
AnubhavDash:main

Conversation

@AnubhavDash

Copy link
Copy Markdown
Contributor

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.

AnubhavDash and others added 3 commits April 27, 2026 08:53
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.
@AnubhavDash

Copy link
Copy Markdown
Contributor Author

Updated the import order to satisfy the Ruff linter (I001)

@AnubhavDash

Copy link
Copy Markdown
Contributor Author

Fixed all issues using ruff locally. Sry for the inconvinience didnt knew u were u using ruff

@416rehman

Copy link
Copy Markdown
Owner

Thanks for the fix @AnubhavDash

@416rehman
416rehman merged commit 58c47c1 into 416rehman:main Apr 27, 2026
2 checks passed
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.

2 participants