問題描述
我想要一個函數來讀取另一個進程的內存.我在想這樣的事情(偽代碼):
I'd like to have a function that allows me to read the memory of another process. I was thinking about something like this (pseudo code):
staticAddress = 0x026E0DC4
processId = GetProcessIdByName(processName)
processHandle = GetProcessHandle(processId)
processBaseAddress = GetBaseAddress(processHandle)
addressToRead = processBaseAddress+staticAddress
readValueAsInt = ReadMemoryInt(processHandle, addressToRead)
readValueAsFloat = ReadMemoryFloat(processHandle, addressToRead)
readValueAsString = ReadMemoryString(processHandle, addressToRead)
這可能嗎?這是我目前得到的:
Would that even be possible? Here is what I got so far:
#include <Windows.h>
#include <conio.h>
#include <tlhelp32.h>
#include <string>
#include <psapi.h>
#pragma comment( lib, "psapi" )
int GetProcessId(char* ProcName) {
PROCESSENTRY32 pe32;
HANDLE hSnapshot = NULL;
pe32.dwSize = sizeof( PROCESSENTRY32 );
hSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
if( Process32First( hSnapshot, &pe32 ) ) {
do {
if( strcmp( pe32.szExeFile, ProcName ) == 0 )
break;
} while( Process32Next( hSnapshot, &pe32 ) );
}
if( hSnapshot != INVALID_HANDLE_VALUE )
CloseHandle( hSnapshot );
return pe32.th32ProcessID;
}
int GetModuleBase(HANDLE processHandle, string &sModuleName)
{
HMODULE *hModules;
char szBuf[50];
DWORD cModules;
DWORD dwBase = -1;
//------
EnumProcessModules(processHandle, hModules, 0, &cModules);
hModules = new HMODULE[cModules/sizeof(HMODULE)];
if(EnumProcessModules(processHandle, hModules, cModules/sizeof(HMODULE), &cModules)) {
for(int i = 0; i < cModules/sizeof(HMODULE); i++) {
if(GetModuleBaseName(processHandle, hModules[i], szBuf, sizeof(szBuf))) {
if(sModuleName.compare(szBuf) == 0) {
dwBase = (DWORD)hModules[i];
break;
}
}
}
}
delete[] hModules;
return dwBase;
}
int ReadMemoryInt(HANDLE processHandle, LPCVOID address) {
//LPVOID buffer = ??;
//SIZE_T size = ??;
SIZE_T NumberOfBytesToRead = 4; //??
ReadProcessMemory(processHandle, address, buffer, size, NumberOfBytesToRead)
return buffer; //??
}
int ReadMemoryFloat(HANDLE processHandle, LPCVOID address) {
//LPVOID buffer = ??;
//SIZE_T size = ??;
SIZE_T NumberOfBytesToRead = 8; //??
ReadProcessMemory(processHandle, address, buffer, size, NumberOfBytesToRead)
return buffer; //??
}
int ReadMemoryString(HANDLE processHandle, LPCVOID address) {
//LPVOID buffer = ??;
//SIZE_T size = ??;
SIZE_T NumberOfBytesToRead = 999; //??
ReadProcessMemory(processHandle, address, buffer, size, NumberOfBytesToRead)
return buffer; //??
}
int main()
{
//read an integer from "Program.exe"+0x05D8A3C4
int address = 0x05D8A3C4;
char* processName = "Program.exe";
int processId = GetProcessId(processName);
HANDLE processHandle = OpenProcess(PROCESS_ALL_ACCESS, false, processId);
int processBaseAddress = GetModuleBase(processHandle, (string)"Program.exe";
LPCVOID actualAddress = processBaseAddress+address;
int readValue = ReadMemory(processHandle, actualAddress);
std::cout << readValue << std::endl;
CloseHandle(processHandle);
return 0;
}
正如您從代碼中的問號所看到的,我真的不確定 ReadProcessMemory 的緩沖區"和大小"參數.如果有人能幫我解決這個問題,我將不勝感激.
As you can see form the question marks in the code I'm really unsure about the "buffer" and "size" parameters of ReadProcessMemory. I'd really appreciate it if someone could help me figuring this out.
推薦答案
以下是 ReadMemoryInt()
函數的示例:
Here is an example for your ReadMemoryInt()
function:
int ReadMemoryInt(HANDLE processHandle, LPCVOID address) {
int buffer = 0;
SIZE_T NumberOfBytesToRead = sizeof(buffer); //this is equal to 4
SIZE_T NumberOfBytesActuallyRead;
BOOL err = ReadProcessMemory(processHandle, address, &buffer, NumberOfBytesToRead, &NumberOfBytesActuallyRead);
if (err || NumberOfBytesActuallyRead != NumberOfBytesToRead)
/*an error occured*/ ;
return buffer;
}
&
表示傳遞的是變量的地址而不是它的值.
The &
mean that the address of the variable is passed instead its value.
而在ReadMemoryString()
中,您無法知道需要讀取的實際大小,您可以讀取一個大塊(大小為 999)或讀取許多小塊,直到得到一個包含
主站蜘蛛池模板:
午夜精品久久久
|
亚洲国产欧美一区二区三区久久
|
国产精品视频免费看
|
91av大全|
国产色婷婷精品综合在线手机播放
|
午夜精品一区二区三区在线视
|
国产欧美精品一区二区三区
|
亚洲人成网亚洲欧洲无码
|
羞羞视频免费在线
|
欧美激情一区二区三级高清视频
|
欧美三级在线
|
国产乱码精品1区2区3区
|
日韩一区二区福利视频
|
国产片侵犯亲女视频播放
|
91精品国产综合久久精品图片
|
国产伦精品一区二区三区四区视频
|
隔壁老王国产在线精品
|
成年人在线视频
|
午夜影院在线观看
|
国产美女永久免费无遮挡
|
九九热在线视频
|
国产午夜精品一区二区三区嫩草
|
日韩视频三区
|
奇米av|
伊人网站在线观看
|
久久6视频
|
新超碰97
|
粉嫩一区二区三区性色av
|
久久三区|
aaaaaaa片毛片免费观看
|
国产第一区二区
|
国产精品久久久久久久久久久久午夜片
|
欧美在线视频网
|
亚洲精品一区二区三区在线观看
|
一级毛片免费
|
国产一级片免费看
|
美女久久久久久久久
|
午夜视频一区二区
|
成人午夜视频在线观看
|
久久精品视频网站
|
欧美黑人一区
|