示例#1
0
        public static void SendKeyUp(short keyBoardScanCode)
        {
            Thread.Sleep(100);

            NativeImport.SendInput(1, CreateKeyBoardInput(0, keyBoardScanCode, KEYEVENTF_KEYUP),
                                   Marshal.SizeOf(typeof(INPUT)));
        }
示例#2
0
        internal void OnDraw()
        {
            RenderLoop.Run(this, () =>
            {
                if (!ExSharpBase.Events.Drawing.IsMenuBeingDrawn)
                {
                    NativeImport.BringWindowToTop(Handle);
                }

                DrawFactory.device.Clear(ClearFlags.Target, new RawColorBGRA(0, 0, 0, 0),
                                         1.0f, 0);
                DrawFactory.device.SetRenderState(RenderState.ZEnable, false);
                DrawFactory.device.SetRenderState(RenderState.Lighting, false);
                DrawFactory.device.SetRenderState(RenderState.CullMode, Cull.None);
                DrawFactory.device.SetTransform(TransformState.Projection,
                                                Matrix.OrthoOffCenterLH(0, Width, Height, 0, 0, 1));

                DrawFactory.device.BeginScene();

                ExSharpBase.Events.Drawing.OnDeviceDraw();

                DrawFactory.device.EndScene();
                DrawFactory.device.Present();
            });
        }
示例#3
0
        public static void SendKey(short keyBoardScanCode, int keyUporDown)
        {
            Thread.Sleep(100);

            NativeImport.SendInput(1, CreateKeyBoardInput(0, keyBoardScanCode, keyUporDown),
                                   Marshal.SizeOf(typeof(INPUT)));
        }
示例#4
0
        public static void SendVirtualKeyUp(VirtualKeyCodes virtualKeyCode)
        {
            Thread.Sleep(100);

            NativeImport.SendInput(1, CreateKeyBoardInput((short)virtualKeyCode, 0, KEYEVENTF_KEYUP),
                                   Marshal.SizeOf(typeof(INPUT)));
        }
示例#5
0
        internal void OnDraw()
        {
            DateTime lastRender = DateTime.UtcNow;

            RenderLoop.Run(this, () =>
            {
                int elapsedSinceRender = (int)(DateTime.UtcNow - lastRender).TotalMilliseconds;
                System.Threading.Thread.Sleep(Math.Max(0, 1000 / 80 - elapsedSinceRender));
                lastRender = DateTime.UtcNow;

                if (!ExSharpBase.Events.Drawing.IsMenuBeingDrawn)
                {
                    NativeImport.BringWindowToTop(this.Handle);
                }

                DrawFactory.device.Clear(ClearFlags.Target, new SharpDX.Mathematics.Interop.RawColorBGRA(0, 0, 0, 0), 1.0f, 0);
                DrawFactory.device.SetRenderState(RenderState.ZEnable, false);
                DrawFactory.device.SetRenderState(RenderState.Lighting, false);
                DrawFactory.device.SetRenderState(RenderState.CullMode, Cull.None);
                DrawFactory.device.SetTransform(TransformState.Projection, Matrix.OrthoOffCenterLH(0, this.Width, this.Height, 0, 0, 1));

                DrawFactory.device.BeginScene();

                ExSharpBase.Events.Drawing.OnDeviceDraw();

                DrawFactory.device.EndScene();
                DrawFactory.device.Present();
            });
        }
示例#6
0
        static void ProtectionSafeMemoryCopy(IntPtr dest, IntPtr source, int count)
        {
            // UIntPtr = size_t
            var bufferSize = new UIntPtr((uint)count);

            Enums.VirtualProtectionType oldProtection, temp;

            // unprotect memory to copy buffer
            if (!NativeImport.VirtualProtect(dest, bufferSize, Enums.VirtualProtectionType.ExecuteReadWrite, out oldProtection))
            {
                throw new Exception("Failed to unprotect memory.");
            }

            byte *pDest = (byte *)dest;
            byte *pSrc  = (byte *)source;

            // copy buffer to address
            for (int i = 0; i < count; i++)
            {
                *(pDest + i) = *(pSrc + i);
            }

            // protect back
            if (!NativeImport.VirtualProtect(dest, bufferSize, oldProtection, out temp))
            {
                throw new Exception("Failed to protect memory.");
            }
        }
