Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用具有进程模块基址和偏移量的ReadProcessMemory_C#_Pointers_Memory_Process_Memory Address - Fatal编程技术网

C# 使用具有进程模块基址和偏移量的ReadProcessMemory

C# 使用具有进程模块基址和偏移量的ReadProcessMemory,c#,pointers,memory,process,memory-address,C#,Pointers,Memory,Process,Memory Address,如何使用进程模块的基址和偏移量读取内存?我用以下内容获取了所需模块的基址: Process process = Process.GetProcessesByName("process")[0]; ProcessModule bClient; ProcessModuleCollection bModules = process.Modules; IntPtr processHandle = OpenProcess(0x10, fals

如何使用进程模块的基址和偏移量读取内存?我用以下内容获取了所需模块的基址:

        Process process = Process.GetProcessesByName("process")[0];
        ProcessModule bClient;
        ProcessModuleCollection bModules = process.Modules;
        IntPtr processHandle = OpenProcess(0x10, false, process.Id);
        int firstOffset = 0xA4C58C;
        int anotherOffset = 0xFC;

        for (int i = 0; i < bModules.Count; i++)
        {
            bClient = bModules[i];
            if (bClient.ModuleName == "module.dll")
            {
                IntPtr baseAddress = bClient.BaseAddress;
                Console.WriteLine("Base address: " + baseAddress);
            }
        }
这给了我一个指针;在这种情况下为440911244

例如,我可以在作弊引擎中使用此指针来浏览其内存区域,并找到另一个指针所指向的值,但我没有找到将偏移量添加到
第一个指针的正确方法

我的问题是,我是否必须在向指针添加另一个偏移量之前使用ReadProcessMemory?如果是,在这种情况下,正确的使用方法是什么

[DllImport("kernel32.dll", SetLastError = true)]
static extern bool ReadProcessMemory(
IntPtr hProcess, 
IntPtr lpBaseAddress,
IntPtr lpBuffer, 
int dwSize, 
out IntPtr lpNumberOfBytesRead);

将ReadProcessMemory lpBuffer参数更改为:

byte[] lpBuffer,
然后


将ReadProcessMemory lpBuffer参数更改为:

byte[] lpBuffer,
然后


什么是“另一个偏移”?您希望从进程的内存中读取什么?@krzysztoffraca firstOffset指向一个特定的内存区域,在那里,另一个offset指向我需要读取的“float”。什么是“另一个offset”?您希望从进程的内存中读取什么?@krzysztoffraca firstOffset指向一个特定的内存区域,在那里,另一个offset指向我需要读取的“float”。谢谢您的回答。但我认为它不起作用;仅仅将偏移量添加到基址似乎指向了错误的位置。是否可以向基址添加int类型偏移量(十六进制)?编辑:似乎只向基址添加一个偏移量(firstOffset),读取内存就会得到正确的“临时地址”。从那里我需要进一步查找最终的浮点。我已经更新了答案,对错误表示歉意。谢谢你的回答。但我认为它不起作用;仅仅将偏移量添加到基址似乎指向了错误的位置。是否可以向基址添加int类型偏移量(十六进制)?编辑:似乎只向基址添加一个偏移量(firstOffset),读取内存就会得到正确的“临时地址”。从那里我需要进一步寻找最终的浮动。我已经更新了答案,为错误道歉。
byte[] buffer = new byte[sizeof(float)];
IntPtr bytesRead = IntPtr.Zero;

IntPtr readAddress = IntPtr.Add(baseAddress, firstOffset);
readAddress = IntPtr.Add(readAddress, anotherOffset)

ReadProcessMemory(processHandle, readAddress, buffer, buffer.Length, out bytesRead);

float value = BitConverter.ToSingle(buffer, 0);