mirror of
https://github.com/HolographicHat/Yae.git
synced 2025-12-16 19:38:13 +08:00
117 lines
4.2 KiB
C#
117 lines
4.2 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using System.Runtime.InteropServices;
|
|
using System.Security;
|
|
|
|
namespace YaeAchievement.Win32;
|
|
|
|
[SuppressMessage("Interoperability", "CA1401:P/Invokes 应该是不可见的")]
|
|
public static class Native {
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
|
public static extern bool CreateProcess(
|
|
string lpApplicationName,
|
|
string? lpCommandLine,
|
|
ref SecurityAttributes lpProcessAttributes,
|
|
ref SecurityAttributes lpThreadAttributes,
|
|
bool bInheritHandles,
|
|
CreationFlags dwCreationFlags,
|
|
IntPtr lpEnvironment,
|
|
string? lpCurrentDirectory,
|
|
[In] ref StartupInfo lpStartupInfo,
|
|
out ProcessInformation lpProcessInformation
|
|
);
|
|
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
[DllImport("kernel32.dll", SetLastError = true)]
|
|
public static extern bool TerminateProcess(IntPtr hProcess, uint uExitCode);
|
|
|
|
[DllImport("kernel32.dll")]
|
|
public static extern bool WriteProcessMemory(
|
|
IntPtr hProcess,
|
|
IntPtr lpBaseAddress,
|
|
char[] lpBuffer,
|
|
int nSize,
|
|
out IntPtr lpNumberOfBytesWritten
|
|
);
|
|
|
|
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
public static extern IntPtr GetModuleHandle(string lpModuleName);
|
|
|
|
[DllImport("kernel32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
|
|
[SuppressMessage("Globalization", "CA2101:指定对 P/Invoke 字符串参数进行封送处理")]
|
|
public static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
|
|
public static extern IntPtr VirtualAllocEx(
|
|
IntPtr hProcess,
|
|
IntPtr lpAddress,
|
|
int dwSize,
|
|
AllocationType flAllocationType,
|
|
MemoryProtection flProtect
|
|
);
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
|
|
public static extern bool VirtualFreeEx(IntPtr hProcess, IntPtr lpAddress, int dwSize, AllocationType dwFreeType);
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true)]
|
|
public static extern uint ResumeThread(IntPtr hThread);
|
|
|
|
[SuppressUnmanagedCodeSecurity]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
[DllImport("kernel32.dll", SetLastError = true)]
|
|
public static extern bool CloseHandle(IntPtr hObject);
|
|
|
|
[DllImport("kernel32.dll")]
|
|
public static extern IntPtr CreateRemoteThread(
|
|
IntPtr hProcess,
|
|
IntPtr lpThreadAttributes,
|
|
int dwStackSize,
|
|
IntPtr lpStartAddress,
|
|
IntPtr lpParameter,
|
|
uint dwCreationFlags,
|
|
out IntPtr lpThreadId
|
|
);
|
|
|
|
[DllImport("kernel32.dll")]
|
|
public static extern IntPtr GetConsoleWindow();
|
|
|
|
// ReSharper disable once InconsistentNaming
|
|
private const int STD_INPUT_HANDLE = -10;
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true)]
|
|
public static extern IntPtr GetStdHandle(int nStdHandle = STD_INPUT_HANDLE);
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true)]
|
|
public static extern bool GetConsoleMode(IntPtr handle, out int lpMode);
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true)]
|
|
public static extern bool SetConsoleMode(IntPtr handle, int ioMode);
|
|
|
|
[DllImport("comdlg32.dll", SetLastError = true)]
|
|
public static extern int CommDlgExtendedError();
|
|
|
|
[DllImport("comdlg32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
|
public static extern bool GetOpenFileName([In, Out] OpenFileName ofn);
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true)]
|
|
public static extern IntPtr GlobalLock(IntPtr mem);
|
|
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
[DllImport("kernel32.dll", SetLastError = true)]
|
|
public static extern bool GlobalUnlock(IntPtr mem);
|
|
|
|
[DllImport("user32.dll", SetLastError = true)]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
public static extern bool OpenClipboard(IntPtr owner);
|
|
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
[DllImport("user32.dll", SetLastError = true)]
|
|
public static extern bool CloseClipboard();
|
|
|
|
[DllImport("user32.dll", SetLastError = true)]
|
|
public static extern IntPtr SetClipboardData(uint uFormat, IntPtr data);
|
|
|
|
[DllImport("user32.dll")]
|
|
public static extern bool EmptyClipboard();
|
|
}
|