features: fix Regex.get_value_str() corrupting capa2yara output#2886
features: fix Regex.get_value_str() corrupting capa2yara output#2886mr-tz merged 2 commits intomandiant:masterfrom
Conversation
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 resolves a critical bug that caused incorrect YARA rule generation due to improper handling of regular expression patterns. By ensuring that the 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
Activity
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 correctly fixes a bug where Regex.get_value_str() was returning an escaped string, which caused issues with YARA rule generation. The fix is to override the method in the Regex class to return the raw value. The change is correct and well-implemented. I've added one suggestion to include a regression test to prevent this issue from happening again in the future.
16e4636 to
1356e0d
Compare
mr-tz
left a comment
There was a problem hiding this comment.
Thank you. How does this change the current behavior of capa main or other receivers of this data?
|
capa main and the render modules don't call get_value_str() anywhere, so no change there. The only callers in the codebase are capa2yara.py (the reported bug, now fixed) and the IDA plugin view.py. In the IDA plugin, Regex passes the isinstance(k, String) check, so the result of get_value_str() already gets wrapped in escape_string(). Before the fix that was a double escape (once inside get_value_str, once outside). Now it escapes once, which is consistent with how plain String features are handled. Rule evaluation uses self.re.search() directly and Regex.str() uses self.value directly, neither goes through get_value_str(). |
closes #1909
Regexinherits fromString, which overridesget_value_str()to callescape_string()(viarepr()). This doubles all backslashes in the regex pattern beforecapa2yara.pyever sees it, producing corrupted YARA rules.Fix: override
get_value_str()onRegexto returnself.valuedirectly (same as the baseFeatureclass), since regex backslashes are syntax, not escape sequences.StringandSubstringescaping is intentional and unchanged.Introduced by 58e94a3.
Checklist