|
|
using System; using System.IO; using System.Runtime.InteropServices;
namespace Apewer.Internals.Interop {
[System.Security.SecuritySafeCritical] class Kernel32 {
[DllImport("kernel32.dll", CharSet = CharSet.Auto)] public static extern int CloseHandle(int hObject);
[DllImport("kernel32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool CloseHandle(IntPtr hObject);
[DllImport("kernel32.dll")] public static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess, FileShare dwShareMode, IntPtr securityAttrs, FileMode dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);
[DllImport("kernel32.dll")] public static extern IntPtr CreateFileMapping(IntPtr hFile, IntPtr lpFileMappingAttributes, uint flProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, string lpName);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)] public static extern IntPtr CreateMutex(IntPtr lpMutexAttributes, int bInitialOwner, string lpName);
[DllImport("kernel32.dll")] 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);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)] public static extern int GetExitCodeProcess(int hProcess, out int lpExitCode);
[DllImport("kernel32.dll", SetLastError = true)] public static extern uint GetFileSize(IntPtr hFile, out uint highSize);
[DllImport("kernel32.dll")] private static extern uint GetLastError();
[DllImport("kernel32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] public static extern IntPtr GetModuleHandle(string lpModuleName);
[DllImport("kernel32.dll", ExactSpelling = true)] public static extern IntPtr GetCurrentProcess();
[DllImport("kernel32")] public static extern int GetShortPathName(string lpszLongPath, string lpszShortPath, int cchBuffer);
[DllImport("kernel32.dll", SetLastError = true)] public static extern void GetSystemInfo(ref SystemInfo lpSystemInfo);
[DllImport("kernel32.dll")] public static extern IntPtr MapViewOfFile(IntPtr hFileMappingObject, uint dwDesiredAccess, uint dwFileOffsetHigh, uint dwFileOffsetLow, uint dwNumberOfBytesToMap);
[DllImport("kernel32", BestFitMapping = false, CharSet = CharSet.Auto, SetLastError = true, ThrowOnUnmappableChar = true)] public static extern int MoveFile([MarshalAs(UnmanagedType.LPTStr)][In] string lpExistingFileName, [MarshalAs(UnmanagedType.LPTStr)][In] string lpNewFileName);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)] public static extern IntPtr OpenMutex(uint dwDesiredAccess, int bInheritHandle, string lpName);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)] public static extern int OpenProcess(int dwDesiredAccess, int bInheritHandle, int dwProcessId);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)] public static extern int OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
[DllImport("kernel32.dll")] public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, IntPtr lpBuffer, int nSize, IntPtr lpNumberOfBytesRead);
/// <summary>Copies the contents of a source memory block to a destination memory block, and supports overlapping source and destination memory blocks.</summary>
/// <param name="Destination">A pointer to the destination memory block to copy the bytes to.</param>
/// <param name="Source">A pointer to the source memory block to copy the bytes from.</param>
/// <param name="Length">The number of bytes to copy from the source to the destination.</param>
[DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory")] public static extern void RtlMoveMemory(ref double Destination, int Source, int Length);
[DllImport("kernel32")] public static extern int Sleep(int millisecond);
/// <summary>撤消文件映像。</summary>
[DllImport("kernel32.dll")] public static extern bool UnmapViewOfFile(IntPtr lpBaseAddress);
[DllImportAttribute("kernel32.dll")] public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, int[] lpBuffer, int nSize, IntPtr lpNumberOfBytesWritten);
}
}
|