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 


[help]My first time DLL Injection
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
ShurikeN
Advanced Cheater
Reputation: 0

Joined: 09 Jan 2008
Posts: 84

PostPosted: Fri Jun 06, 2008 5:53 am    Post subject: [help]My first time DLL Injection Reply with quote

i tried to inject this test dll into minesweeper, i used winjector and it says successfully injected but the messagebox doesn't show up. Am i missing something here?
Code:

#include <windows.h>

BOOL APIENTRY DllMain ( HINSTANCE hInst, DWORD dwReason, LPVOID reserved )
{
      if( dwReason == DLL_PROCESS_ATTACH )
            MessageBox( 0, "Attached!", 0, 0 );
     return TRUE;
}

_________________
Code:
XXXXXX      XXXXXX
   XXXXX  XXXXX
     XXXXXXXX
    D I R E C T
     XXXXXXXX
   XXXXX  XXXXX
XXXXXX      XXXXXX
      GameDev
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Fri Jun 06, 2008 6:49 am    Post subject: Reply with quote

Use CreateThread.
Back to top
View user's profile Send private message
ShurikeN
Advanced Cheater
Reputation: 0

Joined: 09 Jan 2008
Posts: 84

PostPosted: Fri Jun 06, 2008 7:28 am    Post subject: Reply with quote

didn't work too. I thought it was my compiler (CodeBlocks) but when i tried it on my OLD Dev-C++ it gives the same result.
Code:

#include <windows.h>

DWORD ThreadID;
DWORD WINAPI NewThread( LPVOID lParam ) {
      MessageBox( 0, "Attached!", 0, 0 );
      ExitThread( 0 );
}

BOOL APIENTRY DllMain( HINSTANCE hInst, DWORD dwReason, LPVOID lpReserved ) {
     if( dwReason == DLL_PROCESS_ATTACH ) {
          CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)&NewThread, 0, 0, &ThreadID );
     }
     return 1;
}

_________________
Code:
XXXXXX      XXXXXX
   XXXXX  XXXXX
     XXXXXXXX
    D I R E C T
     XXXXXXXX
   XXXXX  XXXXX
XXXXXX      XXXXXX
      GameDev
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Fri Jun 06, 2008 9:18 am    Post subject: Reply with quote

It's not necessary to use CreateThread. It should work fine. Try removing if(dwReason....) part.
Back to top
View user's profile Send private message
Bizarro
I post too much
Reputation: 0

Joined: 01 May 2007
Posts: 2648

PostPosted: Fri Jun 06, 2008 9:26 am    Post subject: Reply with quote

try this
u need to add a loop. otherwise it will only check once/

Code:

switch( dwReason )
   {
   case DLL_PROCESS_ATTACH:
MessageBox( 0, "Attached!", 0, 0 );
   break;
   case DLL_PROCESS_DETACH:
      break;
   }

_________________

w8 baby.com Banner contest, Come join NOW!!
Check us out for Prize deatils
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Fri Jun 06, 2008 9:34 am    Post subject: Reply with quote

Bizarro wrote:
try this
u need to add a loop. otherwise it will only check once/

Code:

switch( dwReason )
   {
   case DLL_PROCESS_ATTACH:
MessageBox( 0, "Attached!", 0, 0 );
   break;
   case DLL_PROCESS_DETACH:
      break;
   }

so it suppose to pop up the message one time isnt it ?

_________________
Stylo
Back to top
View user's profile Send private message
Bizarro
I post too much
Reputation: 0

Joined: 01 May 2007
Posts: 2648

PostPosted: Fri Jun 06, 2008 9:37 am    Post subject: Reply with quote

1qaz wrote:
Bizarro wrote:
try this
u need to add a loop. otherwise it will only check once/

Code:

switch( dwReason )
   {
   case DLL_PROCESS_ATTACH:
MessageBox( 0, "Attached!", 0, 0 );
   break;
   case DLL_PROCESS_DETACH:
      break;
   }

so it suppose to pop up the message one time isnt it ?


yea.
thats why createthread is suggested once its attached

_________________

w8 baby.com Banner contest, Come join NOW!!
Check us out for Prize deatils


Last edited by Bizarro on Fri Jun 06, 2008 9:38 am; edited 1 time in total
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Fri Jun 06, 2008 9:37 am    Post subject: Reply with quote

Make sure you are not using the Dev-C++/Code::Blocks compiler, it messes with the .dll format and does not give it a proper entry point.

Compile it in MSVC 08 and it will work just fine. Smile
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Fri Jun 06, 2008 10:26 am    Post subject: Reply with quote

tombana wrote:
It's not necessary to use CreateThread. It should work fine. Try removing if(dwReason....) part.


If he'll remove that compare statement how can it detect if he injected or not ? he wants to make sure a successful injection.
Back to top
View user's profile Send private message
Estx
Expert Cheater
Reputation: 0

Joined: 04 Mar 2008
Posts: 172

PostPosted: Fri Jun 06, 2008 10:27 am    Post subject: Reply with quote

MessageBoxA instead of MessageBox should work fine for minesweeper.

Code:
#include <windows.h>

BOOL APIENTRY DllMain ( HINSTANCE hInst, DWORD dwReason, LPVOID reserved )
{
      if( dwReason == DLL_PROCESS_ATTACH )
            MessageBoxA(0, "Attached!", 0, 0);
     return TRUE;
}
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Fri Jun 06, 2008 10:39 am    Post subject: Reply with quote

Rot1 wrote:
tombana wrote:
It's not necessary to use CreateThread. It should work fine. Try removing if(dwReason....) part.


If he'll remove that compare statement how can it detect if he injected or not ? he wants to make sure a successful injection.

I meant just for testing, to make sure the problem is not that part. If you would remove it, the messagebox would be displayed when injection is succesfull, but also when a new thread is created or when the process is quit.
Back to top
View user's profile Send private message
HalfPrime
Grandmaster Cheater
Reputation: 0

Joined: 12 Mar 2008
Posts: 532
Location: Right there...On your monitor

PostPosted: Fri Jun 06, 2008 10:56 am    Post subject: Reply with quote

For dev-cpp, atleast, try compiling it as C instead of C++.
_________________
Back to top
View user's profile Send private message
ShurikeN
Advanced Cheater
Reputation: 0

Joined: 09 Jan 2008
Posts: 84

PostPosted: Fri Jun 06, 2008 5:23 pm    Post subject: Reply with quote

HalfPrime wrote:
For dev-cpp, atleast, try compiling it as C instead of C++.

great! it worked. Although i tried in CodeBlocks but no luck. now i have to use old Dev-C++ for DLL programming Shocked

_________________
Code:
XXXXXX      XXXXXX
   XXXXX  XXXXX
     XXXXXXXX
    D I R E C T
     XXXXXXXX
   XXXXX  XXXXX
XXXXXX      XXXXXX
      GameDev
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Fri Jun 06, 2008 6:55 pm    Post subject: Reply with quote

ShurikeN wrote:
HalfPrime wrote:
For dev-cpp, atleast, try compiling it as C instead of C++.

great! it worked. Although i tried in CodeBlocks but no luck. now i have to use old Dev-C++ for DLL programming Shocked


Just upgrade to Visual Studio. A lot less of a hassle.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
ShurikeN
Advanced Cheater
Reputation: 0

Joined: 09 Jan 2008
Posts: 84

PostPosted: Fri Jun 06, 2008 8:03 pm    Post subject: Reply with quote

i love visual studio but i prefer to use CodeBlocks because its installer is light (about 20mb only). The fact that i don't have my own PC i just store the installer in my flashdisk and port it whenever i sit on someone's PC.
_________________
Code:
XXXXXX      XXXXXX
   XXXXX  XXXXX
     XXXXXXXX
    D I R E C T
     XXXXXXXX
   XXXXX  XXXXX
XXXXXX      XXXXXX
      GameDev
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
Goto page 1, 2  Next
Page 1 of 2

 
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