示例#7
0
文件: Base.cs 项目: vnhaxnet/ExCheat
        internal void OnDraw()
        {
            RenderLoop.Run(this, () =>
            {
                if (!ExSharpBase.Events.Drawing.IsMenuBeingDrawn)
                {
                    NativeImport.BringWindowToTop(this.Handle);
                    NativeImport.RECT rct = default;
                    NativeImport.GetWindowRect(Utils.GetPubgWindow(), out rct);
                    if (this.Location != new System.Drawing.Point(rct.Left, rct.Top))
                    {
                        this.Width    = rct.Right - rct.Left;
                        this.Height   = rct.Bottom - rct.Top;
                        this.Location = new System.Drawing.Point(rct.Left, rct.Top);
                    }
                }



                DrawFactory.device.Clear(ClearFlags.Target, new SharpDX.Mathematics.Interop.RawColorBGRA(0, 0, 0, 0), 1.0f, 0);
                DrawFactory.device.SetRenderState(RenderState.ZEnable, false);
                DrawFactory.device.SetRenderState(RenderState.Lighting, false);
                DrawFactory.device.SetRenderState(RenderState.CullMode, Cull.None);
                DrawFactory.device.SetTransform(TransformState.Projection, Matrix.OrthoOffCenterLH(0, this.Width, this.Height, 0, 0, 1));

                DrawFactory.device.BeginScene();

                ExSharpBase.Events.Drawing.OnDeviceDraw();
                DrawFactory.device.EndScene();
                DrawFactory.device.Present();
            });
        }
        public Color[] getColorsAt(Point location, Point size)
        {
            Bitmap screenPixel = new Bitmap(size.X, size.Y, PixelFormat.Format32bppArgb);

            using (Graphics gdest = Graphics.FromImage(screenPixel))
            {
                using (Graphics gsrc = Graphics.FromHwnd(IntPtr.Zero))
                {
                    IntPtr hSrcDC = gsrc.GetHdc();
                    IntPtr hDC    = gdest.GetHdc();
                    int    retval = NativeImport.BitBlt(hDC, 0, 0, (size.X), (size.Y), hSrcDC, location.X - (size.X), location.Y - (size.Y), (int)CopyPixelOperation.SourceCopy);
                    gdest.ReleaseHdc();
                    gsrc.ReleaseHdc();
                }
            }

            List <Color> cols = new List <Color>();

            for (int x = 0; x < screenPixel.Width; x++)
            {
                for (int y = 0; y < screenPixel.Height; y++)
                {
                    cols.Add(screenPixel.GetPixel(x, y));
                }
            }

            return(cols.ToArray());
        }
示例#9
0
        private bool WriteProcessMemory(IntPtr Pointer, byte[] BytesToWrite)
        {
            IntPtr nBytes;

            return(NativeImport.WriteProcessMemory(LoadedProcess.Handle, Pointer, BytesToWrite,
                                                   BytesToWrite.Length, out nBytes));
        }
示例#10
0
        public NativeImport.NativeStructs.RawInput GetRawInputData(IntPtr lParam)
        {
            uint dwSize = 0;

            NativeImport.GetRawInputData(
                lParam,
                RID_INPUT,
                IntPtr.Zero,
                ref dwSize,
                (uint)Marshal.SizeOf(typeof(NativeImport.NativeStructs.RawInputHeader))
                );

            IntPtr buffer = Marshal.AllocHGlobal((int)dwSize);

            NativeImport.GetRawInputData(
                lParam,
                RID_INPUT,
                buffer,
                ref dwSize,
                (uint)Marshal.SizeOf(typeof(NativeImport.NativeStructs.RawInputHeader))
                );

            NativeImport.NativeStructs.RawInput raw = (NativeImport.NativeStructs.RawInput)Marshal.PtrToStructure(buffer, typeof(NativeImport.NativeStructs.RawInput));
            Marshal.FreeHGlobal(buffer);

            return(raw);
        }
