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.

94 lines
5.1 KiB

3 years ago
11 months ago
3 years ago
3 years ago
3 years ago
2 years ago
1 year ago
3 years ago
3 years ago
11 months ago
3 years ago
11 months ago
3 years ago
11 months 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.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
  33. public static extern int GetCurrentThreadId();
  34. [DllImport("kernel32")]
  35. public static extern int GetShortPathName(string lpszLongPath, string lpszShortPath, int cchBuffer);
  36. [DllImport("kernel32.dll", SetLastError = true)]
  37. public static extern void GetSystemInfo(ref SystemInfo lpSystemInfo);
  38. [DllImport("kernel32.dll")]
  39. public static extern IntPtr MapViewOfFile(IntPtr hFileMappingObject, uint dwDesiredAccess, uint dwFileOffsetHigh, uint dwFileOffsetLow, uint dwNumberOfBytesToMap);
  40. [DllImport("kernel32", BestFitMapping = false, CharSet = CharSet.Auto, SetLastError = true, ThrowOnUnmappableChar = true)]
  41. public static extern int MoveFile([MarshalAs(UnmanagedType.LPTStr)][In] string lpExistingFileName, [MarshalAs(UnmanagedType.LPTStr)][In] string lpNewFileName);
  42. [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
  43. public static extern IntPtr OpenMutex(uint dwDesiredAccess, int bInheritHandle, string lpName);
  44. [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
  45. public static extern int OpenProcess(int dwDesiredAccess, int bInheritHandle, int dwProcessId);
  46. [DllImport("kernel32.dll", EntryPoint = "OpenProcess")]
  47. public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
  48. // BOOL ReadProcessMemory([in] HANDLE hProcess, [in] LPCVOID lpBaseAddress, [out] LPVOID lpBuffer, [in] SIZE_T nSize, [out] SIZE_T *lpNumberOfBytesRead);
  49. [DllImport("kernel32.dll ")]
  50. public static extern bool ReadProcessMemory(IntPtr hProcess, int lpBaseAddress, byte[] lpBuffer, int nSize, out int lpNumberOfBytesRead);
  51. /// <summary>Copies the contents of a source memory block to a destination memory block, and supports overlapping source and destination memory blocks.</summary>
  52. /// <param name="Destination">A pointer to the destination memory block to copy the bytes to.</param>
  53. /// <param name="Source">A pointer to the source memory block to copy the bytes from.</param>
  54. /// <param name="Length">The number of bytes to copy from the source to the destination.</param>
  55. [DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory")]
  56. public static extern void RtlMoveMemory(ref double Destination, int Source, int Length);
  57. [DllImport("kernel32")]
  58. public static extern int Sleep(int millisecond);
  59. /// <summary>撤消文件映像。</summary>
  60. [DllImport("kernel32.dll")]
  61. public static extern bool UnmapViewOfFile(IntPtr lpBaseAddress);
  62. // BOOL WriteProcessMemory([in] HANDLE hProcess, [in] LPVOID lpBaseAddress, [in] LPCVOID lpBuffer, [in] SIZE_T nSize, [out] SIZE_T *lpNumberOfBytesWritten);
  63. [DllImport("kernel32.dll")]
  64. public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, int nSize, out int lpNumberOfBytesWritten);
  65. }
  66. }