forked from Ixiko/AHK-libs-and-classes-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcessMem.ahk
77 lines (74 loc) · 1.5 KB
/
ProcessMem.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
getProcessHandle(pid,mode=0x001F0FFF){
return DllCall("OpenProcess",UInt,mode,UInt,0,UInt,pid,UInt)
}
releaseProcessHandle(hProcess){
DllCall("psapi\CloseProcess","Int",hProcess)
}
getPEName(pid){
hModule=0
dwNeed=0
l=0
max:=VarSetCapacity(s,256,0)
hProcess:=getProcessHandle(pid,0x410) ;ぬるいアクセス権でないと拒否られることがある
if(DllCall("psapi\EnumProcessModules","Int",hProcess,"Int*",hModule,"Int",4,"UInt*",dwNeed,"Int")<>0){
l:=DllCall("psapi\GetModuleFileNameExA","Int",hProcess,"Int",hModule,"Str",s,"Int",max,"Int")
}
releaseProcessHandle(hProcess)
return s
}
readProcMem(pid,addr,len){
if(len="Int64"){
type=Int64 *
size=8
}else If len in Int,UInt
{
type=%len% *
size=4
}else If len in Short,UShort
{
type=%len% *
size=2
}else If len in Char,UChar
{
type=%len% *
size=1
}else{
type=Str
size:=VarSetCapacity(s,len)+1
}
hProcess:=getProcessHandle(pid)
DllCall("ReadProcessMemory","Int",hProcess,"Int",addr,type,res,"Int",size,"Int",0)
releaseProcessHandle(hProcess)
return res
}
writeProcMem(pid,addr,val){
StringLen,size,val
if val is integer
{
IfInString,val,0x
{
if(size>10){
type=Int64 *
size=8
}else if(size>6){
type=Int *
size=4
}else if(size>4){
type=Short *
size=2
}else{
type=Char *
size=1
}
}else{
type=Int *
size=4
}
}else{
type=Str
size++
}
hProcess:=getProcessHandle(pid)
DllCall("WriteProcessMemory","Int",hProcess,"Int",addr,type,val,"Int",size,"Int",0)
releaseProcessHandle(hProcess)
}