QuestionSolvedwhat i have to do if my module base address is bigger than 32bits?

Posts 17 of 7 · Page 1 of 1
what i have to do if my module base address is bigger than 32bits?
in my case, my game's base address is 00007FF73BF50000
and i have to add this address 014C9910 to base address
and 8 118 28 60 14C offsets
but my visual studio project is 32bits
so when i try to compile it, i got a warning
someone help me how can i use readprocessmemory with this big baseaddress?

also i hope to know how can i get 00007FF73BF50000 address?
i saw this address in my cheat engine's pe preferred header image base address
but i don't like this way, i just hope to know it with my code
can i get this address just using process title name?

i can't use GetModuleHandle()
because my program is external




DWORD BaseAddress = 0x00007FF73BF50000;
DWORD MoneyAddr = 0x014C9910;
DWORD MoneyOffs[] = {0x8,0x118,0x28,0x60,0x14C};

HWND sh = ::FindWindow(NULL, TEXT("Slime Rancher"));
if (sh != NULL)
{
DWORD pid;
GetWindowThreadProcessId(sh, &pid);
HANDLE hp = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
DWORD hv = 0;

if (ReadProcessMemory(hp, [what i have to insert here?], &hv, sizeof(hv), 0) != 0)
{
cout << "[Address]:" << hv << endl;
int money = 300000;
WriteProcessMemory(hp, [what i have to insert here?], money, sizeof(money),0);
}
}
Quote Originally Posted by MikeRohsoft View Post
I would say, the easiest way would being lazy and use my class: https://www.mpgh.net/forum/showthrea...1#post13366671
It also provides an "getBaseAddress" Function
thanks for your help!
can you help me for fixing your header file?
i can't compile it with this error.


void Memory::initVars(MODULEENTRY32);

1>------ Build started: Project: BaseAddre, Configuration: Debug x64 ------
1>stdafx.cpp
1>c:\users\admin\source\repos\baseaddre\baseaddre\ mem.h(20): error C4596: 'initVars': illegal qualified name in member declaration
1>Done building project "BaseAddre.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
this is really less info. Maybe your Project is Unicode and doesnt need the conversion, i need a screenshot from the IDE what it made red for help u there
thanks for your answer!
Quote Originally Posted by MikeRohsoft View Post
this is really less info. Maybe your Project is Unicode and doesnt need the conversion, i need a screenshot from the IDE what it made red for help u there
https://gyazo.com/95b9dcd5b18c293c4f35d79596d0310f

here is my Visual Studio 2017 Screenshot
something wrong?
uhm just remove the Memory:: prefix, it seems for me

- - - Updated - - -

if it has still other problems, like encoding, try this version:
mem.h
Code:
    #ifndef __MEMORY__
    using offsets = std::vector<uint64_t>;
    class Memory
    {
    private:
    	HANDLE pHandle;
    	int pID;
    	uint64_t BaseAddress;
    	std::string FilePath;
    	uint64_t iSize;
    public:
    	Memory(const char*, const char* = nullptr);
    	~Memory();
    	bool isHex(char c);
    	std::string getFilePath();
    	uint64_t getBaseAddress();
    	int getProcessId();
    	uint64_t getImageSize();
    	HANDLE getHandle();
    	void initVars(MODULEENTRY32*);
    	void getProcess(const char*, PROCESSENTRY32*);
    	void getModule(const char*, MODULEENTRY32*, PROCESSENTRY32*);
    	uint64_t getAddress(uint64_t, offsets = {});
    	uint64_t patternScan(char*, std::string, uint64_t = 0);
    	uint64_t patternScan(const std::string&, uint64_t = 0);
    	bool createPattern(const std::string&, std::string&, std::string&);
     
    	template<typename T> T read(uint64_t Address, offsets offsets = {})
    	{
    		T ret;
    		if (Address == 0)
    			return ret;
    		uint64_t nAddress = getAddress(Address, offsets);
    		ReadProcessMemory(pHandle, (void*)nAddress, &ret, sizeof(T), 0);
    		return ret;
    	}
     
    	template<typename T> void write(uint64_t Address, T value, offsets offsets = {})
    	{
    		uint64_t nAddress = getAddress(Address, offsets);
    		WriteProcessMemory(pHandle, (void*)nAddress, &value, sizeof(T), 0);
    	}
     
    	std::string readString(uint64_t, int, offsets = {});
    	void writeString(uint64_t, std::string&, offsets = {});
    };
     
    #define __MEMORY__
    #endif
