Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and extend Windows API hooking #548

Merged
merged 2 commits into from Sep 22, 2022
Merged

Conversation

upside2
Copy link
Contributor

@upside2 upside2 commented Sep 14, 2022

Fixing bugs in API hooking of Windows functions GetModuleHandleExW() and _alloca_probe(), and adding more vamp signatures for _alloca_probe(). The correct stack adjustment in _alloca_probe() is important for deciding if variables are local, and in guessing how many arguments are passed to a function.

The signatures cover 32-bit and 64-bit executables from all Visual Studio versions; it turns out the opcodes change a little over time, and vamp was only covering some of the 32-bit cases. One of the existing signatures was misnamed.

The GetModuleHandleExW() hook had a typo.

The _alloca_probe() hook had a few problems: stack size delta is off by 4 bytes, stack size not safeguarded against going negative (which can happen during emulation if EAX is garbage), and needless execution of the page read loop which in real samples can take up to 1.5 secs of CPU time.

I created a unit test that leverages existing VIVTESTFILE samples.

@mr-tz
Copy link
Contributor

mr-tz commented Sep 15, 2022

This may be a fix for #515.

Copy link
Contributor

@atlas0fd00m atlas0fd00m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work, thank you!
good fixes, new VAMP sigs, easy to read, and unittests so we know when we break it!

i'll wait a day or two before merging in case @rakuy0 has any concerns.

thanks @upside2 !

@

@atlas0fd00m atlas0fd00m merged commit 978d51c into vivisect:master Sep 22, 2022
@atlas0fd00m
Copy link
Contributor

@mr-tz can you validate this is a fix for #515 ?

@upside2 upside2 deleted the emuhook branch January 16, 2023 19:07
@rakuy0 rakuy0 added this to the v1.1.0 milestone Feb 11, 2023
@rakuy0 rakuy0 added the bug label Feb 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants