WirteAddressOffset , WriteBytes , Write2Byte , Write8Byte ,WriteFloat
本帖最後由 BeeBan 於 2024-10-9 13:38 編輯WirteAddressOffset : 寫入基址,偏移
void WriteAddressOffset(DWORD baseAddress, std::vector<DWORD> offsets, int value)
{
HANDLE hProcess = GetPvZProcessHandle();//這邊只是我讀取我遊戲的進程
if (hProcess == NULL) return;
DWORD currentAddress;
SIZE_T bytesRead;
if (!ReadProcessMemory(hProcess, (LPCVOID)baseAddress, ¤tAddress, sizeof(currentAddress), &bytesRead)) {
CloseHandle(hProcess);
return;
}
for (size_t i = 0; i < offsets.size(); i++) {
currentAddress += offsets;
if (i != offsets.size() - 1) {
if (!ReadProcessMemory(hProcess, (LPCVOID)currentAddress, ¤tAddress, sizeof(currentAddress), &bytesRead)) {
CloseHandle(hProcess);
return;
}
}
}
if (!WriteProcessMemory(hProcess, (LPVOID)currentAddress, &value, sizeof(value), NULL)) {
CloseHandle(hProcess);
return;
}
CloseHandle(hProcess);//關閉進程
}
例句: WriteAddressOffset(0x006A9EC0, {0x768, 0x5560}, 9990); //基址, 一級偏移 , 二級偏移, 數值 (在裡面處理多個偏移也都是沒有問題
---------------------------------------------------------------------------------------------------------------------------------------------------------------
WriteBytes : 寫入4自節
static bool WriteBytes(DWORD dwAddr, const std::initializer_list<unsigned char>& bytes) //用來寫入數據
{
DWORD dwOld;
size_t len = bytes.size();
if (!VirtualProtect((LPVOID)dwAddr, len, PAGE_EXECUTE_READWRITE, &dwOld)) {
return false;
}
memcpy_s((void*)dwAddr, len, bytes.begin(), len);
DWORD dwNew;
return VirtualProtect((LPVOID)dwAddr, len, dwOld, &dwNew);
}
例: WriteBytes(0x0054EBA8, { 0xEB, 0x00, 0x80 });
---------------------------------------------------------------------------------------------------------------------------------------------------------------
Write2Byte : 專門用來寫入2個字節的數據
static bool Write2Byte(DWORD dwAddr, WORD value) //WORD是2字節(16位)
{
DWORD dwOld;
if (!VirtualProtect((LPVOID)dwAddr, sizeof(WORD), PAGE_EXECUTE_READWRITE, &dwOld)) {
return false;
}
*(WORD*)dwAddr = value;
DWORD dwNew;
return VirtualProtect((LPVOID)dwAddr, sizeof(WORD), dwOld, &dwNew);
}
例:Write2Byte(0x0040E477,0xEB46);
---------------------------------------------------------------------------------------------------------------------------------------------------------------
Write8Byte: 專門用來寫入8個字節的數據
static bool Write8Byte(DWORD dwAddr, uint64_t value) //8字節(64位)
{
DWORD dwOld;
if (!VirtualProtect((LPVOID)dwAddr, sizeof(uint64_t), PAGE_EXECUTE_READWRITE, &dwOld)) {
return false;
}
*(uint64_t*)dwAddr = value;
DWORD dwNew;
return VirtualProtect((LPVOID)dwAddr, sizeof(uint64_t), dwOld, &dwNew);
}
例:Write8Byte(0x0040D7D0,0xB001C3285357);
---------------------------------------------------------------------------------------------------------------------------------------------------------------
WriteFloat : 專門用來寫入 4 字節的浮點數
static bool WriteFloat(DWORD dwAddr, float value) //4字節的浮點數
{
DWORD dwOld;
if (!VirtualProtect((LPVOID)dwAddr, sizeof(float), PAGE_EXECUTE_READWRITE, &dwOld)) {
return false;
}
*(float*)dwAddr = value;
DWORD dwNew;
return VirtualProtect((LPVOID)dwAddr, sizeof(float), dwOld, &dwNew);
}
例: WriteFloat(0x0040F000, 1.23f);
頁:
[1]