1

我有一个将 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。

谢谢!

4

1 回答 1

1

您的注入器、目标进程和 DLL 都必须是 x64。

原因是因为这条线:

GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");

这将返回 x86 LoadLibrary() 的地址而不是 x64 地址。

于 2020-06-01T18:52:05.023 回答