-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoHotkeyMemoryLib.ahk
172 lines (144 loc) · 3.83 KB
/
AutoHotkeyMemoryLib.ahk
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
if (A_PtrSize != 4)
{
MsgBox, You are not running 32-bit version of Autohotkey L, reinstall correct version. Script will now terminate.
ExitApp
}
GetModuleInfo(ModuleName, PID, byRef mBase="", byRef mSize="")
{
TH32CS_SNAPMODULE := 0x00000008
INVALID_HANDLE_VALUE = -1
VarSetCapacity(me32, 548, 0)
NumPut(548, me32)
snapMod := DllCall("CreateToolhelp32Snapshot", "Uint", TH32CS_SNAPMODULE, "Uint", PID)
If (snapMod = INVALID_HANDLE_VALUE) {
Return 0
}
If (DllCall("Module32First", "Uint", snapMod, "Uint", &me32)){
If StrGet(&me32 + 32, "cp0")=ModuleName
{
mBase:=NumGet(&me32 + 20)
mSize:=NumGet(&me32 + 24)
DllCall("CloseHandle", "UInt", snapMod)
Return
}
while(DllCall("Module32Next", "Uint", snapMod, "UInt", &me32))
{
If StrGet(&me32 + 32, "cp0")=ModuleName
{
mBase:=NumGet(&me32 + 20)
mSize:=NumGet(&me32 + 24)
DllCall("CloseHandle", "UInt", snapMod)
Return
}
}
}
DllCall("CloseHandle", "Uint", snapMod)
}
GetProcessHandle(pid)
{
return DllCall("OpenProcess", "UInt", 0x8|0x10|0x20, "UInt", 0, "UInt", pid, "UInt")
}
ReadMemFloat(ProcessHandle, MADDRESS)
{
if DllCall("ReadProcessMemory","UInt",ProcessHandle,"UInt",MADDRESS,"Float*",MVALUE,"UInt",4,"UInt*",0)!=0
{
return MVALUE
}
}
ReadMemUInt(ProcessHandle, MADDRESS)
{
if DllCall("ReadProcessMemory","UInt",ProcessHandle,"UInt",MADDRESS,"UInt*",MVALUE,"UInt",4,"UInt*",0)!=0
{
return MVALUE
}
}
ReadMemSInt(ProcessHandle, MADDRESS)
{
if DllCall("ReadProcessMemory","UInt",ProcessHandle,"UInt",MADDRESS,"Int*",MVALUE,"UInt",4,"UInt*",0)!=0
{
return MVALUE
}
}
WriteMemUInt(ProcessHandle, MADDRESS, val)
{
DllCall("WriteProcessMemory","UInt",ProcessHandle,"UInt",MADDRESS,"UInt*",val,"UInt",4,"UInt*",0)!=0
}
WriteMemSInt(ProcessHandle, MADDRESS, val)
{
DllCall("WriteProcessMemory","UInt",ProcessHandle,"UInt",MADDRESS,"Int*",val,"UInt",4,"UInt*",0)!=0
}
WriteMemFloat(ProcessHandle, MADDRESS, val)
{
DllCall("WriteProcessMemory","UInt",ProcessHandle,"UInt",MADDRESS,"Float*",val,"UInt",4,"UInt*",0)!=0
}
ReadMemStr(ProcessHandle, MADDRESS, maxlen=255, cp="cp0")
{
VarSetCapacity(MVALUE,maxlen)
if DllCall("ReadProcessMemory","UInt",ProcessHandle,"UInt",MADDRESS,"PTR",&MVALUE,"UInt",maxlen,"UInt*",bytesread)!=0
{
Str:=StrGet(&MVALUE,cp)
VarSetCapacity(MVALUE,0)
return Str
}
VarSetCapacity(MVALUE,0)
}
GetMultilevelPointer(ProcessHandle, PARRAY)
{
if PARRAY._MaxIndex()<2
return
if (DllCall("ReadProcessMemory","UInt",ProcessHandle,"UInt",PARRAY[1],"UInt*",currOffset,"UInt",4,"UInt*",0)!=0)
{
i:=2
while (i<=PARRAY._MaxIndex() && DllCall("ReadProcessMemory","UInt",ProcessHandle,"UInt",currOffset+PARRAY[i],"UInt*",currOffset,"UInt",4,"UInt*",0)!=0)
{
i:=i+1
}
if (i>PARRAY._MaxIndex())
{
return currOffset
}
}
}
AobScan(ProcessHandle,mBase,mSize, ByRef patternArray)
{
if (patternArray._MaxIndex()>mSize)
{
MsgBox, aobscan fail : pattern array is larger than module size
return
}
VarSetCapacity(ClientCodeSegment,mSize)
if (DllCall("ReadProcessMemory","UInt",ProcessHandle,"UInt",mBase,"PTR",&ClientCodeSegment,"UInt",mSize,"UInt*",bytesread)!=0)
{
pLen:=patternArray._MaxIndex()
if (bytesread<>mSize)
{
VarSetCapacity(ClientCodeSegment,0)
MsgBox, aobscan fail : mSize=%mSize% bytesread=%bytesread%
return
}
i:=0
while (i<=mSize-pLen-1)
{
j:=1
while (j<=pLen)
{
if (patternArray[j]="?" || NumGet(ClientCodeSegment, i+j-1, "UChar")=patternArray[j])
{
j:=j+1
}
else
{
break
}
}
if (j>pLen)
{
VarSetCapacity(ClientCodeSegment,0)
return i
}
i:=i+1
}
}
MsgBox, aobscan fail : pattern not found
VarSetCapacity(ClientCodeSegment,0)
}