微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决从资源中注入一个 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 举报,一经查实,本站将立刻删除。