Fix b2s wide string garbage extraction in Rust binaries issue #867#1223
Fix b2s wide string garbage extraction in Rust binaries issue #867#1223svm1048 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 refactors the string extraction process for Rust binaries to resolve an issue where wide strings were incorrectly parsed as UTF-8, leading to garbage data. By introducing a dedicated module with a strict UTF-8 regex-based extractor, the system now accurately identifies and decodes only valid UTF-8 strings, enhancing the reliability of static string analysis for Rust executables. 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. Changelog
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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses the issue of garbage wide string extraction in Rust binaries by replacing the binary2strings library with a custom, regex-based UTF-8 string extractor. The new implementation in floss/language/rust/strings.py is a significant improvement, providing more precise control over string extraction. The overall changes are well-structured and simplify the logic in floss/language/rust/extract.py. My review includes a few suggestions to enhance code style and adhere to Python best practices for better maintainability.
| static_strings: List[StaticString] = [] | ||
| for offset, string_val in extract_utf8_strings(buffer_rdata, min_length=min_length): | ||
| # our static algorithm does not extract new lines either | ||
| clean_str = string_val.replace("\n", "") | ||
|
|
||
| static_strings.append( | ||
| StaticString( | ||
| string=clean_str, | ||
| offset=offset + start_rdata, | ||
| encoding=StringEncoding.UTF8 | ||
| ) | ||
| ) |
There was a problem hiding this comment.
The loop for building static_strings can be simplified into a more concise and Pythonic list comprehension. This improves readability and maintainability.
static_strings: List[StaticString] = [
StaticString(
string=string_val.replace("\n", ""),
offset=offset + start_rdata,
encoding=StringEncoding.UTF8,
)
for offset, string_val in extract_utf8_strings(buffer_rdata, min_length=min_length)
]|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) | ||
| sys.exit(main()) No newline at end of file |
There was a problem hiding this comment.
The file is missing a final newline character. It's a standard convention (part of the POSIX standard for text files) to end files with a newline. Some tools may not process the last line correctly if it's not terminated by a newline. Please add a newline at the end of the file for compatibility and consistency.
sys.exit(main())| import re | ||
| from typing import Iterator, Tuple | ||
|
|
||
| '''This regular expression is strictly designed to match printable ASCII | ||
| and valid UTF-8 multi-byte sequences.''' |
There was a problem hiding this comment.
The multi-line string on lines 4-5 should be a module-level docstring placed at the top of the file, as per PEP 257. This improves code readability and allows documentation-generation tools to correctly parse the file's purpose.
"""This regular expression is strictly designed to match printable ASCII and valid UTF-8 multi-byte sequences."""
import re
from typing import Iterator, Tuple|
|
||
| print("Extracting strings from test buffer...") | ||
| for offset, extracted_str in extract_utf8_strings(test_buffer, min_length=4): | ||
| print(f"Offset: {hex(offset)} | String: '{extracted_str}'") No newline at end of file |
There was a problem hiding this comment.
The file is missing a final newline character. It's a standard convention (part of the POSIX standard for text files) to end files with a newline. Some tools may not process the last line correctly if it's not terminated by a newline. Please add a newline at the end of the file for compatibility and consistency.
print(f"Offset: {hex(offset)} | String: '{extracted_str}'")
No description provided.