示例#11
0
 public void TestMethod1()
 {
     INativeCrypto impl = NativeImport.Create<INativeCrypto>("");
     // Use methods in impl
     int i = impl.NativeMethod();
     //...
 }
示例#12
0
 public static void UninstallHook()
 {
     if (WKBHookInstance != null)
     {
         NativeImport.UnhookWindowsHookEx(WKBHookInstance);
         Logger.Log("Uninstalled Keyboard hook.");
     }
 }
示例#13
0
        private IntPtr CallMethod(IntPtr ptr, IntPtr arg)
        {
            IntPtr hThreadId;
            var    hThread = NativeImport.CreateRemoteThread(LoadedProcess.Handle, IntPtr.Zero, 0,
                                                             ptr, arg, 0, out hThreadId);

            return(hThread);
        }
示例#14
0
 private void TopPanel_MouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         NativeImport.ReleaseCapture();
         NativeImport.SendMessage(Handle, NativeImport.WM_NCLBUTTONDOWN, NativeImport.HTCAPTION, 0);
     }
 }
示例#15
0
        private bool IsDebuggerAttached()
        {
#if DEBUG
            return(false);
#else
            return(NativeImport.IsDebuggerPresent());
#endif
        }
 // Use this for initialization
 void Start()
 {
     target = GetComponent <Text>();
     if (target != null)
     {
         target.text = NativeImport.TestFunc().ToString();
     }
 }
示例#17
0
        public void OnPaint()
        {
            DrawFactory.Marg.Left   = 0;
            DrawFactory.Marg.Top    = 0;
            DrawFactory.Marg.Right  = this.Width;
            DrawFactory.Marg.Bottom = this.Height;

            NativeImport.DwmExtendFrameIntoClientArea(this.Handle, ref DrawFactory.Marg);
        }
示例#18
0
        internal void LoadAndCallMethod(string Library, string MethodName)
        {
            PerformValidationCheck(Library);

            var LoadedLibraryPTR            = Load(Library);
            var LibraryToLoadCurrentProcPTR = NativeImport.LoadLibrary(Library);
            var PTRToMethod = NativeImport.GetProcAddress(LibraryToLoadCurrentProcPTR, MethodName);

            CallMethod(PTRToMethod, IntPtr.Zero);
        }
