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

InjectAhkDll - Fix malformed VirtualFreeEx calls #11

Merged
merged 2 commits into from Mar 6, 2019

Conversation

lvalkov
Copy link
Contributor

@lvalkov lvalkov commented Mar 3, 2019

MEM_RELEASE in DllCall("VirtualFreeEx","PTR",hProc,"PTR",pBufferRemote,"PTR",nDirLength,MEM_RELEASE) is missing its DWORD type. This causes the value of MEM_RELEASE to be incorrectly interpreted as being the calling convention/return type for the DllCall, causing InjectAhkDll to throw whenever VirtualFreeEx is called.

The Struct definition _MODULEENTRY32 was changed to use Format for populating the array sizes, instead of relying on the continuation section. I imagine you wanted to keep the V1 and V2 versions as similar as possible, but that's not how continuation sections work in V2. Instead of passing in the correct array size, a string is passed. The struct size reported later on by sizeof is, therefore, wrong, which is likely what has been causing the crashes on 64-bit.

The example has also been updated. It injects into notepad x86 on x86 systems, and notepad x86/64 on x64 systems, depending on the bitness of the interpreter.

I need to know what your intentions were regarding constructs such as:

return (DllCall("MessageBox", "Ptr", 0, "Str", "Could not reseve memory for process.", "Str", "Error", "UInt", 0)
      , DllCall("CloseHandle", "Ptr", hProc))

In V1 the result of MessageBox will be returned, whereas in V2, the result of evaluating the last expression will be returned. What did you intend to return here? I'd guess the MessageBox result. Is there an explicit reason for CloseHandle to be called after MessageBox? If not, I'd recommend restructuring these bits.

Lastly, I understand you want to keep both versions similar, but aren't checks like A_IsUnicode ? 2 : 1 pointless, since the V2 interpreters are Unicode only?

@HotKeyIt
Copy link
Owner

HotKeyIt commented Mar 6, 2019

Many thanks ;)
The return MessageBox was just to show the message, return value is not important.

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.

None yet

2 participants