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 


i want get value from cheat engine address in c++

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

Joined: 29 May 2019
Posts: 32

PostPosted: Wed May 13, 2020 12:08 pm    Post subject: i want get value from cheat engine address in c++ Reply with quote

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]



ללא שם.png
 Description:
 Filesize:  9.82 KB
 Viewed:  6953 Time(s)

ללא שם.png


Back to top
View user's profile Send private message
OldCheatEngineUser
Whateven rank
Reputation: 20

Joined: 01 Feb 2016
Posts: 1586

PostPosted: Wed May 13, 2020 1:55 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
gavrielsinvani
Cheater
Reputation: 0

Joined: 29 May 2019
Posts: 32

PostPosted: Wed May 13, 2020 2:31 pm    Post subject: Reply with quote

OldCheatEngineUser wrote:
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



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
View user's profile Send private message
OldCheatEngineUser
Whateven rank
Reputation: 20

Joined: 01 Feb 2016
Posts: 1586

PostPosted: Wed May 13, 2020 6:51 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
gavrielsinvani
Cheater
Reputation: 0

Joined: 29 May 2019
Posts: 32

PostPosted: Thu May 14, 2020 6:20 am    Post subject: Reply with quote

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
View user's profile Send private message
DanyDollaro
Master Cheater
Reputation: 3

Joined: 01 Aug 2019
Posts: 334

PostPosted: Thu May 14, 2020 10:14 am    Post subject: Reply with quote

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
View user's profile Send private message
OldCheatEngineUser
Whateven rank
Reputation: 20

Joined: 01 Feb 2016
Posts: 1586

PostPosted: Thu May 14, 2020 1:22 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
DanyDollaro
Master Cheater
Reputation: 3

Joined: 01 Aug 2019
Posts: 334

PostPosted: Thu May 14, 2020 1:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
OldCheatEngineUser
Whateven rank
Reputation: 20

Joined: 01 Feb 2016
Posts: 1586

PostPosted: Thu May 14, 2020 3:33 pm    Post subject: Reply with quote

why you are being so personal Question 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
View user's profile Send private message Visit poster's website
DanyDollaro
Master Cheater
Reputation: 3

Joined: 01 Aug 2019
Posts: 334

PostPosted: Thu May 14, 2020 4:22 pm    Post subject: Reply with quote

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
View user's profile Send private message
OldCheatEngineUser
Whateven rank
Reputation: 20

Joined: 01 Feb 2016
Posts: 1586

PostPosted: Thu May 14, 2020 5:20 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
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