Pointer & Offset => Adresse & Value

  • Hi brauche Hilfe von den Profis!

    Also vorweg dies ist kein Bot. Ich will damit auch keinen Bot schreiben sondern nur meine Kentnisse bezüglich Memory erweitern.

    Ich hab von einem Prozess [TRose.exe]
    per CheatEngine einen Pointer gefunden [0x006936A8]
    dazu natürlich auch die/den Offset [36]

    Jetzt will ich, wie im Titel beschrieben, den Pointer + Offset in die Adresse umwandeln, wo er hinzeigt und den Wert auslesen. Das Problem hierbei ist, dass ich nicht auf die Adresse komme, auf der der Pointer eigentlich zeigt.

    Wenn ich in CheatEngine nämlich den Prozess anvisiere und den Pointer + Offset eintrage kommt er auf eine richtige Adresse, bei Autoit nicht.

    Hier mein Code:

    Spoiler anzeigen
    [autoit]


    $Offset = 140
    $pid = ProcessExists("TRose.exe");Returns the PID (3020)

    [/autoit] [autoit][/autoit] [autoit]

    $openmem = _MemoryOpen($pid);Returns nothing in MsgBox

    [/autoit] [autoit][/autoit] [autoit]

    $baseADDR = _MemoryGetBaseAddress($openmem,1);Returns base address (3342336)
    $Action_Address = "0x" & Hex($baseADDR + Dec("6936A8")); Returns 0x009C36A8

    [/autoit] [autoit][/autoit] [autoit]

    $Action_Read = _MemoryPointerRead($Action_Address, $openmem, $Offset);Returns 0 (but it's not 0)

    [/autoit] [autoit][/autoit] [autoit]

    MsgBox(64,"Info","Address: "&$Action_Address&@CRLF&"Value: "&$Action_Read)

    [/autoit]

    UDF's (erweiterte NomadMemory.au3)

    Spoiler anzeigen
    [autoit]


    Func _MemoryOpen($iv_Pid, $iv_DesiredAccess = 0x1F0FFF, $if_InheritHandle = 1)

    If Not ProcessExists($iv_Pid) Then
    SetError(1)
    Return 0
    EndIf

    Local $ah_Handle[2] = [DllOpen('kernel32.dll')]

    If @Error Then
    SetError(2)
    Return 0
    EndIf

    Local $av_OpenProcess = DllCall($ah_Handle[0], 'int', 'OpenProcess', 'int', $iv_DesiredAccess, 'int', $if_InheritHandle, 'int', $iv_Pid)

    If @Error Then
    DllClose($ah_Handle[0])
    SetError(3)
    Return 0
    EndIf

    $ah_Handle[1] = $av_OpenProcess[0]

    Return $ah_Handle

    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ;==================

    [/autoit] [autoit][/autoit] [autoit]

    Func _MemoryGetBaseAddress($ah_Handle, $iHexDec = 0)

    Local $iv_Address = 0x00100000
    Local $v_Buffer = DllStructCreate('dword;dword;dword;dword;dword;dword;dword')
    Local $vData
    Local $vType

    If Not IsArray($ah_Handle) Then
    SetError(1)
    Return 0
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    DllCall($ah_Handle[0], 'int', 'VirtualQueryEx', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer))

    If Not @Error Then

    $vData = Hex(DllStructGetData($v_Buffer, 2))
    $vType = Hex(DllStructGetData($v_Buffer, 3))

    While $vType <> "00000080"
    DllCall($ah_Handle[0], 'int', 'VirtualQueryEx', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer))
    $vData = Hex(DllStructGetData($v_Buffer, 2))
    $vType = Hex(DllStructGetData($v_Buffer, 3))
    If Hex($iv_Address) = "01000000" Then ExitLoop
    $iv_Address += 65536

    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    If $vType = "00000080" Then
    SetError(0)
    If $iHexDec = 1 Then
    Return Dec($vData)
    Else
    Return $vData
    EndIf

    Else
    SetError(2)
    Return 0
    EndIf

    Else
    SetError(3)
    Return 0
    EndIf

    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ;=================================================

    [/autoit] [autoit][/autoit] [autoit]

    Func _MemoryPointerRead ($iv_Address, $ah_Handle, $av_Offset, $sv_Type = 'dword')

    If IsArray($av_Offset) Then
    If IsArray($ah_Handle) Then
    Local $iv_PointerCount = UBound($av_Offset) - 1
    Else
    SetError(2)
    Return 0
    EndIf
    Else
    SetError(1)
    Return 0
    EndIf

    Local $iv_Data[2], $i
    Local $v_Buffer = DllStructCreate('dword')

    For $i = 0 to $iv_PointerCount

    If $i = $iv_PointerCount Then
    $v_Buffer = DllStructCreate($sv_Type)
    If @Error Then
    SetError(@Error + 2)
    Return 0
    EndIf

    $iv_Address = '0x' & hex($iv_Data[1] + $av_Offset[$i])
    DllCall($ah_Handle[0], 'int', 'ReadProcessMemory', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer), 'int', '')
    If @Error Then
    SetError(7)
    Return 0
    EndIf

    $iv_Data[1] = DllStructGetData($v_Buffer, 1)

    ElseIf $i = 0 Then
    DllCall($ah_Handle[0], 'int', 'ReadProcessMemory', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer), 'int', '')
    If @Error Then
    SetError(7)
    Return 0
    EndIf

    $iv_Data[1] = DllStructGetData($v_Buffer, 1)

    Else
    $iv_Address = '0x' & hex($iv_Data[1] + $av_Offset[$i])
    DllCall($ah_Handle[0], 'int', 'ReadProcessMemory', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer), 'int', '')
    If @Error Then
    SetError(7)
    Return 0
    EndIf

    $iv_Data[1] = DllStructGetData($v_Buffer, 1)

    EndIf

    Next

    $iv_Data[0] = $iv_Address

    Return $iv_Data

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc

    [/autoit]

    Wäre dankbar wenn mir jemand den Fehler nennen könnte bzw wie ich sonst noch die Adresse bzw den Pointer auslesen kann. Hab mal gesehen, dass Xeno sich damit beschäftigt hat vielleicht hast du ja noch was informatives für mich.

  • Könnte sein, dass du die Adresse erst noch in einen Pointer umwandeln musst?
    $Action_Address = Ptr($Action_Address)

  • Das könnte ein Problem mit den Zugriffsrechten sein. Irgendwo soll es in Nomadmemory eine SetPrivilege Function geben. Mit dem "SeDebugLevel" solltest Du dann auf die Processmemory zugreifen dürfen.

  • Hier mal die Funktion. Hab allerdings keine Ahnung was man damit macht.

    NomadMemory.au3
    [autoit]

    ;==================================================================================
    ; Function: SetPrivilege( $privilege, $bEnable )
    ; Description: Enables (or disables) the $privilege on the current process
    ; (Probably) requires administrator privileges to run
    ;
    ; Author(s): Larry (from autoitscript.com's Forum)
    ; Notes(s):
    ; http://www.autoitscript.com/forum/index.ph…ndpost&p=223999
    ;==================================================================================

    [/autoit] [autoit][/autoit] [autoit]

    Func SetPrivilege( $privilege, $bEnable )
    Const $TOKEN_ADJUST_PRIVILEGES = 0x0020
    Const $TOKEN_QUERY = 0x0008
    Const $SE_PRIVILEGE_ENABLED = 0x0002
    Local $hToken, $SP_auxret, $SP_ret, $hCurrProcess, $nTokens, $nTokenIndex, $priv
    $nTokens = 1
    $LUID = DLLStructCreate("dword;int")
    If IsArray($privilege) Then $nTokens = UBound($privilege)
    $TOKEN_PRIVILEGES = DLLStructCreate("dword;dword[" & (3 * $nTokens) & "]")
    $NEWTOKEN_PRIVILEGES = DLLStructCreate("dword;dword[" & (3 * $nTokens) & "]")
    $hCurrProcess = DLLCall("kernel32.dll","hwnd","GetCurrentProcess")
    $SP_auxret = DLLCall("advapi32.dll","int","OpenProcessToken","hwnd",$hCurrProcess[0], _
    "int",BitOR($TOKEN_ADJUST_PRIVILEGES,$TOKEN_QUERY),"int_ptr",0)
    If $SP_auxret[0] Then
    $hToken = $SP_auxret[3]
    DLLStructSetData($TOKEN_PRIVILEGES,1,1)
    $nTokenIndex = 1
    While $nTokenIndex <= $nTokens
    If IsArray($privilege) Then
    $priv = $privilege[$nTokenIndex-1]
    Else
    $priv = $privilege
    EndIf
    $ret = DLLCall("advapi32.dll","int","LookupPrivilegeValue","str","","str",$priv, _
    "ptr",DLLStructGetPtr($LUID))
    If $ret[0] Then
    If $bEnable Then
    DLLStructSetData($TOKEN_PRIVILEGES,2,$SE_PRIVILEGE_ENABLED,(3 * $nTokenIndex))
    Else
    DLLStructSetData($TOKEN_PRIVILEGES,2,0,(3 * $nTokenIndex))
    EndIf
    DLLStructSetData($TOKEN_PRIVILEGES,2,DllStructGetData($LUID,1),(3 * ($nTokenIndex-1)) + 1)
    DLLStructSetData($TOKEN_PRIVILEGES,2,DllStructGetData($LUID,2),(3 * ($nTokenIndex-1)) + 2)
    DLLStructSetData($LUID,1,0)
    DLLStructSetData($LUID,2,0)
    EndIf
    $nTokenIndex += 1
    WEnd
    $ret = DLLCall("advapi32.dll","int","AdjustTokenPrivileges","hwnd",$hToken,"int",0, _
    "ptr",DllStructGetPtr($TOKEN_PRIVILEGES),"int",DllStructGetSize($NEWTOKEN_PRIVILEGES), _
    "ptr",DllStructGetPtr($NEWTOKEN_PRIVILEGES),"int_ptr",0)
    $f = DLLCall("kernel32.dll","int","GetLastError")
    EndIf
    $NEWTOKEN_PRIVILEGES=0
    $TOKEN_PRIVILEGES=0
    $LUID=0
    If $SP_auxret[0] = 0 Then Return 0
    $SP_auxret = DLLCall("kernel32.dll","int","CloseHandle","hwnd",$hToken)
    If Not $ret[0] And Not $SP_auxret[0] Then Return 0
    return $ret[0]
    EndFunc ;==>SetPrivilege

    [/autoit]
  • jo setz mich jetzt ran es geht ja net umd die rechte sondern erst mal um die konvertierung von pointer zu adresse

    so...:

    bin jetzt glaub nen schritt weiter ich hab jetztmal so umgeschrieben:

    Spoiler anzeigen
    [autoit]


    #include <NomadMemory.au3>
    SetPrivilege("SeDebugPrivilege", 1)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $adr = 0x006936A8
    Dim $off[2]
    $off[0] = 0
    $off[1] = 36

    [/autoit] [autoit][/autoit] [autoit]

    $gamepid = ProcessExists("TRose.exe")
    $gamehandle = _MemoryOpen($gamepid)
    $value = _MemoryPointerRead($adr, $gamehandle, $off)
    _MemoryClose($gamepid)

    [/autoit] [autoit][/autoit] [autoit]

    MsgBox(0,"",$value[0])

    [/autoit]

    was ich hier aber net verstehe ist, wieso ändert sich die adresse wenn man bei $off einfach nen array addiert??
    d.h. wenn ich sage

    [autoit]


    Dim $off[1]
    $off[0] = 36

    [/autoit]

    kommt was anderes raus als bei

    [autoit]


    Dim $off[2]
    $off[0] = 0
    $off[1] = 36

    [/autoit]

    das verstehe ich nicht...
    beim unteren kommt was ähnliches wie die Adresse raus!
    das kommt bei meinem script raus: 0x097FF774
    und cheat engine sagt: 0x097FF786

    EDIT:

    beim cheat engine tutorial hats geklappt komisch.. ich versteh da smit dne offsets noch nicht so ganz

    2 Mal editiert, zuletzt von I3iLLiG (26. November 2008 um 19:45)

  • omg ich glaub ich habs hinbekomm ich machn restart...

    ok es ging wenn s mir auch nochn bisschen schleierhaft bleibt^^

    Spoiler anzeigen
    [autoit]


    #include <NomadMemory.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $TRose = _memoryopen(WinGetProcess("ROSE online"))
    Global Const $Pointer = _Memoryread(0x006936A8 , $TRose,'dword')

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    msgbox(0,"",$pointer); 159092336 (+54)

    [/autoit] [autoit][/autoit] [autoit]

    #cs
    Von 159092336 bis 159092390 ist die Differenz 54
    159092390 hab ich mir einfach in CheatEnginge anzeigen lassen...
    #ce

    [/autoit] [autoit][/autoit] [autoit]

    $Offsetoutput = "0x" & hex($Pointer + 54); should be 159092390
    $Text = _MemoryRead($Offsetoutput , $TRose, 'dword')

    [/autoit] [autoit][/autoit] [autoit]

    MsgBox(0,"text",$text)

    [/autoit]

    Einmal editiert, zuletzt von I3iLLiG (26. November 2008 um 20:10)