简体   繁体   English

C ++从指针获取地址

[英]C++ Get an address off of a pointer

I'm trying to understand C++ way of Reading/Writing in memory. 我试图理解C ++在内存中读/写的方式。 What I have is, I'm trying to get an address off of a pointer. 我所拥有的是,我正试图从指针中获取一个地址。 I have the pointer which will point to my desired address. 我有指针指向我想要的地址。 Like I have the current address I want to use to read the value, let's say the address is 14C9862 but as every time I run the program again this address changes. 就像我有我想要用来读取值的当前地址一样,假设地址是14C9862但是每次我再次运行程序时这个地址都会改变。 I have the pointer which writes to this address (I'm using cheat engine) and it says the pointer is equal to eax+ePSXE.exe+A82020 as for eax = 77420 and ePSXE.exe = 1718 (ignoring the zeros), so how could I write this in C++ in a way that I can get the ADDRESS every time I run the program again. 我有写入此地址的指针(我正在使用作弊引擎)并且它表示指针等于eax + ePSXE.exe + A82020,eax = 77420ePSXE.exe = 1718 (忽略零),所以我怎么能用C ++写这个,每次我再次运行程序时都可以得到ADDRESS。

Current code: 当前代码:

int readTest {}       
ReadProcessMemory(handle, (LPBYTE*)ePSXe+pointer?, &readTest, sizeof(readTest), 0);
        std::cout << readTest << std::endl;

As I'm thinking now LPBYTE is a pointer to a byte so couldn't it be like (A82020*)???? 正如我现在想的那样,LPBYTE是指向一个字节的指针所以不能像(A82020*)???? I'm just going insane I don't know how to do it. 我只是疯了,我不知道怎么做。

It looks like your target address can be calculated if you know the base address of the ePSXE.exe module. 如果您知道ePSXE.exe模块的基址,则看起来可以计算目标地址。

You could get it with use of the following code: 您可以使用以下代码获取它:

#include <windows.h>
#include <TlHelp32.h> 

DWORD procId = 0;   // <-- Replace with real process ID
MODULEENTRY32 lpModuleEntry = {0};
HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, procId);
if(!hSnapShot)
{
  return NULL;
}

DWORD baseAddress = 0;
lpModuleEntry.dwSize = sizeof(lpModuleEntry);
BOOL bModule = Module32First( hSnapShot, &lpModuleEntry );
while(bModule)
{
  if(!strcmp( lpModuleEntry.szModule, "ePSXE.exe") )
  {
    CloseHandle( hSnapShot );
    baseAddress = reinterpret_cast<DWORD>(lpModuleEntry.modBaseAddr);
  }
  bModule = Module32Next( hSnapShot, &lpModuleEntry );
}
CloseHandle( hSnapShot );

Finally you need to combine static part of address with the module base address: 最后,您需要将地址的静态部分与模块基址相结合:

ReadProcessMemory(handle, reinterpret_cast<LPVOID>(baseAddress + 0xA82020), &readTest, sizeof(readTest), NULL);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM