Advertisement
Guest User

Untitled

a guest
Sep 19th, 2010
1,148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 1.40 KB | None | 0 0
  1. Func _MemoryModuleGetBaseAddress($iPID, $sModule)
  2.     If Not ProcessExists($iPID) Then Return SetError(1, 0, 0)
  3.  
  4.     If Not IsString($sModule) Then Return SetError(2, 0, 0)
  5.  
  6.     Local   $PSAPI = DllOpen("psapi.dll")
  7.  
  8.     ;Get Process Handle
  9.     Local   $hProcess
  10.     Local   $PERMISSION = BitOR(0x0002, 0x0400, 0x0008, 0x0010, 0x0020) ; CREATE_THREAD, QUERY_INFORMATION, VM_OPERATION, VM_READ, VM_WRITE
  11.  
  12.     If $iPID > 0 Then
  13.         Local $hProcess = DllCall("kernel32.dll", "ptr", "OpenProcess", "dword", $PERMISSION, "int", 0, "dword", $iPID)
  14.         If $hProcess[0] Then
  15.             $hProcess = $hProcess[0]
  16.         EndIf
  17.     EndIf
  18.  
  19.     ;EnumProcessModules
  20.     Local   $Modules = DllStructCreate("ptr[1024]")
  21.     Local   $aCall = DllCall($PSAPI, "int", "EnumProcessModules", "ptr", $hProcess, "ptr", DllStructGetPtr($Modules), "dword", DllStructGetSize($Modules), "dword*", 0)
  22.     If $aCall[4] > 0 Then
  23.         Local   $iModnum = $aCall[4] / 4
  24.         Local   $aTemp
  25.         For $i = 1 To $iModnum
  26.             $aTemp =  DllCall($PSAPI, "dword", "GetModuleBaseNameW", "ptr", $hProcess, "ptr", Ptr(DllStructGetData($Modules, 1, $i)), "wstr", "", "dword", 260)
  27.             If $aTemp[3] = $sModule Then
  28.                 DllClose($PSAPI)
  29.                 Return Ptr(DllStructGetData($Modules, 1, $i))
  30.             EndIf
  31.         Next
  32.     EndIf
  33.  
  34.     DllClose($PSAPI)
  35.     Return SetError(-1, 0, 0)
  36.  
  37. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement