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

MH_CreateHook return MH_ERROR_MEMORY_ALLOC #2

Open
hahaleyile opened this issue May 14, 2024 · 2 comments
Open

MH_CreateHook return MH_ERROR_MEMORY_ALLOC #2

hahaleyile opened this issue May 14, 2024 · 2 comments

Comments

@hahaleyile
Copy link

MH_STATUS status = MH_CreateHook(MessageBoxW, (void*)MessageBoxWHook, (void**)&pOriginalMessageBoxW);
if (status == MH_OK) {
status = MH_QueueEnableHook(MessageBoxW);
}

The code above return MH_ERROR_MEMORY_ALLOC, but the hook is working. What's even stranger is that when I add a new hook to GetComputerNameW, all hooks fail.

@m417z
Copy link
Owner

m417z commented May 15, 2024

The code above return MH_ERROR_MEMORY_ALLOC, but the hook is working

That doesn't make sense, I believe there's some misunderstanding on your side. Perhaps it failed in a specific process, and the hook worked in another process?

In any case, similar code is used as the core of Windhawk, which is used by many users and was proven to be working and stable, so I believe the problems you see are as a result of your code changes.

MH_ERROR_MEMORY_ALLOC can also be caused by the following, although it's not a common scenario:
TsudaKageyu/minhook#107

@hahaleyile
Copy link
Author

hahaleyile commented May 16, 2024

Thanks for the reply! After your tip, I found out that there was a global variable defined in the namespace, and moving it out fix the problem. Also, there are indeed some special high-privileged processes that can't be injected.

In my project, I defined slot handle in namespace before, this caused problem. May I ask why?

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

No branches or pull requests

2 participants