示例#19
0
        private nint AllocateSinglePageNearAddress(nint targetAddr)
        {
            var sysInfo = new NativeImport.NativeStructs.SYSTEM_INFO();

            NativeImport.GetSystemInfo(ref sysInfo);

            nuint pageSize = sysInfo.dwPageSize;

            nuint startAddr = ((nuint)targetAddr & ~(pageSize - 1));
            nuint minAddr   = (nuint)Math.Min((long)(startAddr - 0x7FFFFF00), sysInfo.lpMinimumApplicationAddress.ToInt64());
            nuint maxAddr   = (nuint)Math.Min((long)(startAddr - 0x7FFFFF00), sysInfo.lpMaximumApplicationAddress.ToInt64());

            nuint startPage = (startAddr - (startAddr % pageSize));

            nuint pageOffset = 1;

            while (true)
            {
                nuint byteOffset = pageOffset * pageSize;
                nuint highAddr   = startPage + byteOffset;
                nuint lowAddr    = (startPage > byteOffset) ? startPage - byteOffset : 0;

                bool needsExit = highAddr > maxAddr && lowAddr < minAddr;

                if (highAddr < maxAddr)
                {
                    IntPtr outAddr = NativeImport.VirtualAlloc((nint)highAddr, pageSize, NativeImport.NativeStructs.AllocationType.Commit | NativeImport.NativeStructs.AllocationType.Reserve,
                                                               NativeImport.NativeStructs.MemoryProtection.ExecuteReadWrite);
                    if (outAddr != IntPtr.Zero)
                    {
                        return(outAddr);
                    }
                }

                if (lowAddr > minAddr)
                {
                    IntPtr outAddr = NativeImport.VirtualAlloc((nint)lowAddr, pageSize, NativeImport.NativeStructs.AllocationType.Commit | NativeImport.NativeStructs.AllocationType.Reserve,
                                                               NativeImport.NativeStructs.MemoryProtection.ExecuteReadWrite);
                    if (outAddr != IntPtr.Zero)
                    {
                        return(outAddr);
                    }
                }

                pageOffset++;

                if (needsExit)
                {
                    break;
                }
            }

            return(0);
        }
        public void ColorMode()
        {
            bool darkMode = Program.tasktraySettingsInstance.darkMode;

            int color = darkMode ? LWA_DARKMODECOLORKEY : LWA_LIGHTMODECOLORKEY;

            NativeImport.SetLayeredWindowAttributes(this.Handle, (uint)color, 1, NativeImport.WindowsStyleModifiers.LWA_ALPHA);

            this.BackColor = darkMode ? Color.FromArgb(1, 2, 3) : Color.FromArgb(255, 254, 253);
            this.Refresh();
        }
示例#21
0
        private int CallLoadLibraryA(IntPtr PointerToArg)
        {
            IntPtr hThreadId;
            var    hThread = NativeImport.CreateRemoteThread(LoadedProcess.Handle, IntPtr.Zero, 0, LoadLibraryPTR, PointerToArg, 0, out hThreadId);

            NativeImport.WaitForSingleObject(hThread, unchecked ((uint)-1));
            uint exitCode;

            NativeImport.GetExitCodeThread(hThread, out exitCode);
            return((int)exitCode);
        }
        public OverlayWindow()
        {
            InitializeComponent();
            this.TopMost         = true;
            this.WindowState     = FormWindowState.Maximized;
            this.FormBorderStyle = FormBorderStyle.None;

            NativeImport.SetWindowLong(this.Handle, NativeImport.WindowsStyleModifiers.GWL_EXSTYLE,
                                       (IntPtr)(NativeImport.GetWindowLong(this.Handle, NativeImport.WindowsStyleModifiers.GWL_EXSTYLE) | NativeImport.WindowsStyleModifiers.WS_EX_LAYERED | NativeImport.WindowsStyleModifiers.WS_EX_TRANSPARENT));
            NativeImport.SetLayeredWindowAttributes(this.Handle, NativeImport.WindowsStyleModifiers.LWA_COLORKEY, 1, NativeImport.WindowsStyleModifiers.LWA_ALPHA);

            this.BackColor = Color.FromArgb(1, 2, 3);
        }
示例#23
0
        internal Loader(string ProcessName)
        {
            try { LoadedProcess = Process.GetProcessesByName(ProcessName).First(); }
            catch (Exception)
            {
                Console.WriteLine($"Could Not Find Process: {ProcessName}");
                Console.Read();
                Environment.Exit(0);
            }

            Kernel32PTR    = NativeImport.LoadLibrary("kernel32");
            LoadLibraryPTR = NativeImport.GetProcAddress(Kernel32PTR, "LoadLibraryA");
        }
示例#24
0
        private void MoveToMouseCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if (MoveToMouseCheckBox.Checked)
            {
                this.Hide();

                NativeImport.SetForegroundWindow(Utils.GetLeagueProcess().MainWindowHandle);

                Thread.Sleep(1000); //Prevents instant IssueOrder when League window isn't active.

                Game.Engine.IssueOrder(Enums.GameObjectOrder.MoveTo);
            }
        }
