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 


How to call a function inside a injected DLL?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
decheatengine
Cheater
Reputation: 0

Joined: 10 Jun 2007
Posts: 25

PostPosted: Tue Mar 18, 2008 10:04 pm    Post subject: How to call a function inside a injected DLL? Reply with quote

How to call a function inside a injected DLL from a GUI? I tried the below code but it didnt work.

Code:

//inject the dll to the process
HMODULE dll = InjectDll("notepad.exe", "Trainer.dll");

//blah blah blah
//blah blah blah
//blah blah blah
//here try to invoke a functionn from GUI
HMODULE hDummy = LoadLibrary("Trainer.dll");

PVOID func = GetProcAddress(hDummy, "_Hello");
    DWORD offset = (DWORD)func - (DWORD)hDummy;
    DWORD realfunc = (DWORD)dll + offset;

     HANDLE hThread = CreateRemoteThread(0, 0, 0, (LPTHREAD_START_ROUTINE)realfunc, 0, 0,0);
     DWORD error = GetLastError();
     if (hThread != 0)
    {
        WaitForSingleObject(hThread, INFINITE);
        CloseHandle(hThread);
        FreeLibrary(hDummy);
 }


The value in realfunc is correct after i checked it using moon LightEngine's "Enumerate DLL and Symbols". But CreateRemoteThread returned NULL and error = 6.

Help please.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Tue Mar 18, 2008 10:58 pm    Post subject: Reply with quote

CreateRemoteThread needs the processhandle of the process you've injected the dll in.

If you're doing the current process, use -1, not 0. Else Give it the processhandle.

Also, you could run the function from the dllmain

_________________
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
decheatengine
Cheater
Reputation: 0

Joined: 10 Jun 2007
Posts: 25

PostPosted: Sun Mar 23, 2008 6:23 am    Post subject: Reply with quote

DarkByte thanks for the answer. I'm now able to invoke a function in Notepad.exe but everytime the program crashes in FreeLibrary(hDummy). Shouldn't I need to free the library?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Sun Mar 23, 2008 6:33 am    Post subject: Reply with quote

try FreeLibraryAndExitThread if you call the freelibrary from inside the dll
_________________
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
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking 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