forked from sdyxxjj123/AutoTimeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNativeFunctions.cs
150 lines (137 loc) · 4.77 KB
/
NativeFunctions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using CodeStage.AntiCheat.ObscuredTypes;
namespace PCRAutoTimeline
{
public unsafe class NativeFunctions
{
[DllImport("user32")]
public static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
//移动鼠标
public const int MOUSEEVENTF_MOVE = 0x0001;
//模拟鼠标左键按下
public const int MOUSEEVENTF_LEFTDOWN = 0x0002;
//模拟鼠标左键抬起
public const int MOUSEEVENTF_LEFTUP = 0x0004;
//模拟鼠标右键按下
public const int MOUSEEVENTF_RIGHTDOWN = 0x0008;
//模拟鼠标右键抬起
public const int MOUSEEVENTF_RIGHTUP = 0x0010;
//模拟鼠标中键按下
public const int MOUSEEVENTF_MIDDLEDOWN = 0x0020;
//模拟鼠标中键抬起
public const int MOUSEEVENTF_MIDDLEUP = 0x0040;
//标示是否采用绝对坐标
public const int MOUSEEVENTF_ABSOLUTE = 0x8000;
[DllImport("user32.dll")]
public static extern bool SetCursorPos(int X, int Y);
[DllImport("user32.dll")]
public static extern bool GetCursorPos(out POINT lpPoint);
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int X;
public int Y;
public override string ToString()
{
return (X, Y).ToString();
}
public POINT(int x, int y)
{
this.X = x;
this.Y = y;
}
}
[StructLayout(LayoutKind.Sequential)]
public struct MEMORY_BASIC_INFORMATION
{
public long BaseAddress;
public long AllocationBase;
public int AllocationProtect;
public short PartitionId;
public long RegionSize;
public int State;
public int Protect;
public int Type;
}
public const int MEMORY_BASIC_INFORMATION_SIZE = 48;
public enum AllocationProtect : uint
{
PAGE_EXECUTE = 0x00000010,
PAGE_EXECUTE_READ = 0x00000020,
PAGE_EXECUTE_READWRITE = 0x00000040,
PAGE_EXECUTE_WRITECOPY = 0x00000080,
PAGE_NOACCESS = 0x00000001,
PAGE_READONLY = 0x00000002,
PAGE_READWRITE = 0x00000004,
PAGE_WRITECOPY = 0x00000008,
PAGE_GUARD = 0x00000100,
PAGE_NOCACHE = 0x00000200,
PAGE_WRITECOMBINE = 0x00000400
}
public enum AllocationType
{
Commit = 0x1000,
Reserve = 0x2000,
Decommit = 0x4000,
Release = 0x8000,
Reset = 0x80000,
Physical = 0x400000,
TopDown = 0x100000,
WriteWatch = 0x200000,
LargePages = 0x20000000
}
public enum MemoryProtection
{
Execute = 0x10,
ExecuteRead = 0x20,
ExecuteReadWrite = 0x40,
ExecuteWriteCopy = 0x80,
NoAccess = 0x01,
ReadOnly = 0x02,
ReadWrite = 0x04,
WriteCopy = 0x08,
GuardModifierflag = 0x100,
NoCacheModifierflag = 0x200,
WriteCombineModifierflag = 0x400
}
[DllImport("kernel32.dll")]
public static extern bool ReadProcessMemory
(
long lpProcess,
long lpBaseAddress,
byte[] lpBuffer,
long nSize,
int BytesRead
);
[DllImport("kernel32.dll")]
public static extern bool ReadProcessMemory
(
long lpProcess,
long lpBaseAddress,
void *lpBuffer,
long nSize,
int BytesRead
);
[DllImport("kernel32.dll")]
public static extern int VirtualQueryEx
(
long hProcess,
long lpAddress,
out MEMORY_BASIC_INFORMATION lpBuffer,
int dwLength
);
public static bool ReadProcessMemory<T>(long hProcess, long lpAddress, out T lpBuffer) where T : unmanaged
{
fixed (T *ptr = &lpBuffer)
return ReadProcessMemory(hProcess, lpAddress, ptr, Marshal.SizeOf<T>(), 0);
}
[DllImport("kernel32.dll")]
public static extern int OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
[DllImport("kernel32.dll")]
public static extern int CloseHandle(int dwHandle);
public const int PROCESS_ALL_ACCESS = 0x1F0FFF;
}
}