从资源中注入一个 dll/library 模块

问题描述

所以我想将一个dll文件注入另一个进程,我使用这个方法

            public static void InjectPlugin(string pluginPath,IntPtr processHandle,IntPtr loadLibraryW)
    {
        IntPtr ptr = Kernel32.VirtualAllocEx(processHandle,IntPtr.Zero,(uint)(pluginPath.Length + 1) * 2U,Kernel32.AllocationType.Reserve | Kernel32.AllocationType.Commit,Kernel32.MemoryProtection.ReadWrite);
        if (ptr != IntPtr.Zero)
        {
            int nobw = 0;
            byte[] p = Encoding.Unicode.GetBytes(pluginPath);
            byte[] nt = Encoding.Unicode.GetBytes("\0");
            if (Kernel32.WriteProcessMemory(processHandle,ptr,p,(uint)(p.Length),out nobw) && Kernel32.WriteProcessMemory(processHandle,new IntPtr(ptr.ToInt64() + p.LongLength),nt,(uint)(nt.Length),out nobw))
            {
                uint tid = 0U;
                IntPtr rt = Kernel32.CreateRemoteThread(processHandle,0U,loadLibraryW,/* CREATE_SUSPENDED */ 0x4,out tid);
                if (rt != IntPtr.Zero)
                {
                    Kernel32.ResumeThread(rt);
                    unchecked
                    {
                        Kernel32.WaitForSingleObject(rt,(uint)(System.Threading.Timeout.Infinite));
                    }
                }
            }
            Kernel32.VirtualFreeEx(processHandle,Kernel32.AllocationType.Release);
        }
    }

问题是我想从我的项目解决方案中的文件加载 dll,我的意思是像嵌入资源一样,我不想在应用程序所在的任何文件夹中共享 dll 文件,我该怎么做?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)