mem.cpp
Code:
    #include "stdafx.h"
     
    Memory::Memory(const char* processName, const char* moduleName)
    {
    	PROCESSENTRY32 pe32;
    	MODULEENTRY32 pe_module;
     
    	Memory::getProcess(processName, &pe32);
    	Memory::getModule(moduleName == nullptr ? processName : moduleName, &pe_module, &pe32);
    	Memory::initVars(&pe_module);
    	Memory::pHandle = OpenProcess(PROCESS_ALL_ACCESS, 0, pID);
    }
     
    Memory::~Memory()
    {
    	CloseHandle(pHandle);
    }
     
    std::string Memory::getFilePath()
    {
    	return FilePath;
    }
     
    uint64_t Memory::getBaseAddress()
    {
    	return BaseAddress;
    }
     
    int Memory::getProcessId()
    {
    	return pID;
    }
     
    uint64_t Memory::getImageSize()
    {
    	return iSize;
    }
     
    HANDLE Memory::getHandle()
    {
    	return pHandle;
    }
     
    void Memory::initVars(MODULEENTRY32* m)
    {
    #ifndef _MBCS
    	std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> w2sConverter;
    	Memory::FilePath = w2sConverter.to_bytes(m->szExePath).c_str();
    #else
    	Memory::FilePath = m->szExePath;
    #endif
    	Memory::BaseAddress = (uint64_t)m->modBaseAddr;
    	Memory::pID = m->th32ProcessID;
    	Memory::iSize = m->modBaseSize;
    }
     
    void Memory::getProcess(const char* processName, PROCESSENTRY32* process)
    {
    #ifndef _MBCS
    	std::wstring wprocessName;
    	std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> s2wconverter;
    #endif
    	HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
     
    	if (hSnap == INVALID_HANDLE_VALUE)
    		return;
     
    	process->dwSize = sizeof(PROCESSENTRY32);
    	if (Process32First(hSnap, process) == 0)
    		CloseHandle(hSnap);
    #ifndef _MBCS
    	wprocessName = s2wconverter.from_bytes(processName);
    #endif
    	do
    	{
    #ifndef _MBCS
    		if (lstrcmp(process->szExeFile, &wprocessName[0]) == 0)
    #else
    		if (lstrcmp(process->szExeFile, processName) == 0)
    #endif
    				break;
    	} while (Process32Next(hSnap, process));
    	CloseHandle(hSnap);
     
    	return;
    }
     
    void Memory::getModule(const char* moduleName, MODULEENTRY32* module, PROCESSENTRY32* process)
    {
    #ifndef _MBCS
    	std::wstring wmoduleName;
    	std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> s2wconverter;
    #endif
    	HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, process->th32ProcessID);
     
    	if (hSnap == INVALID_HANDLE_VALUE)
    		return;
     
    	module->dwSize = sizeof(MODULEENTRY32);
    	if (Module32First(hSnap, module) == 0)
    		CloseHandle(hSnap);
    #ifndef _MBCS
    	wmoduleName = s2wconverter.from_bytes(moduleName);
    #endif
    	do
    	{
    #ifndef _MBCS
    		if (lstrcmp(module->szModule, &wmoduleName[0]) == 0)
    #else
    		if (lstrcmp(module->szModule, moduleName) == 0)
    #endif
    			break;
    	} while (Module32Next(hSnap, module));
    	CloseHandle(hSnap);
     
    	return;
    }
     
    bool Memory::isHex(char c)
    {
    	return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
    }
     
    bool Memory::createPattern(const std::string& pattern, std::string& pattern_result, std::string& mask_result)
    {
    	bool result = false;
    	char buffer[2];
    	std::stringstream pattern_s;
    	std::stringstream mask_s;
     
    	if (pattern.empty())
    		return result;
     
    	for (size_t i = 0, l = pattern.size() - 1; i < l; i++)
    	{
    		if (Memory::isHex(pattern[i]))
    		{
    			buffer[0] = pattern[i];
    			buffer[1] = (l >= i + 1 && Memory::isHex(pattern[i + 1])) ? pattern[++i] : 0;
    			pattern_s << (char)strtol(buffer, nullptr, 16);
    			mask_s << 'x';
    			continue;
    		}
    		else if (pattern[i] == '?' || pattern[i] == '*')
    		{
    			pattern_s << "\x90";
    			mask_s << '?';
    			continue;
    		}
    	}
    	result = true;
    	pattern_result = pattern_s.str();
    	mask_result = mask_s.str();
     
    	return result;
    }
     
    uint64_t Memory::patternScan(const std::string& pattern, uint64_t startAddress)
    {
    	std::string sub_ptr;
    	std::string sub_mask;
    	Memory::createPattern(pattern, sub_ptr, sub_mask);
    	return Memory::patternScan(&sub_ptr[0], sub_mask, startAddress);
    }
     
    uint64_t Memory::patternScan(char* sig, std::string pattern, uint64_t startAddress)
    {
    	uint64_t ret = 0;
    	if (startAddress < Memory::BaseAddress || startAddress > (Memory::BaseAddress + Memory::iSize))
    		startAddress = Memory::BaseAddress;
    	char* cBuffer = new char[Memory::iSize];
    	ReadProcessMemory(Memory::pHandle, (void*)startAddress, cBuffer, Memory::iSize, 0);
    	size_t patternLength = pattern.size() - 1;
     
    	for (size_t i = 0, j = 0; i != Memory::iSize; i++)
    	{
    		if (cBuffer[i] == sig[j] || pattern[j] == '?')
    		{
    			if (j == patternLength)
    			{
    				ret = (startAddress + i - j);
    				goto PATTERN_SCAN_END;
    			}
     
    			j++;
    		}
    		else if (j > 0 && (cBuffer[i] == sig[0] || pattern[0] == '?'))
    		{
    			j = 1;
    		}
    		else
    		{
    			j = 0;
    		}
    	}
    PATTERN_SCAN_END:
    	delete[] cBuffer;
    	return ret;
    }
     
     
    uint64_t Memory::getAddress(uint64_t Address, offsets offsets)
    {
    	uint64_t nAddress = Address;
    	if (Address == 0)
    		return nAddress;
    	size_t size = offsets.size() - 1;
    	if (offsets.empty())
    		return nAddress;
     
    	ReadProcessMemory(Memory::pHandle, (void*)nAddress, &nAddress, sizeof(nAddress), 0);
    	for (size_t i = 0; i != size; i++)
    		ReadProcessMemory(Memory::pHandle, (void*)(nAddress + offsets[i]), &nAddress, sizeof(nAddress), 0);
    	nAddress = nAddress + offsets[size];
     
    	return nAddress;
    }
     
    std::string Memory::readString(uint64_t Address, int size, offsets offsets)
    {
    	std::string ret;
    	if (Address == 0)
    		return ret;
    	uint64_t nAddress = Memory::getAddress(Address, offsets);
    	char* buffer = new char[size];
    	ReadProcessMemory(Memory::pHandle, (void*)nAddress, buffer, size, 0);
    	ret = std::string(buffer);
    	delete[] buffer;
    	return ret;
    }
     
    void Memory::writeString(uint64_t Address, std::string& str, offsets offsets)
    {
    	uint64_t nAddress = Memory::getAddress(Address, offsets);
    	WriteProcessMemory(Memory::pHandle, (void*)nAddress, &str[0], str.size(), 0);
    	return;
    }
wow i successfully compiled it, but another error..
Quote Originally Posted by MikeRohsoft View Post
uhm just remove the Memory:: prefix, it seems for me

- - - Updated - - -

if it has still other problems, like encoding, try this version:
mem.h
Code:
    #ifndef __MEMORY__
    using offsets = std::vector<uint64_t>;
    class Memory
    {
    private:
    	HANDLE pHandle;
    	int pID;
    	uint64_t BaseAddress;
    	std::string FilePath;
    	uint64_t iSize;
    public:
    	Memory(const char*, const char* = nullptr);
    	~Memory();
    	bool isHex(char c);
    	std::string getFilePath();
    	uint64_t getBaseAddress();
    	int getProcessId();
    	uint64_t getImageSize();
    	HANDLE getHandle();
    	void initVars(MODULEENTRY32*);
    	void getProcess(const char*, PROCESSENTRY32*);
    	void getModule(const char*, MODULEENTRY32*, PROCESSENTRY32*);
    	uint64_t getAddress(uint64_t, offsets = {});
    	uint64_t patternScan(char*, std::string, uint64_t = 0);
    	uint64_t patternScan(const std::string&, uint64_t = 0);
    	bool createPattern(const std::string&, std::string&, std::string&);
     
    	template<typename T> T read(uint64_t Address, offsets offsets = {})
    	{
    		T ret;
    		if (Address == 0)
    			return ret;
    		uint64_t nAddress = getAddress(Address, offsets);
    		ReadProcessMemory(pHandle, (void*)nAddress, &ret, sizeof(T), 0);
    		return ret;
    	}
     
    	template<typename T> void write(uint64_t Address, T value, offsets offsets = {})
    	{
    		uint64_t nAddress = getAddress(Address, offsets);
    		WriteProcessMemory(pHandle, (void*)nAddress, &value, sizeof(T), 0);
    	}
     
    	std::string readString(uint64_t, int, offsets = {});
    	void writeString(uint64_t, std::string&, offsets = {});
    };
     
    #define __MEMORY__
    #endif
