 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Odecey Master Cheater
Reputation: 1
Joined: 19 Apr 2007 Posts: 259 Location: Scandinavia
|
Posted: Tue Nov 11, 2008 1:45 pm Post subject: Problem with building .dll |
|
|
After receiving no reply in my other thread where I asked if it was possible to hook a function in C#, i tried searching a bit it seems that this would be impossible . I then looked for a solution in C++, and came across this code which I tried to compile: | Code: |
#include <windows.h>
#define SIZE 6
typedef int (WINAPI *pMessageBoxW)(HWND, LPCWSTR, LPCWSTR, UINT);
int WINAPI MyMessageBoxW(HWND, LPCWSTR, LPCWSTR, UINT);
void BeginRedirect(LPVOID);
pMessageBoxW pOrigMBAddress = NULL;
BYTE oldBytes[SIZE] = {0};
BYTE JMP[SIZE] = {0};
DWORD oldProtect, myProtect = PAGE_EXECUTE_READWRITE;
INT APIENTRY DllMain(HMODULE hDLL, DWORD Reason, LPVOID Reserved)
{
switch(Reason)
{
case DLL_PROCESS_ATTACH:
pOrigMBAddress = (pMessageBoxW)
GetProcAddress(GetModuleHandle("user32.dll"),
"MessageBoxW");
if(pOrigMBAddress != NULL)
BeginRedirect(MyMessageBoxW);
break;
case DLL_PROCESS_DETACH:
memcpy(pOrigMBAddress, oldBytes, SIZE);
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}
void BeginRedirect(LPVOID newFunction)
{
BYTE tempJMP[SIZE] = {0xE9, 0x90, 0x90, 0x90, 0x90, 0xC3};
memcpy(JMP, tempJMP, SIZE);
DWORD JMPSize = ((DWORD)newFunction - (DWORD)pOrigMBAddress - 5);
VirtualProtect((LPVOID)pOrigMBAddress, SIZE,
PAGE_EXECUTE_READWRITE, &oldProtect);
memcpy(oldBytes, pOrigMBAddress, SIZE);
memcpy(&JMP[1], &JMPSize, 4);
memcpy(pOrigMBAddress, JMP, SIZE);
VirtualProtect((LPVOID)pOrigMBAddress, SIZE, oldProtect, NULL);
}
int WINAPI MyMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uiType)
{
VirtualProtect((LPVOID)pOrigMBAddress, SIZE, myProtect, NULL);
memcpy(pOrigMBAddress, oldBytes, SIZE);
int retValue = MessageBoxW(hWnd, lpText, lpCaption, uiType);
memcpy(pOrigMBAddress, JMP, SIZE);
VirtualProtect((LPVOID)pOrigMBAddress, SIZE, oldProtect, NULL);
return retValue;
} |
When I try to build this in an otherwise empty project, I get the error:"Fatal error LNK1561: entry point must be defined", I was bewildered at this, since i thought DllMain was the entry point. How can I make this build? Any help is as alway appreciated =).
_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren |
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Tue Nov 11, 2008 2:02 pm Post subject: |
|
|
| Code: | | #pragma comment(linker, "/ENTRY:DllMain") |
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Tue Nov 11, 2008 2:15 pm Post subject: |
|
|
Or try defining it like this:
| Code: | BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved );
|
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Tue Nov 11, 2008 2:17 pm Post subject: |
|
|
Are you compiling under the DLL subsystem?
_________________
|
|
| Back to top |
|
 |
Odecey Master Cheater
Reputation: 1
Joined: 19 Apr 2007 Posts: 259 Location: Scandinavia
|
Posted: Tue Nov 11, 2008 2:21 pm Post subject: |
|
|
Adding that resulted in a new error: Fatal error LNK1276: Invalid directive 'DllMain' found; does not start with '/'. I tried randomly adding/subtracting '/' and spaces to see if you could have mistyped, but to no avail =/.
Edit: Lurc what do you mean? I made a new empty project, added a .cpp file and pasted the code within it.
Edit 2: I'll try what you suggested noz. *Edit* Did not work =(.
Thanks for the replies ^_^.
_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren |
|
| Back to top |
|
 |
BanMe Master Cheater
Reputation: 0
Joined: 29 Nov 2005 Posts: 375 Location: Farmington NH, USA
|
Posted: Tue Nov 11, 2008 4:00 pm Post subject: |
|
|
what are you compiling with? VC++ GCC codeblox ?
if you are using VC++ a empty project will not compile a dll u have to direct the compiler to compile a dll o0.. if you dont know these small simple facts.. you need to play with you compiler options more before asking simple questions
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Tue Nov 11, 2008 4:40 pm Post subject: |
|
|
| Are you building with the switch?
|
|
| Back to top |
|
 |
BirdsEye Advanced Cheater
Reputation: 0
Joined: 05 Apr 2008 Posts: 94
|
Posted: Tue Nov 11, 2008 4:54 pm Post subject: |
|
|
| Odecey wrote: | | Edit: Lurc what do you mean? I made a new empty project, added a .cpp file and pasted the code within it. |
Okay. So re-open your IDE and assuming you have Visual C++ 2008, select a new 'Win32 Project.' Before going any furthur, tick 'DLL' radiobox under the 'Application type:' text. Now just select your previous options and have fun.
|
|
| Back to top |
|
 |
Odecey Master Cheater
Reputation: 1
Joined: 19 Apr 2007 Posts: 259 Location: Scandinavia
|
Posted: Wed Nov 12, 2008 4:08 am Post subject: |
|
|
Thanks BirdsEye, that did the trick =).
_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren |
|
| Back to top |
|
 |
|
|
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
|
|