feat: add snprintf/sprintf hook#1210
feat: add snprintf/sprintf hook#1210codesensei-tushar wants to merge 4 commits 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. |
| fu.call_return(emu, api, argv, ptr) | ||
| return True | ||
|
|
||
| class SnprintfHook: |
There was a problem hiding this comment.
please add some tests that demonstrate this routine works the way we think it does
There was a problem hiding this comment.
Thanks for the review! I'd like to clarify what kind of tests you're looking for:
-
Unit tests - pytest tests that mock the emulator and verify SnprintfHook._prepare_args() and .call() work correctly with various format specifiers.
-
Integration tests - Tests that run FLOSS on an actual binary (like the C test file I shared) and verify decoded strings are extracted.
|
Added |
williballenthin
left a comment
There was a problem hiding this comment.
thank you @codesensei-tushar!
the unit tests look good
|
I did run black previously, but it might not have run properly. In the latest commit, I've verified that all pre-commit checks: The mypy check was failing due to a pre-existing issue in |
Add SnprintfHook implementation
Fixes #318
Changes
snprintf/sprintfhook using Python's native%formatting%sformat specifiers by reading strings from emulator memory%d,%i,%u,%x,%X,%o%10s,%.5s,%08x)sprintf(buf, fmt, ...)andsnprintf(buf, size, fmt, ...)variantsTesting
Tested with this sample C file: test_snprintf_comprehensive.c