You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
4.6 KiB

3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. using System;
  2. using System.IO;
  3. using System.Runtime.InteropServices;
  4. namespace Apewer.Internals.Interop
  5. {
  6. [System.Security.SecuritySafeCritical]
  7. class Kernel32
  8. {
  9. [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
  10. public static extern int CloseHandle(int hObject);
  11. [DllImport("kernel32.dll", SetLastError = true)]
  12. [return: MarshalAs(UnmanagedType.Bool)]
  13. public static extern bool CloseHandle(IntPtr hObject);
  14. [DllImport("kernel32.dll")]
  15. public static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess, FileShare dwShareMode, IntPtr securityAttrs, FileMode dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);
  16. [DllImport("kernel32.dll")]
  17. public static extern IntPtr CreateFileMapping(IntPtr hFile, IntPtr lpFileMappingAttributes, uint flProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, string lpName);
  18. [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
  19. public static extern IntPtr CreateMutex(IntPtr lpMutexAttributes, int bInitialOwner, string lpName);
  20. [DllImport("kernel32.dll")]
  21. public static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref StartupInfo lpStartupInfo, ref ProcessInformation lpProcessInformation);
  22. [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
  23. public static extern int GetExitCodeProcess(int hProcess, out int lpExitCode);
  24. [DllImport("kernel32.dll", SetLastError = true)]
  25. public static extern uint GetFileSize(IntPtr hFile, out uint highSize);
  26. [DllImport("kernel32.dll")]
  27. private static extern uint GetLastError();
  28. [DllImport("kernel32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
  29. public static extern IntPtr GetModuleHandle(string lpModuleName);
  30. [DllImport("kernel32.dll", ExactSpelling = true)]
  31. public static extern IntPtr GetCurrentProcess();
  32. [DllImport("kernel32")]
  33. public static extern int GetShortPathName(string lpszLongPath, string lpszShortPath, int cchBuffer);
  34. [DllImport("kernel32.dll", SetLastError = true)]
  35. public static extern void GetSystemInfo(ref SystemInfo lpSystemInfo);
  36. [DllImport("kernel32.dll")]
  37. public static extern IntPtr MapViewOfFile(IntPtr hFileMappingObject, uint dwDesiredAccess, uint dwFileOffsetHigh, uint dwFileOffsetLow, uint dwNumberOfBytesToMap);
  38. [DllImport("kernel32", BestFitMapping = false, CharSet = CharSet.Auto, SetLastError = true, ThrowOnUnmappableChar = true)]
  39. public static extern int MoveFile([MarshalAs(UnmanagedType.LPTStr)][In] string lpExistingFileName, [MarshalAs(UnmanagedType.LPTStr)][In] string lpNewFileName);
  40. [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
  41. public static extern IntPtr OpenMutex(uint dwDesiredAccess, int bInheritHandle, string lpName);
  42. [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
  43. public static extern int OpenProcess(int dwDesiredAccess, int bInheritHandle, int dwProcessId);
  44. [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
  45. public static extern int OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
  46. [DllImport("kernel32.dll")]
  47. public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, IntPtr lpBuffer, int nSize, IntPtr lpNumberOfBytesRead);
  48. /// <summary>Copies the contents of a source memory block to a destination memory block, and supports overlapping source and destination memory blocks.</summary>
  49. /// <param name="Destination">A pointer to the destination memory block to copy the bytes to.</param>
  50. /// <param name="Source">A pointer to the source memory block to copy the bytes from.</param>
  51. /// <param name="Length">The number of bytes to copy from the source to the destination.</param>
  52. [DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory")]
  53. public static extern void RtlMoveMemory(ref double Destination, int Source, int Length);
  54. [DllImport("kernel32")]
  55. public static extern int Sleep(int millisecond);
  56. /// <summary>撤消文件映像。</summary>
  57. [DllImport("kernel32.dll")]
  58. public static extern bool UnmapViewOfFile(IntPtr lpBaseAddress);
  59. [DllImportAttribute("kernel32.dll")]
  60. public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, int[] lpBuffer, int nSize, IntPtr lpNumberOfBytesWritten);
  61. }
  62. }