コード例 #1
0
ファイル: RemoteProcess.cs プロジェクト: mkbiltek2019/StUtil
        private IntPtr LoadDotNetModuleImpl(string path, string typeName, string method, string args)
        {
            bool   x64  = Process.Is64Bit();
            string file = null;

            //Export the bootstrapper
            if (x64)
            {
                file = CreateFile(string.Format(BOOTSTRAP_DLL, "x64"), Properties.Resources.StUtil_Native_Bootstrap_x64);
            }
            else
            {
                file = CreateFile(string.Format(BOOTSTRAP_DLL, "x86"), Properties.Resources.StUtil_Native_Bootstrap_x86);
            }

            if (BootstrapModule == null)
            {
                BootstrapModule = LoadNativeModule(file);
            }
            RemoteMemoryAllocation mPath     = RemoteMemoryAllocation.Allocate(Handle, path, Encoding.Unicode);
            RemoteMemoryAllocation mTypeName = RemoteMemoryAllocation.Allocate(Handle, typeName, Encoding.Unicode);
            RemoteMemoryAllocation mMethod   = RemoteMemoryAllocation.Allocate(Handle, method, Encoding.Unicode);
            RemoteMemoryAllocation mArgs     = RemoteMemoryAllocation.Allocate(Handle, args, Encoding.Unicode);

            try
            {
                CLRINITARGS bootstrap = new CLRINITARGS()
                {
                    args     = mArgs.MemoryAddress,
                    dll      = mPath.MemoryAddress,
                    method   = mMethod.MemoryAddress,
                    typeName = mTypeName.MemoryAddress
                };

                IntPtr v = BootstrapModule.Invoke("CLRBootstrap", bootstrap);
                if (v.ToInt32() < 0)
                {
                    Marshal.ThrowExceptionForHR(v.ToInt32());
                }
                return(v);
            }
            finally
            {
                mPath.Dispose();
                mTypeName.Dispose();
                mMethod.Dispose();
                mArgs.Dispose();
            }
        }
コード例 #2
0
ファイル: RemoteProcess.cs プロジェクト: TGOSeraph/StUtil
        private IntPtr LoadDotNetModuleImpl(string path, string typeName, string method, string args)
        {
            bool x64 = Process.Is64Bit();
            string file = null;
            //Export the bootstrapper
            if (x64)
            {
                file = CreateFile(string.Format(BOOTSTRAP_DLL, "x64"), Properties.Resources.StUtil_Native_Bootstrap_x64);
            }
            else
            {
                file = CreateFile(string.Format(BOOTSTRAP_DLL, "x86"), Properties.Resources.StUtil_Native_Bootstrap_x86);
            }

            if (BootstrapModule == null)
            {
                BootstrapModule = LoadNativeModule(file);
            }
            RemoteMemoryAllocation mPath = RemoteMemoryAllocation.Allocate(Handle, path, Encoding.Unicode);
            RemoteMemoryAllocation mTypeName = RemoteMemoryAllocation.Allocate(Handle,   typeName, Encoding.Unicode);
            RemoteMemoryAllocation mMethod = RemoteMemoryAllocation.Allocate(Handle, method, Encoding.Unicode);
            RemoteMemoryAllocation mArgs = RemoteMemoryAllocation.Allocate(Handle, args, Encoding.Unicode);
            try
            {
                CLRINITARGS bootstrap = new CLRINITARGS()
                {
                    args = mArgs.MemoryAddress,
                    dll = mPath.MemoryAddress,
                    method = mMethod.MemoryAddress,
                    typeName = mTypeName.MemoryAddress
                };

                IntPtr v = BootstrapModule.Invoke("CLRBootstrap", bootstrap);
                if (v.ToInt32() < 0)
                {
                    Marshal.ThrowExceptionForHR(v.ToInt32());
                }
                return v;
            }
            finally
            {
                mPath.Dispose();
                mTypeName.Dispose();
                mMethod.Dispose();
                mArgs.Dispose();
            }
        }