[英]C# code to inject 64bit dll to process
我有一個代碼可以將 32 位庫 (C++) 注入外部 32 位進程:
[DllImport("kernel32")]
public static extern IntPtr CreateRemoteThread(
IntPtr hProcess,
IntPtr lpThreadAttributes,
uint dwStackSize,
UIntPtr lpStartAddress, // raw Pointer into remote process
IntPtr lpParameter,
uint dwCreationFlags,
out IntPtr lpThreadId
);
...
public static bool InjectDLL(Process p, string dll)
{
IntPtr bytesout;
Int32 LenWrite = dll.Length + 1;
IntPtr AllocMem = (IntPtr)VirtualAllocEx(p.Handle, (IntPtr)null, (uint)LenWrite, 0x1000, 0x40);
WriteProcessMemory(p.Handle, AllocMem, dll, (UIntPtr)LenWrite, out bytesout);
UIntPtr Injector = (UIntPtr)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
IntPtr hThread = (IntPtr)CreateRemoteThread(p.Handle, (IntPtr)null, 0, Injector, AllocMem, 0, out bytesout);
return true;
}
但是如何修復該代碼以將 64 位庫注入 64 位進程? 上面的代碼不適用於 64 位進程和 dll。
謝謝!
您的injector 、您的目標進程和 DLL 都必須是 x64。
原因是因為這一行:
GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
這將返回 x86 LoadLibrary() 的地址而不是 x64 地址。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.