CGC_Codes

WinAPI

Mar 13th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6.  
  7. namespace SecureDesktop
  8. {
  9.     public class WinAPI
  10.     {
  11.         [DllImport("kernel32.dll", SetLastError = true)]
  12.         [return: MarshalAs(UnmanagedType.Bool)]
  13.         public static extern bool GetExitCodeProcess(IntPtr hProcess, out uint lpExitCode);
  14.  
  15.         [DllImport("user32.dll")]
  16.         public static extern IntPtr CreateDesktop(string lpszDesktop, IntPtr lpszDevice,
  17.         IntPtr pDevmode, int dwFlags, uint dwDesiredAccess, IntPtr lpsa);
  18.  
  19.         [DllImport("user32.dll")]
  20.         public static extern bool SwitchDesktop(IntPtr hDesktop);
  21.  
  22.         [DllImport("user32.dll")]
  23.         public static extern bool CloseDesktop(IntPtr handle);
  24.  
  25.         [DllImport("user32.dll")]
  26.         public static extern bool SetThreadDesktop(IntPtr hDesktop);
  27.  
  28.         [DllImport("user32.dll")]
  29.         public static extern IntPtr GetThreadDesktop(int dwThreadId);
  30.  
  31.         [DllImport("kernel32.dll")]
  32.         public static extern int GetCurrentThreadId();
  33.  
  34.         [DllImport("kernel32.dll", SetLastError = true)]
  35.         public static extern bool CreateProcess(
  36.             string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,
  37.             uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo,
  38.             out PROCESS_INFORMATION lpProcessInformation);
  39.  
  40.         [DllImport("kernel32.dll", SetLastError = true)]
  41.         [return: MarshalAs(UnmanagedType.Bool)]
  42.         public static extern bool TerminateProcess(IntPtr hProcess, uint uExitCode);
  43.  
  44.         public enum DESKTOP_ACCESS : uint
  45.         {
  46.             DESKTOP_NONE = 0,
  47.             DESKTOP_READOBJECTS = 0x0001,
  48.             DESKTOP_CREATEWINDOW = 0x0002,
  49.             DESKTOP_CREATEMENU = 0x0004,
  50.             DESKTOP_HOOKCONTROL = 0x0008,
  51.             DESKTOP_JOURNALRECORD = 0x0010,
  52.             DESKTOP_JOURNALPLAYBACK = 0x0020,
  53.             DESKTOP_ENUMERATE = 0x0040,
  54.             DESKTOP_WRITEOBJECTS = 0x0080,
  55.             DESKTOP_SWITCHDESKTOP = 0x0100,
  56.  
  57.             GENERIC_ALL = (DESKTOP_READOBJECTS | DESKTOP_CREATEWINDOW | DESKTOP_CREATEMENU |
  58.                             DESKTOP_HOOKCONTROL | DESKTOP_JOURNALRECORD | DESKTOP_JOURNALPLAYBACK |
  59.                             DESKTOP_ENUMERATE | DESKTOP_WRITEOBJECTS | DESKTOP_SWITCHDESKTOP),
  60. #if HOOKS_ENABLED
  61.             CUSTOM_SECURE = (DESKTOP_READOBJECTS | DESKTOP_CREATEWINDOW | DESKTOP_CREATEMENU | DESKTOP_HOOKCONTROL | DESKTOP_WRITEOBJECTS | DESKTOP_SWITCHDESKTOP)
  62. #else
  63.             CUSTOM_SECURE = (DESKTOP_READOBJECTS | DESKTOP_CREATEWINDOW | DESKTOP_CREATEMENU | DESKTOP_WRITEOBJECTS | DESKTOP_SWITCHDESKTOP)
  64. #endif
  65.         }
  66.  
  67.         public struct PROCESS_INFORMATION
  68.         {
  69.             public IntPtr hProcess;
  70.             public IntPtr hThread;
  71.             public uint dwProcessId;
  72.             public uint dwThreadId;
  73.         }
  74.  
  75.         public struct STARTUPINFO
  76.         {
  77.             public uint cb;
  78.             public string lpReserved;
  79.             public string lpDesktop;
  80.             public string lpTitle;
  81.             public uint dwX;
  82.             public uint dwY;
  83.             public uint dwXSize;
  84.             public uint dwYSize;
  85.             public uint dwXCountChars;
  86.             public uint dwYCountChars;
  87.             public uint dwFillAttribute;
  88.             public uint dwFlags;
  89.             public short wShowWindow;
  90.             public short cbReserved2;
  91.             public IntPtr lpReserved2;
  92.             public IntPtr hStdInput;
  93.             public IntPtr hStdOutput;
  94.             public IntPtr hStdError;
  95.         }
  96.  
  97.         public const int
  98.         ULW_ALPHA = 0x00000002,
  99.         WS_EX_LAYERED = 0x00080000,
  100.         WS_EX_TRANSPARENT = 0x00000020,
  101.         WS_EX_TOOLWINDOW = 0x00000080,
  102.         WS_EX_TOPMOST = 0x00000008;
  103.  
  104.         public const byte AC_SRC_OVER = 0x00;
  105.         public const byte AC_SRC_ALPHA = 0x01;
  106.  
  107.  
  108.         [StructLayout(LayoutKind.Sequential, Pack = 1)]
  109.         struct ARGB
  110.         {
  111.             public byte Blue;
  112.             public byte Green;
  113.             public byte Red;
  114.             public byte Alpha;
  115.         }
  116.  
  117.  
  118.         [StructLayout(LayoutKind.Sequential, Pack = 1)]
  119.         public struct BLENDFUNCTION
  120.         {
  121.             public byte BlendOp;
  122.             public byte BlendFlags;
  123.             public byte SourceConstantAlpha;
  124.             public byte AlphaFormat;
  125.         }
  126.  
  127.  
  128.         [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
  129.         public static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref Point pptDst, ref Size psize, IntPtr hdcSrc, ref Point pprSrc, Int32 crKey, ref BLENDFUNCTION pblend, Int32 dwFlags);
  130.  
  131.         [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
  132.         public static extern IntPtr GetDC(IntPtr hWnd);
  133.  
  134.         [DllImport("user32.dll", ExactSpelling = true)]
  135.         public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
  136.  
  137.         [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
  138.         public static extern IntPtr CreateCompatibleDC(IntPtr hDC);
  139.  
  140.         [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
  141.         public static extern bool DeleteDC(IntPtr hdc);
  142.  
  143.         [DllImport("gdi32.dll", ExactSpelling = true)]
  144.         public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
  145.  
  146.         [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
  147.         public static extern bool DeleteObject(IntPtr hObject);
  148.  
  149.  
  150.         public static IntPtr HWND_TOPMOST = new IntPtr(-1);
  151.         public const int
  152.         SWP_NOSIZE = 0x0001,
  153.         SWP_NOMOVE = 0x0002,
  154.         SWP_SHOWWINDOW = 0x0040;
  155.  
  156.         [DllImport("user32.dll", SetLastError = true)]
  157.         public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);
  158.  
  159.         public enum ShowCommands : int
  160.         {
  161.             SW_HIDE = 0,
  162.             SW_SHOWNORMAL = 1,
  163.             SW_NORMAL = 1,
  164.             SW_SHOWMINIMIZED = 2,
  165.             SW_SHOWMAXIMIZED = 3,
  166.             SW_MAXIMIZE = 3,
  167.             SW_SHOWNOACTIVATE = 4,
  168.             SW_SHOW = 5,
  169.             SW_MINIMIZE = 6,
  170.             SW_SHOWMINNOACTIVE = 7,
  171.             SW_SHOWNA = 8,
  172.             SW_RESTORE = 9,
  173.             SW_SHOWDEFAULT = 10,
  174.             SW_FORCEMINIMIZE = 11,
  175.             SW_MAX = 11
  176.         }
  177.  
  178.         [DllImport("shell32.dll")]
  179.         public static extern IntPtr ShellExecute(
  180.             IntPtr hwnd,
  181.             string lpOperation,
  182.             string lpFile,
  183.             string lpParameters,
  184.             string lpDirectory,
  185.             ShowCommands nShowCmd);
  186.  
  187.         [DllImport("Shlwapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
  188.         public static extern uint AssocQueryString(AssocF flags, AssocStr str, string pszAssoc, string pszExtra, [Out] StringBuilder pszOut, ref uint pcchOut);
  189.  
  190.         [Flags]
  191.         public enum AssocF : uint
  192.         {
  193.             None = 0,
  194.             Init_NoRemapCLSID = 0x1,
  195.             Init_ByExeName = 0x2,
  196.             Open_ByExeName = 0x2,
  197.             Init_DefaultToStar = 0x4,
  198.             Init_DefaultToFolder = 0x8,
  199.             NoUserSettings = 0x10,
  200.             NoTruncate = 0x20,
  201.             Verify = 0x40,
  202.             RemapRunDll = 0x80,
  203.             NoFixUps = 0x100,
  204.             IgnoreBaseClass = 0x200,
  205.             Init_IgnoreUnknown = 0x400,
  206.             Init_FixedProgId = 0x800,
  207.             IsProtocol = 0x1000,
  208.             InitForFile = 0x2000,
  209.         }
  210.  
  211.         public enum AssocStr
  212.         {
  213.             Command = 1,
  214.             Executable,
  215.             FriendlyDocName,
  216.             FriendlyAppName,
  217.             NoOpen,
  218.             ShellNewValue,
  219.             DDECommand,
  220.             DDEIfExec,
  221.             DDEApplication,
  222.             DDETopic,
  223.             InfoTip,
  224.             QuickTip,
  225.             TileInfo,
  226.             ContentType,
  227.             DefaultIcon,
  228.             ShellExtension,
  229.             DropTarget,
  230.             DelegateExecute,
  231.             SupportedUriProtocols,
  232.             Max,
  233.         }
  234.  
  235.         public const int S_OK = 0, S_FALSE = 1;
  236.  
  237.         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
  238.         public class MEMORYSTATUSEX
  239.         {
  240.             public uint dwLength;
  241.             public uint dwMemoryLoad;
  242.             public ulong ullTotalPhys;
  243.             public ulong ullAvailPhys;
  244.             public ulong ullTotalPageFile;
  245.             public ulong ullAvailPageFile;
  246.             public ulong ullTotalVirtual;
  247.             public ulong ullAvailVirtual;
  248.             public ulong ullAvailExtendedVirtual;
  249.             public MEMORYSTATUSEX()
  250.             {
  251.                 this.dwLength = (uint)Marshal.SizeOf(typeof(MEMORYSTATUSEX));
  252.             }
  253.         }
  254.  
  255.         [return: MarshalAs(UnmanagedType.Bool)]
  256.         [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  257.         public static extern bool GlobalMemoryStatusEx([In, Out] MEMORYSTATUSEX lpBuffer);
  258.  
  259.         [StructLayout(LayoutKind.Sequential)]
  260.         public struct POINT
  261.         {
  262.             public int X;
  263.             public int Y;
  264.         }
  265.  
  266.         [DllImport("user32.dll")]
  267.         public static extern bool GetCursorPos(out POINT lpPoint);
  268.  
  269.         [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
  270.         public static extern bool GetDiskFreeSpace(string lpRootPathName,
  271.            out uint lpSectorsPerCluster,
  272.            out uint lpBytesPerSector,
  273.            out uint lpNumberOfFreeClusters,
  274.            out uint lpTotalNumberOfClusters);
  275.     }
  276. }
Advertisement
Add Comment
Please, Sign In to add comment