protected override Delegate InitializeDelegate()
        {
            GameSharpProcess process = GameSharpProcess.Instance;
            ModulePointer    ntdll   = process.Modules["ntdll.dll"];
            IMemoryPointer   ntQueryInformationProcessPtr = ntdll.GetProcAddress("NtQueryInformationProcess");

            return(ntQueryInformationProcessPtr.ToDelegate <NtQueryInformationProcessDelegate>());
        }
Beispiel #2
0
        protected override Delegate InitializeDelegate()
        {
            IProcess       process              = GameSharpProcess.Instance;
            ModulePointer  kernel32             = process.Modules["kernel32.dll"];
            IMemoryPointer IsDebuggerPresentPtr = kernel32.GetProcAddress("IsDebuggerPresent");

            return(IsDebuggerPresentPtr.ToDelegate <IsDebuggerPresentDelegate>());
        }
Beispiel #3
0
        protected override Delegate InitializeDelegate()
        {
            GameSharpProcess process = GameSharpProcess.Instance;

            ModulePointer user32dll = process.Modules["user32.dll"];

            IMemoryPointer messageBoxWPtr = user32dll.GetProcAddress("MessageBoxW");

            return(messageBoxWPtr.ToDelegate <MessageBoxWDelegate>());
        }
Beispiel #4
0
        public override Delegate GetHookDelegate()
        {
            GameSharpProcess process = GameSharpProcess.Instance;

            ModulePointer user32dll = process.Modules["user32.dll"];

            IMemoryPointer messageBoxWPtr = user32dll.GetProcAddress("MessageBoxW");

            return(messageBoxWPtr.ToDelegate <HookMessageBoxWDelegate>());
        }
Beispiel #5
0
        private void ValidateDbgBreakPoint()
        {
            ModulePointer ntdll = Process.Modules["ntdll.dll"];

            MemoryPointer dbgBreakPointPtr = ntdll.GetProcAddress("DbgBreakPoint");

            byte dbgBreakPointByte = dbgBreakPointPtr.Read <byte>();

            if (dbgBreakPointByte != 0xCC)
            {
                MemoryPatches.Add(new MemoryPatch(dbgBreakPointPtr, new byte[] { 0xCC }));
            }
        }
Beispiel #6
0
        public ModulePointer LoadLibrary(string pathToDll, bool resolveReferences = true)
        {
            byte[] loadLibraryOpcodes = LoadLibraryHelper.LoadLibraryPayload(pathToDll);

            MemoryPointer allocatedMemory = AllocateManagedMemory(loadLibraryOpcodes.Length);

            if (Kernel32.WriteProcessMemory(Native.Handle, allocatedMemory.Address, loadLibraryOpcodes, loadLibraryOpcodes.Length, out IntPtr _))
            {
                ModulePointer kernel32Module = Modules["kernel32.dll"];
                MemoryPointer loadLibraryAddress;
                if (resolveReferences)
                {
                    loadLibraryAddress = kernel32Module.GetProcAddress("LoadLibraryW");
                }
                else
                {
                    loadLibraryAddress = kernel32Module.GetProcAddress("LoadLibraryExW");
                }

                if (loadLibraryAddress == null)
                {
                    throw new Win32Exception($"Couldn't get proc address, error code: {Marshal.GetLastWin32Error()}.");
                }

                if (Kernel32.CreateRemoteThread(Native.Handle, IntPtr.Zero, 0, loadLibraryAddress.Address, allocatedMemory.Address, 0, IntPtr.Zero) == IntPtr.Zero)
                {
                    throw new Win32Exception($"Couldn't create a remote thread, error code: {Marshal.GetLastWin32Error()}.");
                }
            }

            ModulePointer injectedModule;

            while (!Modules.TryGetValue(Path.GetFileName(pathToDll).ToLower(), out injectedModule))
            {
                Thread.Sleep(1);
            }

            return(injectedModule);
        }