Advertisement
Guest User

Tools of Exile Working 1.0.2 (non-steam offsets)

a guest
Nov 29th, 2013
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.97 KB | None | 0 0
  1. if FileExists("ExpTrackerConfig.ini") = 0 then
  2. IniWrite("ExpTrackerConfig.ini", "Config", "HotkeyReset", "{F3}")
  3. IniWrite("ExpTrackerConfig.ini", "Config", "HotkeyExit", "{F4}")
  4. IniWrite("ExpTrackerConfig.ini", "Config", "HotkeyToggle", "{F5}")
  5. IniWrite("ExpTrackerConfig.ini", "Config", "DisplayLocationX", "0")
  6. IniWrite("ExpTrackerConfig.ini", "Config", "DisplayLocationY", "0")
  7. EndIf
  8.  
  9. HotKeySet(IniRead("ExpTrackerConfig.ini", "Config", "HotkeyReset", "{F3}"), "Reset")
  10. HotKeySet(IniRead("ExpTrackerConfig.ini", "Config", "HotkeyExit", "{F4}"), "Close")
  11. HotKeySet(IniRead("ExpTrackerConfig.ini", "Config", "HotkeyToggle", "{F5}"), "Toggle")
  12.  
  13. #RequireAdmin
  14. if IsAdmin() = 0 Then
  15. MsgBox(0, "", "You are not running as an administrator! Please right-click this program, then click Run As Administrator.")
  16. Exit
  17. EndIf
  18.  
  19. SetPrivilege("SeDebugPrivilege", 1)
  20.  
  21. $pid = ProcessExists("PathOfExile.exe")
  22.  
  23. if $pid = 0 Then
  24. MsgBox(0, "", "Please run Path of Exile before starting this program.")
  25. Exit
  26. EndIf
  27.  
  28. $handle = _MemoryOpen($pid)
  29. if $handle = 0 Then
  30. MsgBox(0, "", "Unable to open the Path of Exile process to read memory. Please ensure you do not have any software blocking this program from running properly, such as anti-virus software.")
  31. Exit
  32. EndIf
  33.  
  34. $baseaddress = GetBaseAddress($pid)
  35.  
  36. $playerbase = $baseaddress + 0x00785114
  37. $playerbase = _MemoryRead($playerbase, $handle, "dword")
  38.  
  39. local $expMinOffsets[5] = [0x54, 0x508, 0x7C, 0x7C, 0x374]
  40. local $expMaxOffsets[5] = [0x54, 0x508, 0x7C, 0x7C, 0x378]
  41. local $levelOffsets[5] = [0x54, 0x508, 0x7C, 0x7C, 0x37C]
  42.  
  43. $time = TimerInit()
  44. $startExp = ReadPointer($playerbase, $handle, $expMinOffsets)
  45. $curLevel = ReadPointer($playerbase, $handle, $levelOffsets)
  46.  
  47. $dispX = IniRead("ExpTrackerConfig.ini", "Config", "DisplayLocationX", "0")
  48. $dispY = IniRead("ExpTrackerConfig.ini", "Config", "DisplayLocationY", "0")
  49.  
  50. $hidden = 0
  51.  
  52. While 1
  53.  
  54. if $hidden = 1 Then
  55. ToolTip("", 0, 0)
  56. Sleep(10)
  57. ContinueLoop
  58. EndIf
  59.  
  60. If ProcessExists("PathOfExile.exe") = false then
  61. Exit
  62. EndIf
  63.  
  64.  
  65. $expMin = ReadPointer($playerbase, $handle, $expMinOffsets)
  66. $expMax = ReadPointer($playerbase, $handle, $expMaxOffsets)
  67. $level = ReadPointer($playerbase, $handle, $levelOffsets)
  68.  
  69. $expgained = $expMin - $startExp
  70. if $expgained < 0 Then
  71. $expgained = 0
  72. EndIf
  73.  
  74. $expremaining = $expMax - $expMin
  75. $ttl = 0
  76.  
  77. $seconds = TimerDiff($time) / 1000
  78. $minutes = round(floor(mod($seconds / 60, 60)))
  79. $hours = round(floor($seconds / 3600))
  80. $seconds = round(mod($seconds, 60))
  81. $runtime = $hours & ":" & $minutes & ":" & $seconds
  82.  
  83.  
  84. $exphour = 0
  85. if $expgained > 0 then
  86. $runninghours = TimerDiff($time) / (1000 * 60 * 60)
  87. $exphour = round($expgained / $runninghours)
  88. $ttlhours = $expremaining / $exphour
  89. $ttlminutes = $ttlhours * 60
  90. $ttlseconds = $ttlminutes * 60
  91.  
  92.  
  93. $init = $ttlseconds
  94. $hrs = round(floor($init / 3600))
  95. $mins = round(floor(mod(($init / 60), 60)))
  96. $secs = round(mod($init, 60))
  97.  
  98. $ttl = $hrs & ":" & $mins & ":" & $secs
  99.  
  100. if $exphour > 10000 Then
  101. $exphour = round($exphour / 1000)
  102. $exphour = AddCommas($exphour)
  103. $exphour = $exphour & "k"
  104. EndIf
  105.  
  106. endif
  107.  
  108. if $expMin > 10000 then
  109. $expMin = round($expMin / 1000)
  110. $expMin = AddCommas($expMin)
  111. $expMin = $expMin & "k"
  112. EndIf
  113.  
  114. if $expMax > 10000 then
  115. $expMax = round($expMax / 1000)
  116. $expMax = AddCommas($expMax)
  117. $expMax = $expMax & "k"
  118. EndIf
  119.  
  120.  
  121. $disX = 2000
  122. $disY = 5
  123.  
  124. ToolTip("Experience: " & $expMin & " / " & $expMax & @CRLF & "Exp/hr: " & $exphour & @CRLF & "TTL: " & $ttl & @CRLF & "Running Time: " & $runtime & @CRLF & "Clock: " & @HOUR & ":" & @MIN, $disX, $disY, "Level: " & $level)
  125. Sleep(2000)
  126. WEnd
  127.  
  128. Func Close()
  129. _MemoryClose($handle)
  130. Exit
  131. EndFunc
  132.  
  133. Func Toggle()
  134. If $hidden = 0 Then
  135. $hidden = 1
  136. Else
  137. $hidden = 0
  138. EndIf
  139. EndFunc
  140.  
  141. Func AddCommas($string)
  142. $t = 0
  143. $final = ""
  144. $var = $string
  145. $result = StringSplit($var, "")
  146. For $x = $result[0] to 1 Step -1
  147. $t = $t + 1
  148. If $t = 4 Then
  149. $final = "," & $final
  150. $t = 1
  151. EndIf
  152. $final = $result[$x] & $final
  153. Next
  154. return $final
  155. EndFunc
  156.  
  157.  
  158. Func ReadPointer($base, $hand, $offsets)
  159. $curAddress = $base
  160. for $x = 0 to UBound($offsets) - 1
  161. $curAddress = _MemoryRead($curAddress + $offsets[$x], $hand, "dword")
  162. Next
  163.  
  164. Return $curAddress
  165. EndFunc
  166.  
  167. Func Reset()
  168. $time = TimerInit()
  169. $startExp = ReadPointer($playerbase, $handle, $expMinOffsets)
  170. $curLevel = ReadPointer($playerbase, $handle, $levelOffsets)
  171. EndFunc
  172.  
  173.  
  174. Func GetBaseAddress($ProcessID)
  175. $HSNAP = DllCall("Kernel32.dll", "HANDLE", "CreateToolhelp32Snapshot", "DWORD", 8, "DWORD", $ProcessID)
  176. $STMODULE = DllStructCreate("DWORD dwSize;DWORD th32ModuleID;DWORD th32ProcessID;" & "DWORD GlblcntUsage;DWORD ProccntUsage;ptr modBaseAddr;" & "DWORD modBaseSize;HANDLE hModule;WCHAR szModule[256];" & "WCHAR szExePath[260]")
  177. DllStructSetData($STMODULE, "dwSize", DllStructGetSize($STMODULE))
  178. $RET = DllCall("Kernel32.dll", "BOOLEAN", "Module32FirstW", "HANDLE", $HSNAP[0], "ptr", DllStructGetPtr($STMODULE))
  179.  
  180. IF ($RET[0] = False) Then
  181. DllCall("Kernel32.dll", "BOOLEAN", "CloseHandle", "HANDLE", $HSNAP[0])
  182. Return 0
  183. Else
  184. $RET[0] = True
  185. Do
  186. If DllStructGetData($STMODULE, "szModule") = "PathOfExile.exe" Then
  187.  
  188. DllCall("Kernel32.dll", "BOOLEAN", "CloseHandle", "HANDLE", $HSNAP[0])
  189.  
  190. Return DllStructGetData($STMODULE, "modBaseAddr")
  191. EndIf
  192. $RET = DllCall("Kernel32.dll", "BOOLEAN", "Module32NextW", "HANDLE", $HSNAP[0], "ptr", DllStructGetPtr($STMODULE))
  193. Until $RET[0] = False
  194. EndIf
  195. EndFunc
  196.  
  197. #include-once
  198. #region _Memory
  199. ;=================================================================================================
  200. ; AutoIt Version: 3.1.127 (beta)
  201. ; Language: English
  202. ; Platform: All Windows
  203. ; Author: Nomad
  204. ; Requirements: These functions will only work with beta.
  205. ;=================================================================================================
  206. ; Credits: wOuter - These functions are based on his original _Mem() functions. But they are
  207. ; easier to comprehend and more reliable. These functions are in no way a direct copy
  208. ; of his functions. His functions only provided a foundation from which these evolved.
  209. ;=================================================================================================
  210. ;
  211. ; Functions:
  212. ;
  213. ;=================================================================================================
  214. ; Function: _MemoryOpen($iv_Pid(, $iv_DesiredAccess(, $iv_InheritHandle)))
  215. ; Description: Opens a process and enables all possible access rights to the process. The
  216. ; Process ID of the process is used to specify which process to open. You must
  217. ; call this function before calling _MemoryClose(), _MemoryRead(), or _MemoryWrite().
  218. ; Parameter(s): $iv_Pid - The Process ID of the program you want to open.
  219. ; $iv_DesiredAccess - (optional) Set to 0x1F0FFF by default, which enables all
  220. ; possible access rights to the process specified by the
  221. ; Process ID.
  222. ; $if_InheritHandle - (optional) If this value is TRUE, all processes created by
  223. ; this process will inherit the access handle. Set to TRUE
  224. ; (1) by default. Set to 0 if you want it to be FALSE.
  225. ; Requirement(s): A valid process ID.
  226. ; Return Value(s): On Success - Returns an array containing the Dll handle and an open handle to
  227. ; the specified process.
  228. ; On Failure - Returns 0
  229. ; @Error - 0 = No error.
  230. ; 1 = Invalid $iv_Pid.
  231. ; 2 = Failed to open Kernel32.dll.
  232. ; 3 = Failed to open the specified process.
  233. ; Author(s): Nomad
  234. ; Note(s):
  235. ;=================================================================================================
  236. Func _MemoryOpen($iv_Pid, $iv_DesiredAccess = 0x1F0FFF, $if_InheritHandle = 1)
  237.  
  238. If Not ProcessExists($iv_Pid) Then
  239. SetError(1)
  240. Return 0
  241. EndIf
  242.  
  243. Local $ah_Handle[2] = [DllOpen('kernel32.dll')]
  244.  
  245. If @Error Then
  246. SetError(2)
  247. Return 0
  248. EndIf
  249.  
  250. Local $av_OpenProcess = DllCall($ah_Handle[0], 'int', 'OpenProcess', 'int', $iv_DesiredAccess, 'int', $if_InheritHandle, 'int', $iv_Pid)
  251.  
  252. If @Error Then
  253. DllClose($ah_Handle[0])
  254. SetError(3)
  255. Return 0
  256. EndIf
  257.  
  258. $ah_Handle[1] = $av_OpenProcess[0]
  259.  
  260. Return $ah_Handle
  261.  
  262. EndFunc
  263.  
  264. ;=================================================================================================
  265. ; Function: _MemoryRead($iv_Address, $ah_Handle(, $sv_Type))
  266. ; Description: Reads the value located in the memory address specified.
  267. ; Parameter(s): $iv_Address - The memory address you want to read from. It must be in hex
  268. ; format (0x00000000).
  269. ; $ah_Handle - An array containing the Dll handle and the handle of the open
  270. ; process as returned by _MemoryOpen().
  271. ; $sv_Type - (optional) The "Type" of value you intend to read. This is set to
  272. ; 'dword'(32bit(4byte) signed integer) by default. See the help file
  273. ; for DllStructCreate for all types.
  274. ; An example: If you want to read a word that is 15 characters in
  275. ; length, you would use 'char[16]'.
  276. ; Requirement(s): The $ah_Handle returned from _MemoryOpen.
  277. ; Return Value(s): On Success - Returns the value located at the specified address.
  278. ; On Failure - Returns 0
  279. ; @Error - 0 = No error.
  280. ; 1 = Invalid $ah_Handle.
  281. ; 2 = $sv_Type was not a string.
  282. ; 3 = $sv_Type is an unknown data type.
  283. ; 4 = Failed to allocate the memory needed for the DllStructure.
  284. ; 5 = Error allocating memory for $sv_Type.
  285. ; 6 = Failed to read from the specified process.
  286. ; Author(s): Nomad
  287. ; Note(s): Values returned are in Decimal format, unless specified as a 'char' type, then
  288. ; they are returned in ASCII format. Also note that size ('char[size]') for all
  289. ; 'char' types should be 1 greater than the actual size.
  290. ;=================================================================================================
  291. Func _MemoryRead($iv_Address, $ah_Handle, $sv_Type = 'dword')
  292.  
  293. If Not IsArray($ah_Handle) Then
  294. SetError(1)
  295. Return 0
  296. EndIf
  297.  
  298. Local $v_Buffer = DllStructCreate($sv_Type)
  299.  
  300. If @Error Then
  301. SetError(@Error + 1)
  302. Return 0
  303. EndIf
  304.  
  305. DllCall($ah_Handle[0], 'int', 'ReadProcessMemory', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer), 'int', '')
  306.  
  307. If Not @Error Then
  308. Local $v_Value = DllStructGetData($v_Buffer, 1)
  309. Return $v_Value
  310. Else
  311. SetError(6)
  312. Return 0
  313. EndIf
  314.  
  315. EndFunc
  316.  
  317. ;=================================================================================================
  318. ; Function: _MemoryWrite($iv_Address, $ah_Handle, $v_Data(, $sv_Type))
  319. ; Description: Writes data to the specified memory address.
  320. ; Parameter(s): $iv_Address - The memory address you want to write to. It must be in hex
  321. ; format (0x00000000).
  322. ; $ah_Handle - An array containing the Dll handle and the handle of the open
  323. ; process as returned by _MemoryOpen().
  324. ; $v_Data - The data to be written.
  325. ; $sv_Type - (optional) The "Type" of value you intend to write. This is set to
  326. ; 'dword'(32bit(4byte) signed integer) by default. See the help file
  327. ; for DllStructCreate for all types.
  328. ; An example: If you want to write a word that is 15 characters in
  329. ; length, you would use 'char[16]'.
  330. ; Requirement(s): The $ah_Handle returned from _MemoryOpen.
  331. ; Return Value(s): On Success - Returns 1
  332. ; On Failure - Returns 0
  333. ; @Error - 0 = No error.
  334. ; 1 = Invalid $ah_Handle.
  335. ; 2 = $sv_Type was not a string.
  336. ; 3 = $sv_Type is an unknown data type.
  337. ; 4 = Failed to allocate the memory needed for the DllStructure.
  338. ; 5 = Error allocating memory for $sv_Type.
  339. ; 6 = $v_Data is not in the proper format to be used with the "Type"
  340. ; selected for $sv_Type, or it is out of range.
  341. ; 7 = Failed to write to the specified process.
  342. ; Author(s): Nomad
  343. ; Note(s): Values sent must be in Decimal format, unless specified as a 'char' type, then
  344. ; they must be in ASCII format. Also note that size ('char[size]') for all
  345. ; 'char' types should be 1 greater than the actual size.
  346. ;=================================================================================================
  347. Func _MemoryWrite($iv_Address, $ah_Handle, $v_Data, $sv_Type = 'dword')
  348.  
  349. If Not IsArray($ah_Handle) Then
  350. SetError(1)
  351. Return 0
  352. EndIf
  353.  
  354. Local $v_Buffer = DllStructCreate($sv_Type)
  355.  
  356. If @Error Then
  357. SetError(@Error + 1)
  358. Return 0
  359. Else
  360. DllStructSetData($v_Buffer, 1, $v_Data)
  361. If @Error Then
  362. SetError(6)
  363. Return 0
  364. EndIf
  365. EndIf
  366.  
  367. DllCall($ah_Handle[0], 'int', 'WriteProcessMemory', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer), 'int', '')
  368.  
  369. If Not @Error Then
  370. Return 1
  371. Else
  372. SetError(7)
  373. Return 0
  374. EndIf
  375.  
  376. EndFunc
  377.  
  378. ;=================================================================================================
  379. ; Function: _MemoryClose($ah_Handle)
  380. ; Description: Closes the process handle opened by using _MemoryOpen().
  381. ; Parameter(s): $ah_Handle - An array containing the Dll handle and the handle of the open
  382. ; process as returned by _MemoryOpen().
  383. ; Requirement(s): The $ah_Handle returned from _MemoryOpen.
  384. ; Return Value(s): On Success - Returns 1
  385. ; On Failure - Returns 0
  386. ; @Error - 0 = No error.
  387. ; 1 = Invalid $ah_Handle.
  388. ; 2 = Unable to close the process handle.
  389. ; Author(s): Nomad
  390. ; Note(s):
  391. ;=================================================================================================
  392. Func _MemoryClose($ah_Handle)
  393.  
  394. If Not IsArray($ah_Handle) Then
  395. SetError(1)
  396. Return 0
  397. EndIf
  398.  
  399. DllCall($ah_Handle[0], 'int', 'CloseHandle', 'int', $ah_Handle[1])
  400. If Not @Error Then
  401. DllClose($ah_Handle[0])
  402. Return 1
  403. Else
  404. DllClose($ah_Handle[0])
  405. SetError(2)
  406. Return 0
  407. EndIf
  408.  
  409. EndFunc
  410.  
  411. ;=================================================================================================
  412. ; Function: _MemoryPointerRead ($iv_Address, $ah_Handle, $av_Offset(, $sv_Type))
  413. ; Description: Reads a chain of pointers and returns an array containing the destination
  414. ; address and the data at the address.
  415. ; Parameter(s): $iv_Address - The static memory address you want to start at. It must be in
  416. ; hex format (0x00000000).
  417. ; $ah_Handle - An array containing the Dll handle and the handle of the open
  418. ; process as returned by _MemoryOpen().
  419. ; $av_Offset - An array of offsets for the pointers. Each pointer must have an
  420. ; offset. If there is no offset for a pointer, enter 0 for that
  421. ; array dimension. (Offsets must be in decimal format, NOT hex!)
  422. ; $sv_Type - (optional) The "Type" of data you intend to read at the destination
  423. ; address. This is set to 'dword'(32bit(4byte) signed integer) by
  424. ; default. See the help file for DllStructCreate for all types.
  425. ; Requirement(s): The $ah_Handle returned from _MemoryOpen.
  426. ; Return Value(s): On Success - Returns an array containing the destination address and the value
  427. ; located at the address.
  428. ; On Failure - Returns 0
  429. ; @Error - 0 = No error.
  430. ; 1 = $av_Offset is not an array.
  431. ; 2 = Invalid $ah_Handle.
  432. ; 3 = $sv_Type is not a string.
  433. ; 4 = $sv_Type is an unknown data type.
  434. ; 5 = Failed to allocate the memory needed for the DllStructure.
  435. ; 6 = Error allocating memory for $sv_Type.
  436. ; 7 = Failed to read from the specified process.
  437. ; Author(s): Nomad
  438. ; Note(s): Values returned are in Decimal format, unless a 'char' type is selected.
  439. ; Set $av_Offset like this:
  440. ; $av_Offset[0] = NULL (not used)
  441. ; $av_Offset[1] = Offset for pointer 1 (all offsets must be in Decimal)
  442. ; $av_Offset[2] = Offset for pointer 2
  443. ; etc...
  444. ; (The number of array dimensions determines the number of pointers)
  445. ;=================================================================================================
  446. Func _MemoryPointerRead ($iv_Address, $ah_Handle, $av_Offset, $sv_Type = 'dword')
  447.  
  448.  
  449.  
  450. If IsArray($av_Offset) Then
  451. If IsArray($ah_Handle) Then
  452. Local $iv_PointerCount = UBound($av_Offset) - 1
  453. Else
  454. SetError(2)
  455. Return 0
  456. EndIf
  457. Else
  458. SetError(1)
  459. Return 0
  460. EndIf
  461.  
  462. Local $iv_Data[2], $i
  463. Local $v_Buffer = DllStructCreate('dword')
  464.  
  465. For $i = 0 to $iv_PointerCount
  466.  
  467. If $i = $iv_PointerCount Then
  468. $v_Buffer = DllStructCreate($sv_Type)
  469. If @Error Then
  470. SetError(@Error + 2)
  471. Return 0
  472. EndIf
  473.  
  474. $iv_Address = '0x' & hex($iv_Data[1] + $av_Offset[$i])
  475. DllCall($ah_Handle[0], 'int', 'ReadProcessMemory', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer), 'int', '')
  476. If @Error Then
  477. SetError(7)
  478. Return 0
  479. EndIf
  480.  
  481. $iv_Data[1] = DllStructGetData($v_Buffer, 1)
  482.  
  483. ElseIf $i = 0 Then
  484. DllCall($ah_Handle[0], 'int', 'ReadProcessMemory', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer), 'int', '')
  485. If @Error Then
  486. SetError(7)
  487. Return 0
  488. EndIf
  489.  
  490. $iv_Data[1] = DllStructGetData($v_Buffer, 1)
  491.  
  492. Else
  493. $iv_Address = '0x' & hex($iv_Data[1] + $av_Offset[$i])
  494. DllCall($ah_Handle[0], 'int', 'ReadProcessMemory', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer), 'int', '')
  495. If @Error Then
  496. SetError(7)
  497. Return 0
  498. EndIf
  499.  
  500. $iv_Data[1] = DllStructGetData($v_Buffer, 1)
  501.  
  502. EndIf
  503.  
  504. Next
  505.  
  506. $iv_Data[0] = $iv_Address
  507.  
  508. Return $iv_Data
  509.  
  510. EndFunc
  511.  
  512. ;=================================================================================================
  513. ; Function: _MemoryPointerWrite ($iv_Address, $ah_Handle, $av_Offset, $v_Data(, $sv_Type))
  514. ; Description: Reads a chain of pointers and writes the data to the destination address.
  515. ; Parameter(s): $iv_Address - The static memory address you want to start at. It must be in
  516. ; hex format (0x00000000).
  517. ; $ah_Handle - An array containing the Dll handle and the handle of the open
  518. ; process as returned by _MemoryOpen().
  519. ; $av_Offset - An array of offsets for the pointers. Each pointer must have an
  520. ; offset. If there is no offset for a pointer, enter 0 for that
  521. ; array dimension.
  522. ; $v_Data - The data to be written.
  523. ; $sv_Type - (optional) The "Type" of data you intend to write at the destination
  524. ; address. This is set to 'dword'(32bit(4byte) signed integer) by
  525. ; default. See the help file for DllStructCreate for all types.
  526. ; Requirement(s): The $ah_Handle returned from _MemoryOpen.
  527. ; Return Value(s): On Success - Returns the destination address.
  528. ; On Failure - Returns 0.
  529. ; @Error - 0 = No error.
  530. ; 1 = $av_Offset is not an array.
  531. ; 2 = Invalid $ah_Handle.
  532. ; 3 = Failed to read from the specified process.
  533. ; 4 = $sv_Type is not a string.
  534. ; 5 = $sv_Type is an unknown data type.
  535. ; 6 = Failed to allocate the memory needed for the DllStructure.
  536. ; 7 = Error allocating memory for $sv_Type.
  537. ; 8 = $v_Data is not in the proper format to be used with the
  538. ; "Type" selected for $sv_Type, or it is out of range.
  539. ; 9 = Failed to write to the specified process.
  540. ; Author(s): Nomad
  541. ; Note(s): Data written is in Decimal format, unless a 'char' type is selected.
  542. ; Set $av_Offset like this:
  543. ; $av_Offset[0] = NULL (not used, doesn't matter what's entered)
  544. ; $av_Offset[1] = Offset for pointer 1 (all offsets must be in Decimal)
  545. ; $av_Offset[2] = Offset for pointer 2
  546. ; etc...
  547. ; (The number of array dimensions determines the number of pointers)
  548. ;=================================================================================================
  549. Func _MemoryPointerWrite ($iv_Address, $ah_Handle, $av_Offset, $v_Data, $sv_Type = 'dword')
  550.  
  551. If IsArray($av_Offset) Then
  552. If IsArray($ah_Handle) Then
  553. Local $iv_PointerCount = UBound($av_Offset) - 1
  554. Else
  555. SetError(2)
  556. Return 0
  557. EndIf
  558. Else
  559. SetError(1)
  560. Return 0
  561. EndIf
  562.  
  563. Local $iv_StructData, $i
  564. Local $v_Buffer = DllStructCreate('dword')
  565.  
  566. For $i = 0 to $iv_PointerCount
  567. If $i = $iv_PointerCount Then
  568. $v_Buffer = DllStructCreate($sv_Type)
  569. If @Error Then
  570. SetError(@Error + 3)
  571. Return 0
  572. EndIf
  573.  
  574. DllStructSetData($v_Buffer, 1, $v_Data)
  575. If @Error Then
  576. SetError(8)
  577. Return 0
  578. EndIf
  579.  
  580. $iv_Address = '0x' & hex($iv_StructData + $av_Offset[$i])
  581. DllCall($ah_Handle[0], 'int', 'WriteProcessMemory', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer), 'int', '')
  582. If @Error Then
  583. SetError(9)
  584. Return 0
  585. Else
  586. Return $iv_Address
  587. EndIf
  588. ElseIf $i = 0 Then
  589. DllCall($ah_Handle[0], 'int', 'ReadProcessMemory', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer), 'int', '')
  590. If @Error Then
  591. SetError(3)
  592. Return 0
  593. EndIf
  594.  
  595. $iv_StructData = DllStructGetData($v_Buffer, 1)
  596.  
  597. Else
  598. $iv_Address = '0x' & hex($iv_StructData + $av_Offset[$i])
  599. DllCall($ah_Handle[0], 'int', 'ReadProcessMemory', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer), 'int', '')
  600. If @Error Then
  601. SetError(3)
  602. Return 0
  603. EndIf
  604.  
  605. $iv_StructData = DllStructGetData($v_Buffer, 1)
  606.  
  607. EndIf
  608. Next
  609.  
  610. EndFunc
  611.  
  612.  
  613. ;==================================================================================
  614. ; Function: SetPrivilege( $privilege, $bEnable )
  615. ; Description: Enables (or disables) the $privilege on the current process
  616. ; (Probably) requires administrator privileges to run
  617. ;
  618. ; Author(s): Larry (from autoitscript.com's Forum)
  619. ; Notes(s):
  620. ; http://www.autoitscript.com/forum/index.php?s=&showtopic=31248&view=findpost&p=223999
  621. ;==================================================================================
  622.  
  623. Func SetPrivilege( $privilege, $bEnable )
  624. Const $TOKEN_ADJUST_PRIVILEGES = 0x0020
  625. Const $TOKEN_QUERY = 0x0008
  626. Const $SE_PRIVILEGE_ENABLED = 0x0002
  627. Local $hToken, $SP_auxret, $SP_ret, $hCurrProcess, $nTokens, $nTokenIndex, $priv
  628. $nTokens = 1
  629. $LUID = DLLStructCreate("dword;int")
  630. If IsArray($privilege) Then $nTokens = UBound($privilege)
  631. $TOKEN_PRIVILEGES = DLLStructCreate("dword;dword[" & (3 * $nTokens) & "]")
  632. $NEWTOKEN_PRIVILEGES = DLLStructCreate("dword;dword[" & (3 * $nTokens) & "]")
  633. $hCurrProcess = DLLCall("kernel32.dll","hwnd","GetCurrentProcess")
  634. $SP_auxret = DLLCall("advapi32.dll","int","OpenProcessToken","hwnd",$hCurrProcess[0], _
  635. "int",BitOR($TOKEN_ADJUST_PRIVILEGES,$TOKEN_QUERY),"int*",0)
  636. If $SP_auxret[0] Then
  637. $hToken = $SP_auxret[3]
  638. DLLStructSetData($TOKEN_PRIVILEGES,1,1)
  639. $nTokenIndex = 1
  640. While $nTokenIndex <= $nTokens
  641. If IsArray($privilege) Then
  642. $ntokenvar=$ntokenindex-1
  643. $priv = $privilege[$ntokenvar]
  644. Else
  645. $priv = $privilege
  646. EndIf
  647. $ret = DLLCall("advapi32.dll","int","LookupPrivilegeValue","str","","str",$priv, _
  648. "ptr",DLLStructGetPtr($LUID))
  649. If $ret[0] Then
  650. If $bEnable Then
  651. DLLStructSetData($TOKEN_PRIVILEGES,2,$SE_PRIVILEGE_ENABLED,(3 * $nTokenIndex))
  652. Else
  653. DLLStructSetData($TOKEN_PRIVILEGES,2,0,(3 * $nTokenIndex))
  654. EndIf
  655. DLLStructSetData($TOKEN_PRIVILEGES,2,DllStructGetData($LUID,1),(3 * ($nTokenIndex-1)) + 1)
  656. DLLStructSetData($TOKEN_PRIVILEGES,2,DllStructGetData($LUID,2),(3 * ($nTokenIndex-1)) + 2)
  657. DLLStructSetData($LUID,1,0)
  658. DLLStructSetData($LUID,2,0)
  659. EndIf
  660. $nTokenIndex += 1
  661. WEnd
  662. $ret = DLLCall("advapi32.dll","int","AdjustTokenPrivileges","hwnd",$hToken,"int",0, _
  663. "ptr",DllStructGetPtr($TOKEN_PRIVILEGES),"int",DllStructGetSize($NEWTOKEN_PRIVILEGES), _
  664. "ptr",DllStructGetPtr($NEWTOKEN_PRIVILEGES),"int*",0)
  665. $f = DLLCall("kernel32.dll","int","GetLastError")
  666. EndIf
  667. $NEWTOKEN_PRIVILEGES=0
  668. $TOKEN_PRIVILEGES=0
  669. $LUID=0
  670. If $SP_auxret[0] = 0 Then Return 0
  671. $SP_auxret = DLLCall("kernel32.dll","int","CloseHandle","hwnd",$hToken)
  672. If Not $ret[0] And Not $SP_auxret[0] Then Return 0
  673. return $ret[0]
  674. EndFunc ;==>SetPrivilege
  675.  
  676. ;===================================================================================================
  677. ; Function........: _MemoryGetBaseAddress($ah_Handle, $iHD)
  678. ;
  679. ; Description.....: Reads the 'Allocation Base' from the open process.
  680. ;
  681. ; Parameter(s)....: $ah_Handle - An array containing the Dll handle and the handle of the open
  682. ; process as returned by _MemoryOpen().
  683. ; $iHD - Return type:
  684. ; |0 = Hex (Default)
  685. ; |1 = Dec
  686. ;
  687. ; Requirement(s)..: A valid process ID.
  688. ;
  689. ; Return Value(s).: On Success - Returns the 'allocation Base' address and sets @Error to 0.
  690. ; On Failure - Returns 0 and sets @Error to:
  691. ; |1 = Invalid $ah_Handle.
  692. ; |2 = Failed to find correct allocation address.
  693. ; |3 = Failed to read from the specified process.
  694. ;
  695. ; Author(s).......: Nomad. Szhlopp.
  696. ; URL.............: http://www.autoitscript.com/forum/index.php?showtopic=78834
  697. ; Note(s).........: Go to Www.CheatEngine.org for the latest version of CheatEngine.
  698. ;===================================================================================================
  699. Func _MemoryGetBaseAddress($ah_Handle, $iHexDec = 0)
  700.  
  701. Local $iv_Address = 0x00100000
  702. Local $v_Buffer = DllStructCreate('dword;dword;dword;dword;dword;dword;dword')
  703. Local $vData
  704. Local $vType
  705.  
  706. If Not IsArray($ah_Handle) Then
  707. SetError(1)
  708. Return 0
  709. EndIf
  710.  
  711.  
  712. DllCall($ah_Handle[0], 'int', 'VirtualQueryEx', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer))
  713.  
  714. If Not @Error Then
  715.  
  716. $vData = Hex(DllStructGetData($v_Buffer, 2))
  717. $vType = Hex(DllStructGetData($v_Buffer, 3))
  718.  
  719. While $vType <> "00000080"
  720. DllCall($ah_Handle[0], 'int', 'VirtualQueryEx', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer))
  721. $vData = Hex(DllStructGetData($v_Buffer, 2))
  722. $vType = Hex(DllStructGetData($v_Buffer, 3))
  723. If Hex($iv_Address) = "01000000" Then ExitLoop
  724. $iv_Address += 65536
  725.  
  726. WEnd
  727.  
  728. If $vType = "00000080" Then
  729. SetError(0)
  730. If $iHexDec = 1 Then
  731. Return Dec($vData)
  732. Else
  733. Return $vData
  734. EndIf
  735.  
  736. Else
  737. SetError(2)
  738. Return 0
  739. EndIf
  740.  
  741. Else
  742. SetError(3)
  743. Return 0
  744. EndIf
  745.  
  746. EndFunc ;==>_MemoryGetBa
  747. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement