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 


Please Help [DLL]

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Sun Oct 18, 2009 5:37 pm    Post subject: Please Help [DLL] Reply with quote

Okay guys, i'm making a hack for Some Game and right now each time I inject it to Some Game , Some Game crashes.

Code:

#include <windows.h>
#include <stdio.h>

DWORD VirtualX = (DWORD)GetProcAddress(GetModuleHandleA("kernel32.dll"), "VirtualProtect") + 5;

BOOL WINAPI VirtualProtectX(LPVOID lpAddress, SIZE_T dwSize, DWORD flNewProtect, PDWORD lpflOldProtect)
{
   _asm {
      mov edi,edi
      push ebp
      mov esp, ebp
      jmp [VirtualX]
   }
}


void Hacks()
{
       Sleep(10000);

      VirtualProtectX((LPVOID)0x178ACE8C, 4, PAGE_EXECUTE_READWRITE, NULL);

      DWORD Ammo = *(DWORD*)0x178ACE8C;

      if (Ammo != 0)
      {
         *(DWORD*)0x178ACE8C = 999;
      }

}

BOOL WINAPI DllMain(HINSTANCE module, DWORD dwReason, LPVOID lpvReserved)
{
   if(dwReason == DLL_PROCESS_ATTACH)
   {
      
      CreateThread(0, 0, (LPTHREAD_START_ROUTINE)Hacks, 0, 0, 0);              
   }

   return TRUE;
}


Can you tell me whats wrong?

- Thanks
Back to top
View user's profile Send private message MSN Messenger
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sun Oct 18, 2009 6:39 pm    Post subject: Reply with quote

Attach the Visual Studio debugger to the program after you inject it and you can step through your injected dll.

it's pretty rad.
Back to top
View user's profile Send private message
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Sun Oct 18, 2009 6:55 pm    Post subject: Reply with quote

Also, I find this a common problem for every game I inject my dll to and want to use DMA to write.
Back to top
View user's profile Send private message MSN Messenger
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Mon Oct 19, 2009 6:11 am    Post subject: Reply with quote

RTFM..
MSDN wrote:
lpflOldProtect [out]

A pointer to a variable that receives the previous access protection value of the first page in the specified region of pages. If this parameter is NULL or does not point to a valid variable, the function fails.
Back to top
View user's profile Send private message
TheRealLinky
How do I cheat?
Reputation: 0

Joined: 18 Jun 2009
Posts: 7

PostPosted: Mon Oct 19, 2009 3:39 pm    Post subject: Reply with quote

Your dll may be detected as a hack. Does it crash or just shut down? Whats the error code? What operating system is it? Is 32 or 64 bit? Is dep enabled?
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Mon Oct 19, 2009 6:17 pm    Post subject: Reply with quote

Jani: I think it's optional, I've used NULL for that arg countless times before without crashing.

OP: Are you even sure the pointer has allocated yet? Last time I checked the pointer was allocated after you get into a game.

Code:

DWORD dwVP = (DWORD)VirtualProtect;

bool __declspec(naked) VirtualProtectX( LPVOID lpAddress, SIZE_T dwSize, DWORD flNewProtect, PDWORD lpflOldProtect )
{
   _asm {
      push ebp
      mov esp, ebp
      jmp [dwVP]
   }
}
DWORD __stdcall mainT( void )
{
    if(!VirtualProtectX((LPVOID)0x178ACE8C, 4, PAGE_EXECUTE_READWRITE, NULL))
       return MessageBox(NULL, "Could not change page protection!", NULL, MB_ICONERROR);
    for(;;)
    {
       if(GetAsyncKeyState(VK_F10) & 0x8000)
          break;
    }
    MessageBox(NULL, "You've pushed F10!", "Success!", MB_OK);
    DWORD dwAmmo = NULL;
    for(;;Sleep(10))
    {
       dwAmmo = *(DWORD*)0x178ACE8C;
       if(dwAmmo != 0)
          *(DWORD*)0x178ACE8C = 100;
    }
}

BOOL WINAPI DllMain( HINSTANCE hInst, DWORD dwReason, LPVOID lpvReserved )
{
   if(dwReason == DLL_PROCESS_ATTACH)
   {
      DisableThreadLibraryCalls(hInst);
      return CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)&mainT, NULL, NULL, NULL) != INVALID_HANDLE_VALUE;
   }
   return false;
}


This should work, just push F10 after you're ingame.
Back to top
View user's profile Send private message
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Mon Oct 19, 2009 6:29 pm    Post subject: Reply with quote

Edit: Actually, it never worked.
Back to top
View user's profile Send private message MSN Messenger
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Tue Oct 20, 2009 4:02 am    Post subject: Reply with quote

&Vage wrote:
Jani: I think it's optional, I've used NULL for that arg countless times before without crashing.
Well, it doesn't say opt_ anywhere. Nor that it can be NULL.
So,
-> VirtualProtect fails, because the param is NULL.
-> He doesn't know about it, because he's not checking the return value.
-> He still tries to write the value.
-> Crash.
-> ???
-> Profit.
Back to top
View user's profile Send private message
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Tue Oct 20, 2009 7:16 pm    Post subject: Reply with quote

So if the NULL is the problem, should I replace NULL with 0?

Also, NULL is also 0.

#define NULL 0
Back to top
View user's profile Send private message MSN Messenger
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Wed Oct 21, 2009 3:50 am    Post subject: Reply with quote

iPromise wrote:
So if the NULL is the problem, should I replace NULL with 0?
...

What do you think? If it may NOT be 0 and you replace it with 0.. Sure that will work. What about actually storing the old protection? And better yet, restoring it when you're done with your tinkering.

@&Vage: your DllMain is always returning true, if dwReason == DLL_PROCESS_ATTACH, even if CreateThread failed. CreateThread doesn't return INVALID_HANDLE_VALUE when it fails.
Back to top
View user's profile Send private message
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Wed Oct 21, 2009 5:33 pm    Post subject: Reply with quote

I'll give it a test.
Back to top
View user's profile Send private message MSN Messenger
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Wed Nov 04, 2009 7:05 pm    Post subject: Reply with quote

DWORD Protection;

VirtualProtectX((LPVOID) 0x1234567, 4, PAGE_EXECUTE_READWRITE, &Protection);
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 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