View previous topic :: View next topic |
Author |
Message |
gavrielsinvani Cheater Reputation: 0
Joined: 29 May 2019 Posts: 32
|
Posted: Wed May 13, 2020 12:08 pm Post subject: i want get value from cheat engine address in c++ |
|
|
i have it:
Cheat engine:
"game.exe"+007EC208
pointer = D4C
and i get value in cheat engine ,
so...
now i want get value of it address in c++ ,
simple:
int GetValue = "game.exe"+007EC208+D4C;
printf("the value is : x " .. GetValue );
Do you understand me, now how I do it right?
please help me
[/img]
Description: |
|
Filesize: |
9.82 KB |
Viewed: |
7066 Time(s) |
|
|
|
Back to top |
|
|
OldCheatEngineUser Whateven rank Reputation: 20
Joined: 01 Feb 2016 Posts: 1587
|
Posted: Wed May 13, 2020 1:55 pm Post subject: |
|
|
CEF have tons of similar topics, use the search to find what you need.
here is an example:
https://forum.cheatengine.org/viewtopic.php?p=5716973#5716973
_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
Jul 26, 2020
STN wrote: | i am a sweetheart. |
|
|
Back to top |
|
|
gavrielsinvani Cheater Reputation: 0
Joined: 29 May 2019 Posts: 32
|
Posted: Wed May 13, 2020 2:31 pm Post subject: |
|
|
I tried to do this:
But the value I get is wrong,
What did I do wrong?
Code: |
DWORD GetProcId(const wchar_t* procName)
{
DWORD procId = 0;
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnap != INVALID_HANDLE_VALUE)
{
PROCESSENTRY32 procEntry;
procEntry.dwSize = sizeof(procEntry);
if (Process32First(hSnap, &procEntry))
{
do
{
if (!_wcsicmp(procEntry.szExeFile, procName))
{
procId = procEntry.th32ProcessID;
break;
}
} while (Process32Next(hSnap, &procEntry));
}
}
CloseHandle(hSnap);
return procId;
}
uintptr_t GetModuleBaseAddress(DWORD procId, const wchar_t* modName)
{
uintptr_t modBaseAddr = 0;
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, procId);
if (hSnap != INVALID_HANDLE_VALUE)
{
MODULEENTRY32 modEntry;
modEntry.dwSize = sizeof(modEntry);
if (Module32First(hSnap, &modEntry))
{
do
{
if (!_wcsicmp(modEntry.szModule, modName))
{
modBaseAddr = (uintptr_t)modEntry.modBaseAddr;
break;
}
} while (Module32Next(hSnap, &modEntry));
}
}
CloseHandle(hSnap);
return modBaseAddr;
}
uintptr_t FindDMAAddy(HANDLE hProc, uintptr_t ptr, std::vector<unsigned int> offsets)
{
uintptr_t addr = ptr;
for (unsigned int i = 0; i < offsets.size(); ++i)
{
ReadProcessMemory(hProc, (BYTE*)addr, &addr, sizeof(addr), 0);
addr += offsets[i];
}
return addr;
}
//Get ProcId of the target process
DWORD procId = GetProcId(L"game.exe");
//Getmodulebaseaddress
uintptr_t moduleBase = GetModuleBaseAddress(procId, L"game.exe");
//Get Handle to Process
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, NULL, procId);
//Resolve base address of the pointer chain
uintptr_t dynamicPtrBaseAddr = moduleBase + 0x007EC208;
//Resolve the pointer chain
std::vector<unsigned int> offsets = {0xD4C};
uintptr_t addr = FindDMAAddy(hProcess, dynamicPtrBaseAddr, offsets);
label88->Text = Convert::ToString(addr); // Print Value
|
|
|
Back to top |
|
|
OldCheatEngineUser Whateven rank Reputation: 20
Joined: 01 Feb 2016 Posts: 1587
|
Posted: Wed May 13, 2020 6:51 pm Post subject: |
|
|
gavrielsinvani wrote: | Code: | return procId;
...
//Get ProcId of the target process
DWORD procId = GetProcId(L"game.exe"); |
|
you are not performing any checks on procID, what if you did not find the desired PID?
all else looks good to me, with exception for <...> thingy that i do not understand; i can safely guess this is c++ related thing.
is your target process 32-bit or 64-bit? because its unclear what data-types you are using!
_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
Jul 26, 2020
STN wrote: | i am a sweetheart. |
|
|
Back to top |
|
|
gavrielsinvani Cheater Reputation: 0
Joined: 29 May 2019 Posts: 32
|
Posted: Thu May 14, 2020 6:20 am Post subject: |
|
|
OldCheatEngineUser wrote: | gavrielsinvani wrote: | Code: | return procId;
...
//Get ProcId of the target process
DWORD procId = GetProcId(L"game.exe"); |
|
you are not performing any checks on procID, what if you did not find the desired PID?
all else looks good to me, with exception for <...> thingy that i do not understand; i can safely guess this is c++ related thing.
is your target process 32-bit or 64-bit? because its unclear what data-types you are using! |
If it matters it's dll trainer (i think winapi 32 c++ code) I inject into the game
=/I don't understand where I was wrong
|
|
Back to top |
|
|
DanyDollaro Master Cheater Reputation: 3
Joined: 01 Aug 2019 Posts: 334
|
Posted: Thu May 14, 2020 10:14 am Post subject: |
|
|
gavrielsinvani wrote: | If it matters it's dll trainer (i think winapi 32 c++ code) I inject into the game |
Yes, it is very, very, very important.
In the source code I don't see the main (of the Dll), and since you are doing an internal hack there are no reasons to use "ReadProcessMemory" since to read in memory with an injected Dll just do this:
Code: | int Var = *(int*) 0x00400000; |
Same thing for other functions.
Fortunately for you I found an old template, I could write it in better ways but I think it is enough to give you an idea of what you want to do:
Code: | #include "pch.h"
#include <iostream>
#include <vector>
#include <Windows.h>
FILE* Console;
DWORD WINAPI Dll_main(HMODULE hModule)
{
AllocConsole();
freopen_s(&Console, "CONOUT$", "w", stdout);
size_t ModuleBase = (size_t)GetModuleHandle(L"Module Name");
size_t* Adr = reinterpret_cast<size_t*>((*reinterpret_cast<size_t*>(ModuleBase + 0x007EC208)) + 0x0D4C);
while (true) {
std::cout << *Adr << '\n';
Sleep(500);
}
return 0;
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
CloseHandle(CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)Dll_main, hModule, 0, nullptr));
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
|
Edit: I corrected the reference to the DllMain function in the call to CreateThread
Last edited by DanyDollaro on Thu May 14, 2020 1:38 pm; edited 1 time in total |
|
Back to top |
|
|
OldCheatEngineUser Whateven rank Reputation: 20
Joined: 01 Feb 2016 Posts: 1587
|
Posted: Thu May 14, 2020 1:22 pm Post subject: |
|
|
you think its c++ 32bit?
its clear that you did not write anything, and if you dont know your target bitness nor your dll bitness then ... idk no comment.
_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
Jul 26, 2020
STN wrote: | i am a sweetheart. |
|
|
Back to top |
|
|
DanyDollaro Master Cheater Reputation: 3
Joined: 01 Aug 2019 Posts: 334
|
Posted: Thu May 14, 2020 1:42 pm Post subject: |
|
|
OldCheatEngineUser wrote: | you think its c++ 32bit?
its clear that you did not write anything, and if you dont know your target bitness nor your dll bitness then ... idk no comment.
|
It is not C++ that has 32 bits, but the compilation of the project can have that feature.
I said it's an idea, I didn't say that Dll works for anything.
DanyDollaro wrote: | to give you an idea |
and among other things, not knowing the bitness of the program in which the Dll will be injected I wrote the local variables of the Dll as "size_t".
|
|
Back to top |
|
|
OldCheatEngineUser Whateven rank Reputation: 20
Joined: 01 Feb 2016 Posts: 1587
|
Posted: Thu May 14, 2020 3:33 pm Post subject: |
|
|
why you are being so personal what is your problem?
_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
Jul 26, 2020
STN wrote: | i am a sweetheart. |
|
|
Back to top |
|
|
DanyDollaro Master Cheater Reputation: 3
Joined: 01 Aug 2019 Posts: 334
|
Posted: Thu May 14, 2020 4:22 pm Post subject: |
|
|
OldCheatEngineUser wrote: | why you are being so personal Question what is your problem? |
Can you explain what this question has to do with the thread theme? if you have something serious to say you can PM me.
I remind you not to ask unnecessary questions to go OT
|
|
Back to top |
|
|
OldCheatEngineUser Whateven rank Reputation: 20
Joined: 01 Feb 2016 Posts: 1587
|
Posted: Thu May 14, 2020 5:20 pm Post subject: |
|
|
DanyDollaro wrote: | I remind you not to ask unnecessary questions to go OT |
no need for backseat moderating, keep this for moderators.
_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
Jul 26, 2020
STN wrote: | i am a sweetheart. |
|
|
Back to top |
|
|
|