【发布时间】:2016-01-23 12:49:39
【问题描述】:
我正在为一个游戏编写一个服务器管理器,但遇到了 C# 中的指针和偏移量。旧的服务器管理器是用 vb6 编写的,由于某种原因不能在我的 Windows 上运行,所以我决定用 C# 编写它的一些基本功能。
我有所有必要的指针和偏移值,我现在写的只是为了获取所有玩家的名字。
玩家指针 = 96C290 玩家名称偏移量 = +20
+668 的偏移量给我下一个玩家指针,将 +20 添加到下一个玩家应该给我下一个 玩家名称 等等开。
读取第一个玩家姓名
public static IntPtr BASE_ADDR = new IntPtr(0x96C290);
public static IntPtr OFFSET_NAME = new IntPtr(0x20);
const int PROCESS_WM_READ = 0x0010;
public static void Read()
{
Process process = Process.GetProcessesByName("gameprocessname")[0];
IntPtr processHandle = OpenProcess(PROCESS_WM_READ, false, process.Id);
//defining data structures
int bytesRead = 0;
byte[] buffer = new byte[4];
//Reading Base Address pointer value
ReadProcessMemory((int)processHandle,(int)BASE_ADDR, buffer, 4, ref bytesRead);
IntPtr myBaseAddress = new IntPtr(BitConverter.ToInt32(buffer, 0));
//Adding offset of 20 to original base pointer address
IntPtr namePointer = BASE_ADDR;
namePointer = IntPtr.Add(namePointer,(int)OFFSET_NAME);
//Getting memory address of name pointer
ReadProcessMemory((int)processHandle, (int)namePointer,buffer, 4, ref bytesRead);
IntPtr playerNameAddress = new IntPtr(BitConverter.ToInt32(buffer, 0));
//reading name from name address . ASCII and Unicode
byte[] playerNameBuffer = new byte[256];
ReadProcessMemory((int)processHandle, (int)playerNameAddress, buffer, 256, ref bytesRead);
string name = Encoding.Default.GetString(playerNameBuffer);
MessageBox.Show(name);
}
我没有得到玩家姓名。 VB6 编写的脚本是可操作的。 我正在使用 Win8.1 64bit,游戏是非常老的 32 位应用程序。
可能是什么问题?我使用 cheat engine 手动查看值,但它也没有显示任何内容。指针和偏移值是正确的。
我使用了不同的偏移值,但没有一个返回正确的值。
问题是**如果我在编码端做错了什么?或者是操作系统 64 位问题。 **
【问题讨论】:
标签: c# pointers offset readprocessmemory