 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
GFr3AK How do I cheat?
Reputation: 0
Joined: 24 May 2014 Posts: 1
|
Posted: Sat May 24, 2014 5:36 pm Post subject: [HELP]retrive module base |
|
|
Hello everyone , after 2 days of hard searching for a good answer , I decided to ask you guys hopeing you'll give me any usefull answer.
I try to get and "base address" (starting address of a program "FreeCell").The problem is , I inject a module inside , then get the process id , process handle etc , and finaly i try to (ofstream to an file, my resoult).
I retrive the good pid , which seems to be the right one if I use the cast (int) , like : cout<<(int)process_id;
My question is , why i can't get the base address of the program , the starting address of the program.All I know is that windows 7 has some kind of dynamic base address changer , that's why the memories of programs running on win7 are changing every time I restart pc.
Here is the code , I don't know if the DWORD GetModuleBase function is correct writen or if the GetModuleBase(x,y) returns any kind of data and I don't know how to view it.
| Code: |
#include <iostream>
#include <Windows.h>
#include <stdio.h>
#include <TlHelp32.h>
#include <Psapi.h>
#include <tchar.h>
#include <string.h>
#include <fstream>
#include <direct.h>
using namespace std;
#pragma comment( lib, "psapi" )
//------------------------------------------------------------------------------------------------------------
DWORD GetModuleBase(const char *szModuleName,const DWORD dwProcessId) {
if ((dwProcessId) || (!szModuleName)) {
return 0;
}
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcessId);
if (hSnap == INVALID_HANDLE_VALUE) {
return 0;
}
MODULEENTRY32 me;
me.dwSize = sizeof(MODULEENTRY32);
DWORD dwReturn = 0;
if(Module32First(hSnap, &me)) {
while (Module32Next(hSnap, &me)) {
if( !strcmp(reinterpret_cast<const char *>(me.szModule), szModuleName)) {
CloseHandle (hSnap);
dwReturn = (DWORD)me.modBaseAddr;
return dwReturn;
}
}
}
CloseHandle(hSnap);
return dwReturn;
}
void do_process(HANDLE hinst)
{
DWORD pid;
HWND wnd = FindWindowA(NULL,"FreeCell");
GetWindowThreadProcessId(wnd,&pid);
HANDLE proces = OpenProcess((DWORD)PROCESS_ALL_ACCESS,0,pid);
//pid = GetProcessId(proces);
ofstream f;
f.open("ion.txt");
f<<(int)pid<<endl<<GetModuleBase("FreeCell.exe",pid);
f.close();
MessageBox(0,L"Injected!",L"Hack",MB_OK);
}
//------------------------------------------------------------------------------------------------------------
BOOL WINAPI DllMain(HANDLE inst,DWORD reas,LPVOID lpres)
{
switch(reas)
{
case DLL_PROCESS_ATTACH:
do_process(inst);
break;
}
return TRUE;
}
|
Mentions : I have and injector , it works fine , and I recive the message + the text inside the "ion.txt"
Hope you could help me.
Sincerly GFr3AK
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sat May 24, 2014 9:44 pm Post subject: |
|
|
Given that you are injected you are doing things a bit outlandish than what is needed.
For one, you don't need to use FindWindow/GetWindowThreadProcessId to get the process id. Instead, you can just use GetCurrentProcessId().
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683180(v=vs.85).aspx
Next, since you want the process base itself of the process you do not need to iterate Module32Next at all. Just call Module32First and return the base address from that first call since it will return the base of the process itself. (The process is the first module in the list.)
| Code: | DWORD GetModuleBase(DWORD dwProcessId)
{
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcessId);
if (hSnap == INVALID_HANDLE_VALUE) {
return 0;
}
MODULEENTRY32 me;
me.dwSize = sizeof(MODULEENTRY32);
bool bRet = Module32First(hSnap, &me);
CloseHandle(hSnap);
return (bRet) ? (DWORD)me.modBaseAddr : 0;
} |
Like that given your current code. You can also use GetModuleHandle instead for a simple 1 call.
_________________
- Retired. |
|
| 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
|
|