 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
shakib187 Expert Cheater
Reputation: 0
Joined: 24 May 2007 Posts: 215
|
Posted: Mon Apr 28, 2014 5:21 am Post subject: [C++/DLL]Crashing when injected |
|
|
| Code: |
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <string>
#include <fstream>
#include <float.h>
using namespace std;
void block()
{
mouse_event(MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0);
Sleep(1);
mouse_event(MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0);
}
DWORD WINAPI LoopFunction( LPVOID lpParam )
{
HANDLE phandle = GetCurrentProcess();
DWORD BaseAddr = (DWORD)GetModuleHandleA("entus.exe");
DWORD painted = 0x017234238;
DWORD pointer2 = BaseAddr+painted;
DWORD thesecond = (DWORD)(*(DWORD*)pointer2 + 0x17c);
DWORD thethird = (DWORD)(*(DWORD*)thesecond + 0x030);
DWORD thefourth = (DWORD)(*(DWORD*)thethird + 0x05D0);
DWORD theresult = (DWORD)(*(DWORD*)thefourth + 0x4E8);
DWORD pointed;
pointed = *(DWORD*)theresult;
while(1) {
if (GetAsyncKeyState(VK_HOME)&1)
if ((*(DWORD*)pointed) == 13)
{
(block());
}
}
Sleep(1);
return 0;
}
BOOL WINAPI DllMain (HINSTANCE hModule, DWORD dwAttached, LPVOID lpvReserved)
{
if (dwAttached == DLL_PROCESS_ATTACH) {
CreateThread(NULL,0,&LoopFunction,NULL,0,NULL);
}
return 1;
}
|
Anyone know what is wrong?
|
|
| Back to top |
|
 |
zm0d Master Cheater
Reputation: 7
Joined: 06 Nov 2013 Posts: 423
|
Posted: Mon Apr 28, 2014 10:09 am Post subject: |
|
|
Didn't got deep in your code but on my first opinion there's probably something wrong with your pointer calculation. Use SteveAndrews method to calculate multi-level pointers:
Code by SteveAndrew he gave me once:
| Code: | void *GetPointerSafest(DWORD PointerBase, ...)
{
DWORD CurrentPointer = (PointerBase + (DWORD)GetModuleHandle(0));
DWORD LastOffset = 0, BytesRead;
va_list Params;
va_start(Params, PointerBase);
for(;;)
{
unsigned int CurrentOffset = va_arg(Params, unsigned int);
if(CurrentOffset != 0xffffffff)
{
CurrentPointer += LastOffset;
ReadProcessMemory((HANDLE)-1, (void*)CurrentPointer, (void*)&CurrentPointer, 4, &BytesRead);
if(BytesRead != 4 || CurrentPointer == 0) //failed reading or we ran into null pointer!
{
CurrentPointer = 0;
break;
}
LastOffset = CurrentOffset;
}
else
{
CurrentPointer += LastOffset;
break;
}
}
va_end(Params);
return (void*)CurrentPointer;
} |
It's ease to use and works correct.
Edit:
Also I'd prefer to use GetModuleHandle(0) when using an injected DLL since this will always return your executables base address. =)
Regards,
zm0d
|
|
| 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
|
|