示例#25
0
        public static void InstallHook()
        {
            if (WinKBHookCallbackDelegate == null && WKBHookInstance == IntPtr.Zero)
            {
                WinKBHookCallbackDelegate = new NativeImport.WindowsHookAdditionals.HookProc(HookedKBWindowsCallback);

                var hinstance = NativeImport.LoadLibrary("User32");

                WKBHookInstance = NativeImport.SetWindowsHookEx(NativeImport.WindowsHookAdditionals.HookType.WH_KEYBOARD_LL, WinKBHookCallbackDelegate, hinstance, 0);

                Logger.Log("Installed Keyboard hook.");
            }
        }
示例#26
0
        public void InstallHooks(IntPtr hwnd)
        {
            winMSHookCallbackDelegate = new NativeImport.WindowsHookAdditionals.HookProc(HookedMSWindowsCallback);
            winKBHookCallbackDelegate = new NativeImport.WindowsHookAdditionals.HookProc(HookedKBWindowsCallback);

            var hinstance = NativeImport.LoadLibrary("User32");

            wMSHookInstance = NativeImport.SetWindowsHookEx(NativeImport.WindowsHookAdditionals.HookType.WH_MOUSE_LL, winMSHookCallbackDelegate, hinstance, 0);
            wKBHookInstance = NativeImport.SetWindowsHookEx(NativeImport.WindowsHookAdditionals.HookType.WH_KEYBOARD_LL, winKBHookCallbackDelegate, hinstance, 0);

            rIUtils = new RawInputUtils(hwnd);

            Console.WriteLine("Installed input hooks");
        }
示例#27
0
        public RawInputUtils(IntPtr hwnd)
        {
            NativeImport.NativeStructs.RAWINPUTDEVICE[] rid = new NativeImport.NativeStructs.RAWINPUTDEVICE[1];

            rid[0].usUsagePage = 0x01;
            rid[0].usUsage     = 0x02;
            rid[0].dwFlags     = RIDEV_INPUTSINK;
            rid[0].hwndTarget  = hwnd;

            if (!NativeImport.RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid[0])))
            {
                throw new ApplicationException("Failed to register raw input device(s).");
            }
        }
示例#28
0
        void InitialiseDesign()
        {
            Color MenuColour       = Color.FromArgb(42, 54, 97);
            Color TransparentColor = Color.FromArgb(0, 255, 255, 255);

            Region = Region.FromHrgn(NativeImport.CreateRoundRectRgn(0, 0, Width, Height, 15, 15));

            CloseButton.BackColor = MenuColour;
            CloseButton.FlatAppearance.BorderSize  = 0;
            CloseButton.FlatAppearance.BorderColor = TransparentColor;

            MinimiseButton.BackColor = MenuColour;
            MinimiseButton.FlatAppearance.BorderSize  = 0;
            MinimiseButton.FlatAppearance.BorderColor = TransparentColor;
        }
示例#29
0
        private bool IsLoadedProcessX64()
        {
            if (!Environment.Is64BitOperatingSystem)
            {
                return(false);
            }

            bool isWow64;

            if (!NativeImport.IsWow64Process(LoadedProcess.Handle, out isWow64))
            {
                isWow64 = false;
            }

            return(!isWow64);
        }
示例#30
0
        private static IntPtr HookedKBWindowsCallback(int code, IntPtr wParam, IntPtr lParam)
        {
            if (code >= 0)
            {
                try
                {
                    OnKeyPress(KeyInterop.KeyFromVirtualKey(Marshal.ReadInt32(lParam)), wParam.ToInt32() == NativeImport.WindowsMessagesModifiers.WM_KEYDOWN ? "Down" : "Up");
                }
                catch { }

                return(NativeImport.CallNextHookEx(IntPtr.Zero, code, wParam, lParam));
            }
            else
            {
                return(NativeImport.CallNextHookEx(IntPtr.Zero, code, wParam, lParam));
            }
        }