Пример #1
0
 public IntPtr Invoke(string method, byte[] args)
 {
     using (RemoteMemoryAllocation mem = RemoteMemoryAllocation.Allocate(Process.Handle, args))
     {
         return(Invoke(method, mem));
     }
 }
Пример #2
0
 public bool Unload()
 {
     return(Process
            .GetModules()
            .First(m => m.Module.FileName.IndexOf("kernel32", StringComparison.InvariantCultureIgnoreCase) > -1)
            .Invoke("FreeLibrary", RemoteMemoryAllocation.Allocate(Process.Handle, BitConverter.GetBytes(BaseAddress.ToInt32()))) != IntPtr.Zero);
 }
Пример #3
0
        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();
            }
        }
Пример #4
0
 public IntPtr Invoke(string method, RemoteMemoryAllocation args)
 {
     return(Invoke(method, args.MemoryAddress));
 }