【发布时间】:2021-12-14 04:20:30
【问题描述】:
我在 python 中有这段代码:
client = pymem.process.module_from_name(pm.process_handle, "client.dll").lpBaseOfDll
我尝试用 C# 重写它。
在 C# 中,我有这个:Magner is a class with imports of user32 and kernel
pHandle = Manager.OpenProcess(Manager.PROCESS_VM_READ | Manager.PROCESS_VM_WRITE | Manager.PROCESS_VM_OPERATION, false, pId);
public static T Read<T>(Int64 address)
{
byte[] Buffer = new byte[Marshal.SizeOf(typeof(T))];
IntPtr ByteRead;
Manager.ReadProcessMemory(pHandle, address, Buffer, (uint)Buffer.Length, out ByteRead);
GCHandle handle = GCHandle.Alloc(Buffer, GCHandleType.Pinned);
T stuff = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T));
handle.Free();
return stuff;
}
磁条码:
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(UInt32 dwAccess, bool inherit, int pid);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool ReadProcessMemory(IntPtr hProcess, Int64 lpBaseAddress, [In, Out] byte[] lpBuffer, UInt64 dwSize, out IntPtr lpNumberOfBytesRead);
// READ FLAGS
public static uint PROCESS_VM_READ = 0x0010;
public static uint PROCESS_VM_WRITE = 0x0020;
public static uint PROCESS_VM_OPERATION = 0x0008;
public static uint PAGE_READWRITE = 0x0004;
问题是,C# 代码适用于正常读数,但在这里我需要按名称获取进程模块。 python 中的代码有效,但我不知道如何在 C# 中进行此操作。过去两周我被困在这里。
编辑:
图片中的这个代码不起作用
【问题讨论】:
-
此图片中的代码不起作用,但对我来说效果很好。那么,如果你运行这段代码,你会得到什么?请注意,字符串比较区分大小写。
-
它返回 process.exe 作为模块之一,但我需要 process.exe 中的 client.dll。我看到的所有代码都使用相同的方式,只是在模块列表中查找“client.dll”,但是当我尝试时它不起作用。区分大小写是正确的
-
client.dll 是 32 位模块吗?如果是在您的 c# 项目属性中选择“首选 32 位”选项。这是 Process.Modules 和 pymem 的 module_from_name 之间的唯一区别,它不会枚举具有不同架构的模块。
标签: c#