-
Notifications
You must be signed in to change notification settings - Fork 0
/
objbase.au3
246 lines (222 loc) · 9.67 KB
/
objbase.au3
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
Global Const $OLE32 = DllOpen("ole32.dll")
; Prog@ndy
Func MAKE_HRESULT($sev,$fac,$code)
Return BitOR(BitShift($sev,-31) , BitOR(BitShift($fac,-16), $code))
EndFunc
Global Const $CLSCTX_INPROC_SERVER = 1
Global Const $CLSCTX_LOCAL_SERVER = 4
Global Const $CLSCTX_SERVER = BitOR($CLSCTX_INPROC_SERVER , $CLSCTX_LOCAL_SERVER)
Global Const $HRESULT = "lresult"
Global Const $S_OK = 0
Global Const $E_NOINTERFACE = 0x80004002
Global Const $E_ABORT = 0x80004004
Global Const $E_ACCESSDENIED = 0x80070005
Global Const $E_FAIL = 0x80004005
;~ Global Const $E_INVALIDARG = 0x80070057
Global Const $E_HANDLE = 0x80070006
Global Const $E_NOTIMPL = 0x80004001
Global Const $E_OUTOFMEMORY = 0x8007000E
Global Const $E_PENDING = 0x8000000A
Global Const $E_POINTER = 0x80004003
Global Const $E_UNEXPECTED = 0x8000FFFF
Global Const $OLE_E_ADVF = 0x80040001
Global Const $OLE_E_ADVISENOTSUPPORTED = 0x80040003
Global Const $OLE_E_BLANK = 0x80040007
Global Const $OLE_E_CANT_BINDTOSOURCE = 0x8004000A
Global Const $OLE_E_CANT_GETMONIKER = 0x80040009
Global Const $OLE_E_CANTCONVERT = 0x80040011
Global Const $OLE_E_CLASSDIFF = 0x80040008
Global Const $OLE_E_ENUM_NOMORE = 0x80040002
Global Const $OLE_E_FIRST = 0x80040000
Global Const $OLE_E_INVALIDHWND = 0x8004000F
Global Const $OLE_E_INVALIDRECT = 0x8004000D
Global Const $OLE_E_LAST = 0x800400FF
Global Const $OLE_E_NOCACHE = 0x80040006
Global Const $OLE_E_NOCONNECTION = 0x80040004
Global Const $OLE_E_NOSTORAGE = 0x80040012
Global Const $OLE_E_NOT_INPLACEACTIVE = 0x80040010
Global Const $OLE_E_NOTRUNNING = 0x80040005
Global Const $OLE_E_OLEVERB = 0x80040000
Global Const $OLE_E_PROMPTSAVECANCELLED = 0x8004000C
Global Const $OLE_E_STATIC = 0x8004000B
Global Const $OLE_E_WRONGCOMPOBJ = 0x8004000E
Global $IID_IUnknown = _GUID("{00000000-0000-0000-C000-000000000046}")
Global Const $tagIID = "DWORD Data1; ushort Data2; ushort Data3; BYTE Data4[8];"
; Prog@ndy
Func _GUID($IID)
$IID = StringRegExpReplace($IID,"([}{])","")
$IID = StringSplit($IID,"-")
Local $_GUID = "DWORD Data1; ushort Data2; ushort Data3; BYTE Data4[8];"
Local $GUID = DllStructCreate($_GUID)
If $IID[0] = 5 Then $IID[4] &= $IID[5]
If $IID[0] > 5 Or $IID[0] < 4 Then Return SetError(1,0,0)
DllStructSetData($GUID,1,Dec($IID[1]))
DllStructSetData($GUID,2,Dec($IID[2]))
DllStructSetData($GUID,3,Dec($IID[3]))
DllStructSetData($GUID,4,Binary("0x"&$IID[4]))
Return $GUID
EndFunc
; Prog@ndy
; compares two GUID / IID DLLStructs
Func _GUID_Compare(ByRef $IID1, ByRef $IID2)
Local $a,$b
For $i = 1 To 4
$a = DllStructGetData($IID1,$i)
If @error Then Return SetError(1,0,0)
$b = DllStructGetData($IID2,$i)
If @error Then Return SetError(1,0,0)
If $a <> $b Then Return 0
Next
Return 1
EndFunc
; The IUnknown-Interface
; description: http://www.reactos.org/generated/doxygen/d8/de9/interfaceIUnknown.html
Global Const $IUnknown = "ptr IUnknown;"
Global Const $IUnknown_vTable = "ptr QueryInterface; ptr AddRef; ptr Release;"
;~ /*** IUnknown methods ***/
;~ STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
; Prog@ndy
Func _IUnknown_QueryInterface(ByRef $ObjArr, ByRef $REFIID)
Local $ret = _ObjFuncCall($HRESULT, $ObjArr, "QueryInterface", "ptr", DllStructGetPtr($REFIID), "ptr*", 0)
If @error Then Return SetError(1,0,0)
Return SetError($ret[0],0,$ret[3])
EndFunc
; Prog@ndy
Func _IUnknown_AddRef(ByRef $ObjArr)
Local $ret = _ObjFuncCall("ULONG", $ObjArr, "AddRef")
If @error Then Return SetError(1,0,0)
Return SetError($ret[0]<1,0,$ret[0])
EndFunc
; Prog@ndy
Func _IUnknown_Release(ByRef $ObjArr)
Local $ret = _ObjFuncCall("ULONG", $ObjArr, "Release")
If @error Then Return SetError(1,0,0)
Return SetError($ret[0],0,$ret[0]=0)
EndFunc
; -- #Region MemoryCalls -----------------------------------
#Region Call ObjectFuncs
; _ObjFunc.. are the MemoryFunc... functions from http://www.autoitscript.com/forum/index.php?showtopic=77463
;~ Global $__COMFN_HookPtr, $__COMFN_HookBak, $__COMFN_HookApi = "LocalFlags", $__COMFN_Kernel32Dll = DllOpen("kernel32.dll")
Global $__COMFN_HookPtr, $__COMFN_HookBak, $__COMFN_HookApi = "LocalCompact", $__COMFN_Kernel32Dll = DllOpen("kernel32.dll")
; by Ward
Func _ObjFuncInit()
Local $KernelHandle = DllCall($__COMFN_Kernel32Dll, "ptr", "LoadLibrary", "str", "kernel32.dll")
Local $HookPtr = DllCall($__COMFN_Kernel32Dll, "ptr", "GetProcAddress", "ptr", $KernelHandle[0], "str", $__COMFN_HookApi)
$__COMFN_HookPtr = $HookPtr[0]
$__COMFN_HookBak = DllStructCreate("ubyte[7]")
DllCall($__COMFN_Kernel32Dll, "int", "WriteProcessMemory", "ptr", -1, "ptr", DllStructGetPtr($__COMFN_HookBak), "ptr", $__COMFN_HookPtr, "uint", 7, "uint*", 0)
DllCall($__COMFN_Kernel32Dll, "int", "WriteProcessMemory", "ptr", -1, "ptr", $__COMFN_HookPtr, "byte*", 0xB8, "uint", 1, "uint*", 0)
DllCall($__COMFN_Kernel32Dll, "int", "WriteProcessMemory", "ptr", -1, "ptr", $__COMFN_HookPtr + 5, "ushort*", 0xE0FF, "uint", 2, "uint*", 0)
EndFunc
; by Ward
; modified by Prog@ndy
; Return array: [0] - result
; [1] - Object Pointer
; [2] - first parameter
; [n+1] - n-th Parameter
Func _ObjFuncCall($RetType, ByRef $ObjArr, $sFuncName, $Type1 = "", $Param1 = 0, $Type2 = "", $Param2 = 0, $Type3 = "", $Param3 = 0, $Type4 = "", $Param4 = 0, $Type5 = "", $Param5 = 0, $Type6 = "", $Param6 = 0, $Type7 = "", $Param7 = 0, $Type8 = "", $Param8 = 0, $Type9 = "", $Param9 = 0, $Type10 = "", $Param10 = 0, $Type11 = "", $Param11 = 0, $Type12 = "", $Param12 = 0, $Type13 = "", $Param13 = 0, $Type14 = "", $Param14 = 0, $Type15 = "", $Param15 = 0, $Type16 = "", $Param16 = 0, $Type17 = "", $Param17 = 0, $Type18 = "", $Param18 = 0, $Type19 = "", $Param19 = 0, $Type20 = "", $Param20 = 0)
If Not IsDllStruct($__COMFN_HookBak) Then _ObjFuncInit()
Local $Address = _ObjGetFuncPtr($ObjArr,$sFuncName)
If @error Then Return SetError(1,-1,0)
If $Address = 0 Then Return SetError(3,-1,0)
_ObjFuncSet($Address)
Local $Ret
Switch @NumParams
Case 3
$Ret = DllCall($__COMFN_Kernel32Dll, $RetType, $__COMFN_HookApi, "ptr", $ObjArr[0])
Case 5
$Ret = DllCall($__COMFN_Kernel32Dll, $RetType, $__COMFN_HookApi, "ptr", $ObjArr[0], $Type1, $Param1)
Case 7
$Ret = DllCall($__COMFN_Kernel32Dll, $RetType, $__COMFN_HookApi, "ptr", $ObjArr[0], $Type1, $Param1, $Type2, $Param2)
Case 9
$Ret = DllCall($__COMFN_Kernel32Dll, $RetType, $__COMFN_HookApi, "ptr", $ObjArr[0], $Type1, $Param1, $Type2, $Param2, $Type3, $Param3)
Case 11
$Ret = DllCall($__COMFN_Kernel32Dll, $RetType, $__COMFN_HookApi, "ptr", $ObjArr[0], $Type1, $Param1, $Type2, $Param2, $Type3, $Param3, $Type4, $Param4)
Case 13
$Ret = DllCall($__COMFN_Kernel32Dll, $RetType, $__COMFN_HookApi, "ptr", $ObjArr[0], $Type1, $Param1, $Type2, $Param2, $Type3, $Param3, $Type4, $Param4, $Type5, $Param5)
Case Else
If Mod(@NumParams,2)=0 Then Return SetError(2,-1,0)
Local $DllCallStr = 'DllCall($__COMFN_Kernel32Dll, $RetType, $__COMFN_HookApi, "ptr", $ObjArr[0]', $n, $i
For $i = 5 To @NumParams Step 2
$n = ($i - 3) / 2
$DllCallStr &= ', $Type' & $n & ', $Param' & $n
Next
$DllCallStr &= ')'
$Ret = Execute($DllCallStr)
EndSwitch
SetError(@error,@extended)
Return $Ret
EndFunc
; by Ward
Func _ObjFuncSet($Address)
DllCall($__COMFN_Kernel32Dll, "int", "WriteProcessMemory", "ptr", -1, "ptr", $__COMFN_HookPtr + 1, "uint*", $Address, "uint", 4, "uint*", 0)
EndFunc
; by Ward
Func _ObjFuncExit()
DllCall($__COMFN_Kernel32Dll, "int", "WriteProcessMemory", "ptr", -1, "ptr", $__COMFN_HookPtr, "ptr", DllStructGetPtr($__COMFN_HookBak), "uint", 7, "uint*", 0)
$__COMFN_HookBak = 0
EndFunc
#EndRegion
; -- #EndRedion MemoryCalls -----------------------------------
; Prog@ndy
Func _ObjCreateFromPtr($ObjPointer, $vTable)
If Not $ObjPointer Then Return SetError(1,0,0)
Local $object[3] = [$ObjPointer]
$object[1] = DllStructCreate("ptr lpvTable",Ptr($object[0]))
If @error Then Return SetError(2,0 ,0)
$object[2] = DllStructCreate($vTable,DllStructGetData($object[1],1))
If @error Then Return SetError(3,0,0)
Return $object
EndFunc
; Prog@ndy
Func _ObjCoCreateInstance(ByRef $CLSID,ByRef $IID,$ObjvTable)
;~ Local $ret = DllCall($OLE32,"long_ptr","CoCreateInstance","ptr",DllStructGetPtr($CLSID),"ptr",0,"dword",$CLSCTX_SERVER, "ptr",DllStructGetPtr($IID),"ptr*",0)
Local $ret = DllCall($OLE32,"long_ptr","CoCreateInstance","ptr",DllStructGetPtr($CLSID),"ptr",0,"dword",$CLSCTX_INPROC_SERVER, "ptr",DllStructGetPtr($IID),"ptr*",0)
Local $object[3] = [$ret[5],0,0]
; get the interface
$object[1] = DllStructCreate("ptr lpvTable",$object[0])
$object[2] = DllStructCreate($ObjvTable,DllStructGetData($object[1],1))
Return $object
EndFunc
; Prog@ndy
Func _ObjCoInitialize()
Local $result = DllCall($OLE32,$HRESULT,"CoInitialize","ptr",0)
Return $result[0]
EndFunc
; Prog@ndy
Func _ObjCoUninitialize()
Local $result = DllCall($OLE32,$HRESULT,"CoUninitialize")
Return $result[0]
EndFunc
; Prog@ndy
Func _ObjGetFuncPtr(ByRef $ObjArr, $FuncName)
If UBound($ObjArr)<>3 Then Return SetError(1,0,0)
Return DllStructGetData($ObjArr[2],$FuncName)
EndFunc
; Prog@ndy
Func _ObjGetObjPtr(ByRef $ObjArr)
If UBound($ObjArr)<>3 Then Return SetError(1,0,0)
If DllStructGetData($ObjArr[1],1)=0 Then Return SetError(2,0,0)
Return $ObjArr[0]
EndFunc
; Prog@ndy
Func _OLEInitialize()
Local $result = DllCall($OLE32,$HRESULT,"OleInitialize","ptr",0)
Return $result[0]
EndFunc
; Prog@ndy
Func _OLEUnInitialize()
Local $result = DllCall($OLE32,$HRESULT,"OleUninitialize")
Return $result[0]
EndFunc
Func _CoTaskMemAlloc($iSize)
Local $result = DllCall($OLE32, "ptr", "CoTaskMemAlloc", "ulong", $iSize)
Return $result[0]
EndFunc
Func _CoTaskMemFree($pMem)
DllCall($OLE32, "none", "CoTaskMemFree", "ptr", $pMem)
EndFunc
Func _CoTaskMemRealloc($pMem, $iSize)
Local $result = DllCall($OLE32, "ptr", "CoTaskMemRealloc", "ptr", $pMem, "ulong", $iSize)
Return $result[0]
EndFunc