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 


Problem with base module address (C++)

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
KnifeOnlyI
How do I cheat?
Reputation: 0

Joined: 01 Feb 2021
Posts: 2

PostPosted: Mon Feb 01, 2021 11:37 am    Post subject: Problem with base module address (C++) Reply with quote

Hi everyone,

(Sorry for my english, I'm french, I'll do my best... Especially without translator)

I'm here because I have a problem to fetch a module base address (for tests, I use a game and Cheat engine to compare C++ results).
The problem is probably related to 32/64bit application, but I can't find it.
I already change the DWORD to DWORD_PTR.
I suppose the game is a 32bit build. Because the register can found are theses : eax, esi and not rax, rsi.

Here is my code function to get a base address of the specified proccess pid and name :

Code:

DWORD_PTR ProcessService::getModuleBaseAddress(DWORD_PTR pid, const std::string &name)
{
    DWORD_PTR modBaseAddr {0};
    HANDLE hSnap {CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, pid)};

    if (hSnap != INVALID_HANDLE_VALUE)
    {
        MODULEENTRY32 modEntry;
        modEntry.dwSize = sizeof(modEntry);

        if (Module32First(hSnap, &modEntry))
        {
            do
            {
                const std::string curModuleName {modEntry.szModule};

                if (name == curModuleName)
                {
                    modBaseAddr = reinterpret_cast<DWORD_PTR>(modEntry.modBaseAddr);

                    break;
                }
            } while (Module32Next(hSnap, &modEntry));
        }
    }

    CloseHandle(hSnap);

    return modBaseAddr; // 0x400000, this value is probably wrong because 32/64bit problem ?
}


And here, my code to perform calculation on address + offsets :

Code:

DWORD_PTR Process::getAddressFromOffsets(DWORD_PTR virtualAddress, const std::vector<unsigned int> &offsets) const
{
    // _address          = 0x400000
    // _virtualAddress = 0x1100F8
    DWORD_PTR addr {_address + virtualAddress}; // Results = 0x5100f8

    int i {0};

    for (unsigned int offset : offsets)
    {
        // Find which address is pointed by *addr pointer
        ReadProcessMemory(_handle, (DWORD_PTR *) addr, &addr, sizeof(addr), nullptr);

        // Add offset to address to find the next pointer
        addr += offset;

        i++;
    }

    return addr;
}


Output results (I remove in the above code to not hide the "real" code):

Quote:

"game.exe" + 1100f8 -> 80c252868
[80c252868 + 438] -> 80c252868
[80c252ca0 + 1f0] -> 80c252ca0
[80c252e90 + 18] -> 80c252e90
[80c252ea8 + 1dc] -> 80c252ea8
[80c253084 + 8] -> 80c253084
[80c25308c + 150] -> 80c25308c


Cheat engine results are in attachement.

I know it's a very common problem, but after a days of research, I failed to solve myself...

Thanks for the help.



Capture.PNG
 Description:
 Filesize:  16.39 KB
 Viewed:  1124 Time(s)

Capture.PNG




Last edited by KnifeOnlyI on Tue Feb 02, 2021 4:43 am; edited 1 time in total
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Mon Feb 01, 2021 1:50 pm    Post subject: Reply with quote

We do not support online/multiplayer hacking on this site.
https://forum.cheatengine.org/faq.php#0

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
KnifeOnlyI
How do I cheat?
Reputation: 0

Joined: 01 Feb 2021
Posts: 2

PostPosted: Tue Feb 02, 2021 4:46 am    Post subject: Reply with quote

Thanks.

I updated the post (Except the screenshot, I need it to compare my calculation and cheat engine results).
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking 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