Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Failed injecting the DLL with MinHook

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
rain-13
Expert Cheater
Reputation: 0

Joined: 18 Mar 2009
Posts: 110

PostPosted: Fri Jul 10, 2015 6:53 am    Post subject: Failed injecting the DLL with MinHook Reply with quote

Hello.

I decided to use MinHook for it's simplicity.

I have compiled it for 64 bit platform but when I inject \Win32Project1\x64\Release\Win32Project1.dll into notepad.exe which is 64 bit application, CE says Failed injecting the DLL. Now I know for sure that both dll and target are 64 bit. And the same project when I compiled it for x86 succeeded with random x86 target.

Has anyone used this library? Any ideas what might cause it? Wrong project settings?

Here's my link to my project:
http://autoit.net.ee/downloads/Win32Project1.zip
I posted here whole project because I didnt know wether I should post just cpp file or project itself.
Back to top
View user's profile Send private message
kriptix
Advanced Cheater
Reputation: 1

Joined: 05 Jun 2011
Posts: 61

PostPosted: Fri Jul 10, 2015 8:51 am    Post subject: Reply with quote

I tried downloading your project 3 times and it's not working. Got to ask the obvious, but are you hooking the right address/function? I'm sure you are, but always gotta ask. I've never used this, but from what he stated in his article several projects have used it
Quote:
As of January 2015, this library is used in some projects: 7+ Taskbar Tweaker, Better Explorer, DxWnd, NonVisual Desktop Access, Open Broadcaster Software, QTTabBar, x360ce and more. I am happy finding that this project is helpful to people.

I took a look at a few of those projects and I think you might want to check out Open Broadcaster Software's project. They use the hook for 32/64 and cross-platform. Their project is open source on github and can be found here.
Back to top
View user's profile Send private message
rain-13
Expert Cheater
Reputation: 0

Joined: 18 Mar 2009
Posts: 110

PostPosted: Fri Jul 10, 2015 9:06 am    Post subject: Reply with quote

Is link not working or project itself? I just tested and it worked for me. Link in first post is direct download. It should not even lead you away from this page.

Does this link work better? I dont know what browser you have but I tested this link with firefox.
http://www.megafileupload.com/d9MY/Win32Project1.zip?pt=wnEk0iEDBGr3VwrhSFqaop3E%2BgQ1EvzAUDmrv7Mrtl8%3D

This is my code:
Code:
#include <Windows.h>
#include "MinHook.h"

#if defined _M_X64
#pragma comment(lib, "libMinHook.x64.lib")
#elif defined _M_IX86
#pragma comment(lib, "libMinHook.x86.lib")
#endif

// Helper function for MH_CreateHookApi().
template <typename T>
inline MH_STATUS MH_CreateHookApiEx(LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, T** ppOriginal)
{
    return MH_CreateHookApi(pszModule, pszProcName, pDetour, reinterpret_cast<LPVOID*>(ppOriginal));
}

typedef HANDLE (WINAPI *CREATEFILEW)(LPCWSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE);

// Pointer for calling original MessageBoxW.
CREATEFILEW fpCreteFileW= NULL;

// Detour function which overrides MessageBoxW.
HANDLE WINAPI DetourCreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess,DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
{
    return fpCreteFileW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);

}


INT APIENTRY DllMain(HMODULE hDLL, DWORD Reason, LPVOID Reserved)
{
    switch(Reason)
    {
    case DLL_PROCESS_ATTACH:
      // Initialize MinHook.
      if (MH_Initialize() != MH_OK)
      {
         MessageBox(0,L"fail1",L"fail",0);
         return 1;
      }

      // Create a hook for MessageBoxW, in disabled state.
      if (MH_CreateHookApiEx(L"Kernel32", "CreateFileW", &DetourCreateFileW, &fpCreteFileW) != MH_OK)
      {
         MessageBox(0,L"fail2",L"fail",0);
         return 1;
      }

      // Enable the hook for MessageBoxW.
      if (MH_EnableHook(&CreateFileW) != MH_OK)
      {
         MessageBox(0,L"fail1",L"fail",0);
         return 1;
      }
        break;
    case DLL_PROCESS_DETACH:
      // Disable the hook for MessageBoxW.
      if (MH_DisableHook(&CreateFileW) != MH_OK)
      {
         return 1;
      }

      // Uninitialize MinHook.
      if (MH_Uninitialize() != MH_OK)
      {
         return 1;
      }
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
        break;
    }
    return TRUE;
}
Back to top
View user's profile Send private message
STN
I post too much
Reputation: 43

Joined: 09 Nov 2005
Posts: 2676

PostPosted: Fri Jul 10, 2015 2:44 pm    Post subject: Reply with quote

The dll injects fine here ? Sure you are running 64bit version of notepad ?

Something must be wrong on your end.

_________________
Cheat Requests/Tables- Fearless Cheat Engine
https://fearlessrevolution.com
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25818
Location: The netherlands

PostPosted: Sat Jul 11, 2015 2:17 am    Post subject: Reply with quote

is it the "modern" app version of calculator?
If so, is the dll in a location with security rights for everyone? (might have to add that specifically)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
rain-13
Expert Cheater
Reputation: 0

Joined: 18 Mar 2009
Posts: 110

PostPosted: Sun Jul 12, 2015 2:20 am    Post subject: Reply with quote

Edit: I figured that if I use CE then it fails but when I use Extreme Injector v3.exe then it works Razz

Edit2: after updating CE from 6.2 to 6.4 it worked with CE also. Sorry for wasting your time guys Sad . Didnt even expect to have it fixed with using something else than CE cuz I thought it to be so universal that "it definitely cant be injector's fault."

Edit3: now I have CE6.2 and 6.4 both. 6.2 keeps failing, 6.4 works every time.


Last edited by rain-13 on Sun Jul 12, 2015 2:39 am; edited 3 times in total
Back to top
View user's profile Send private message
STN
I post too much
Reputation: 43

Joined: 09 Nov 2005
Posts: 2676

PostPosted: Sun Jul 12, 2015 2:30 am    Post subject: Reply with quote

I didn't compile your code but used the dll already in the release folder. Used CE to inject it.

I'll play with this some more and see if i get the same error

_________________
Cheat Requests/Tables- Fearless Cheat Engine
https://fearlessrevolution.com
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites