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 


c++ making a dll to inject to a program

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
PsychicSymphony
Newbie cheater
Reputation: 0

Joined: 17 May 2011
Posts: 13
Location: Ontario

PostPosted: Tue May 17, 2011 4:39 pm    Post subject: c++ making a dll to inject to a program Reply with quote

Im trying to make a dll to inject to a program that will draw a bitmap to the desktop that has info about the hack. All I know about dlls is that the entry point is
[code]BOOL WINAPI DllMain[code]

thats all I know can anyone tell me what goes in the dll main method and how I put a update method into a dll?[/code]

_________________
Psychic Symphony
////
// Very Happy //
// //
////
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Tue May 17, 2011 6:14 pm    Post subject: Reply with quote

If you are asking basics like this, you need to do more research and work before you should even be touching DLLs. You are basically asking for the entire thing to be coded for you.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
PsychicSymphony
Newbie cheater
Reputation: 0

Joined: 17 May 2011
Posts: 13
Location: Ontario

PostPosted: Tue May 17, 2011 7:27 pm    Post subject: Reply with quote

Ok I researched and I found out how to make a dll
my dll consists of
the dllmain method and all the
dllprocessattached cases and stuff

I added a while loop in the dllprocessattached case but the while loop doesnt work should I put it in another one or what?

_________________
Psychic Symphony
////
// Very Happy //
// //
////
Back to top
View user's profile Send private message
Innovation
Grandmaster Cheater
Reputation: 12

Joined: 14 Aug 2008
Posts: 617

PostPosted: Wed May 18, 2011 6:31 am    Post subject: Reply with quote

PsychicSymphony wrote:
I added a while loop in the dllprocessattached case but the while loop doesnt work should I put it in another one or what?

DllMain should return as soon as possible since it holds the OS loader lock. Create a new thread using CreateThread.

Code:
#include <windows.h>

DWORD WINAPI MainThread(LPVOID lpThreadParameter)
{
   // ...
}

BOOL APIENTRY DllMain(__in HMODULE hModule, __in DWORD dwReason, __in LPVOID lpReserved)
{
   if(dwReason == DLL_PROCESS_ATTACH)
   {
      DisableThreadLibraryCalls(hModule);
      if(CreateThread(NULL, 0, MainThread, NULL, 0, NULL) == NULL)
      {
         return FALSE;
      }
   }
   else if(dwReason == DLL_PROCESS_DETACH)
   {
      // ...
   }
   return TRUE;
}
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed May 18, 2011 10:02 am    Post subject: Reply with quote

MSDN says you should actually not create a thread from within dllmain. What I do is inject a dll which exports an init function then call createremotethread from the injector

http://msdn.microsoft.com/en-us/windows/hardware/gg487379
Back to top
View user's profile Send private message
b6oy
Newbie cheater
Reputation: 0

Joined: 21 Sep 2009
Posts: 10

PostPosted: Wed May 18, 2011 1:12 pm    Post subject: Reply with quote

Slugsnack wrote:
MSDN says you should actually not create a thread from within dllmain. What I do is inject a dll which exports an init function then call createremotethread from the injector


thanks, this method helped me bypassing a game protection.
Back to top
View user's profile Send private message
Innovation
Grandmaster Cheater
Reputation: 12

Joined: 14 Aug 2008
Posts: 617

PostPosted: Wed May 18, 2011 2:03 pm    Post subject: Reply with quote

Slugsnack wrote:
MSDN says you should actually not create a thread from within dllmain. What I do is inject a dll which exports an init function then call createremotethread from the injector

http://msdn.microsoft.com/en-us/windows/hardware/gg487379

MSDN wrote:
You should never perform the following tasks from within DllMain:
...
• Call CreateThread. Creating a thread can work if you do not synchronize with other threads, but it is risky.

What can be done in DllMain generally lies in the gray area. While not recommended by MSDN, it's still a working method under certain restrictions.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Wed May 18, 2011 3:45 pm    Post subject: Reply with quote

Innovation wrote:
Slugsnack wrote:
MSDN says you should actually not create a thread from within dllmain. What I do is inject a dll which exports an init function then call createremotethread from the injector

http://msdn.microsoft.com/en-us/windows/hardware/gg487379

MSDN wrote:
You should never perform the following tasks from within DllMain:
...
• Call CreateThread. Creating a thread can work if you do not synchronize with other threads, but it is risky.

What can be done in DllMain generally lies in the gray area. While not recommended by MSDN, it's still a working method under certain restrictions.


I wouldn't consider it a gray area when the developers of the operating system are telling you not to do it. They're pretty clear in the document that you should not do the given list of things inside of DllMain. The article is fairly old so if things have changed, Microsoft would have updated the article to go along with the changes. Given that it hasn't, it's safe to assume the article is still followed in standards for DllMain handling on Windows.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed May 18, 2011 4:26 pm    Post subject: Reply with quote

i just would avoid it given that there is a perfectly viable alternative which i stated above
Back to top
View user's profile Send private message
Innovation
Grandmaster Cheater
Reputation: 12

Joined: 14 Aug 2008
Posts: 617

PostPosted: Wed May 18, 2011 6:03 pm    Post subject: Reply with quote

Slugsnack wrote:
i just would avoid it given that there is a perfectly viable alternative which i stated above

The only problem would be if the DLL injector doesn't support thread creation at an arbitrary export, which is the case for most DLL injectors I have seen that are in wide use. Of course, there are exceptions (as with Cheat Engine).
Back to top
View user's profile Send private message
PsychicSymphony
Newbie cheater
Reputation: 0

Joined: 17 May 2011
Posts: 13
Location: Ontario

PostPosted: Wed May 18, 2011 6:39 pm    Post subject: Reply with quote

Ok lol sorry for not listening to anyone about the threads I just made my own, this is my code
[CODE]
#include "main.h"

HANDLE thread;

int Thread() {
while (1) {
ofstream file;
file.open("test.txt");
file << "worked";
file.close();
Sleep(1);
}
return 0;
}

BOOL APIENTRY DllMain(__in HMODULE hModule, __in DWORD dwReason, __in LPVOID lpReserve) {
if(dwReason == DLL_PROCESS_ATTACH) {
DisableThreadLibraryCalls(hModule);
thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)Thread, NULL, 0, NULL);
}
return true;
}
[/CODE]

The code works it does write to test.txt so im really happy thanks Very Happy
I am trying to now make a menu. This is a question about hooks like keyboard hooks and mouse hooks.

Keyboard and mouse hooks intercepts the input coming from the window and reads them then stops them or sends them back to the window.
Example:
press 1 key->| window gets input
V ^
My program intercepts and reads|

what if the window doesnt use keyboard input like Diablo 2 the game im trying to make a menu for. Diablo 2 uses no keyboard input so would a keyboard hook not work?

_________________
Psychic Symphony
////
// Very Happy //
// //
////
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Thu May 19, 2011 9:08 am    Post subject: Reply with quote

Innovation wrote:
Slugsnack wrote:
i just would avoid it given that there is a perfectly viable alternative which i stated above

The only problem would be if the DLL injector doesn't support thread creation at an arbitrary export, which is the case for most DLL injectors I have seen that are in wide use. Of course, there are exceptions (as with Cheat Engine).


If the personal is capable of coding the DLL to be injected, they should be able to create the injector as well. Calling remote exports isn't hard to do.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Innovation
Grandmaster Cheater
Reputation: 12

Joined: 14 Aug 2008
Posts: 617

PostPosted: Thu May 19, 2011 10:35 am    Post subject: Reply with quote

Wiccaan wrote:
Innovation wrote:
Slugsnack wrote:
i just would avoid it given that there is a perfectly viable alternative which i stated above

The only problem would be if the DLL injector doesn't support thread creation at an arbitrary export, which is the case for most DLL injectors I have seen that are in wide use. Of course, there are exceptions (as with Cheat Engine).


If the personal is capable of coding the DLL to be injected, they should be able to create the injector as well. Calling remote exports isn't hard to do.

I never claimed it was hard. What I meant is that many DLL injectors anticipate that no other call is needed other than to DllMain for the proper functionality because CreateThread works.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Thu May 19, 2011 1:16 pm    Post subject: Reply with quote

Which would be the point of them making their own injector vs. using a premade one.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
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