mem.cpp
Code:
    #include "stdafx.h"
     
    Memory::Memory(const char* processName, const char* moduleName)
    {
    	PROCESSENTRY32 pe32;
    	MODULEENTRY32 pe_module;
     
    	Memory::getProcess(processName, &pe32);
    	Memory::getModule(moduleName == nullptr ? processName : moduleName, &pe_module, &pe32);
    	Memory::initVars(&pe_module);
    	Memory::pHandle = OpenProcess(PROCESS_ALL_ACCESS, 0, pID);
    }
     
    Memory::~Memory()
    {
    	CloseHandle(pHandle);
    }
     
    std::string Memory::getFilePath()
    {
    	return FilePath;
    }
     
    uint64_t Memory::getBaseAddress()
    {
    	return BaseAddress;
    }
     
    int Memory::getProcessId()
    {
    	return pID;
    }
     
    uint64_t Memory::getImageSize()
    {
    	return iSize;
    }
     
    HANDLE Memory::getHandle()
    {
    	return pHandle;
    }
     
    void Memory::initVars(MODULEENTRY32* m)
    {
    #ifndef _MBCS
    	std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> w2sConverter;
    	Memory::FilePath = w2sConverter.to_bytes(m->szExePath).c_str();
    #else
    	Memory::FilePath = m->szExePath;
    #endif
    	Memory::BaseAddress = (uint64_t)m->modBaseAddr;
    	Memory::pID = m->th32ProcessID;
    	Memory::iSize = m->modBaseSize;
    }
     
    void Memory::getProcess(const char* processName, PROCESSENTRY32* process)
    {
    #ifndef _MBCS
    	std::wstring wprocessName;
    	std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> s2wconverter;
    #endif
    	HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
     
    	if (hSnap == INVALID_HANDLE_VALUE)
    		return;
     
    	process->dwSize = sizeof(PROCESSENTRY32);
    	if (Process32First(hSnap, process) == 0)
    		CloseHandle(hSnap);
    #ifndef _MBCS
    	wprocessName = s2wconverter.from_bytes(processName);
    #endif
    	do
    	{
    #ifndef _MBCS
    		if (lstrcmp(process->szExeFile, &wprocessName[0]) == 0)
    #else
    		if (lstrcmp(process->szExeFile, processName) == 0)
    #endif
    				break;
    	} while (Process32Next(hSnap, process));
    	CloseHandle(hSnap);
     
    	return;
    }
     
    void Memory::getModule(const char* moduleName, MODULEENTRY32* module, PROCESSENTRY32* process)
    {
    #ifndef _MBCS
    	std::wstring wmoduleName;
    	std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> s2wconverter;
    #endif
    	HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, process->th32ProcessID);
     
    	if (hSnap == INVALID_HANDLE_VALUE)
    		return;
     
    	module->dwSize = sizeof(MODULEENTRY32);
    	if (Module32First(hSnap, module) == 0)
    		CloseHandle(hSnap);
    #ifndef _MBCS
    	wmoduleName = s2wconverter.from_bytes(moduleName);
    #endif
    	do
    	{
    #ifndef _MBCS
    		if (lstrcmp(module->szModule, &wmoduleName[0]) == 0)
    #else
    		if (lstrcmp(module->szModule, moduleName) == 0)
    #endif
    			break;
    	} while (Module32Next(hSnap, module));
    	CloseHandle(hSnap);
     
    	return;
    }
     
    bool Memory::isHex(char c)
    {
    	return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
    }
     
    bool Memory::createPattern(const std::string& pattern, std::string& pattern_result, std::string& mask_result)
    {
    	bool result = false;
    	char buffer[2];
    	std::stringstream pattern_s;
    	std::stringstream mask_s;
     
    	if (pattern.empty())
    		return result;
     
    	for (size_t i = 0, l = pattern.size() - 1; i < l; i++)
    	{
    		if (Memory::isHex(pattern[i]))
    		{
    			buffer[0] = pattern[i];
    			buffer[1] = (l >= i + 1 && Memory::isHex(pattern[i + 1])) ? pattern[++i] : 0;
    			pattern_s << (char)strtol(buffer, nullptr, 16);
    			mask_s << 'x';
    			continue;
    		}
    		else if (pattern[i] == '?' || pattern[i] == '*')
    		{
    			pattern_s << "\x90";
    			mask_s << '?';
    			continue;
    		}
    	}
    	result = true;
    	pattern_result = pattern_s.str();
    	mask_result = mask_s.str();
     
    	return result;
    }
     
    uint64_t Memory::patternScan(const std::string& pattern, uint64_t startAddress)
    {
    	std::string sub_ptr;
    	std::string sub_mask;
    	Memory::createPattern(pattern, sub_ptr, sub_mask);
    	return Memory::patternScan(&sub_ptr[0], sub_mask, startAddress);
    }
     
    uint64_t Memory::patternScan(char* sig, std::string pattern, uint64_t startAddress)
    {
    	uint64_t ret = 0;
    	if (startAddress < Memory::BaseAddress || startAddress > (Memory::BaseAddress + Memory::iSize))
    		startAddress = Memory::BaseAddress;
    	char* cBuffer = new char[Memory::iSize];
    	ReadProcessMemory(Memory::pHandle, (void*)startAddress, cBuffer, Memory::iSize, 0);
    	size_t patternLength = pattern.size() - 1;
     
    	for (size_t i = 0, j = 0; i != Memory::iSize; i++)
    	{
    		if (cBuffer[i] == sig[j] || pattern[j] == '?')
    		{
    			if (j == patternLength)
    			{
    				ret = (startAddress + i - j);
    				goto PATTERN_SCAN_END;
    			}
     
    			j++;
    		}
    		else if (j > 0 && (cBuffer[i] == sig[0] || pattern[0] == '?'))
    		{
    			j = 1;
    		}
    		else
    		{
    			j = 0;
    		}
    	}
    PATTERN_SCAN_END:
    	delete[] cBuffer;
    	return ret;
    }
     
     
    uint64_t Memory::getAddress(uint64_t Address, offsets offsets)
    {
    	uint64_t nAddress = Address;
    	if (Address == 0)
    		return nAddress;
    	size_t size = offsets.size() - 1;
    	if (offsets.empty())
    		return nAddress;
     
    	ReadProcessMemory(Memory::pHandle, (void*)nAddress, &nAddress, sizeof(nAddress), 0);
    	for (size_t i = 0; i != size; i++)
    		ReadProcessMemory(Memory::pHandle, (void*)(nAddress + offsets[i]), &nAddress, sizeof(nAddress), 0);
    	nAddress = nAddress + offsets[size];
     
    	return nAddress;
    }
     
    std::string Memory::readString(uint64_t Address, int size, offsets offsets)
    {
    	std::string ret;
    	if (Address == 0)
    		return ret;
    	uint64_t nAddress = Memory::getAddress(Address, offsets);
    	char* buffer = new char[size];
    	ReadProcessMemory(Memory::pHandle, (void*)nAddress, buffer, size, 0);
    	ret = std::string(buffer);
    	delete[] buffer;
    	return ret;
    }
     
    void Memory::writeString(uint64_t Address, std::string& str, offsets offsets)
    {
    	uint64_t nAddress = Memory::getAddress(Address, offsets);
    	WriteProcessMemory(Memory::pHandle, (void*)nAddress, &str[0], str.size(), 0);
    	return;
    }
thanks for your help! finally now i can successfully compile it!
Posts 17 of 7 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?