ModulBase unter Windows7

  • Ich versuche aus einem Prozess die Modulbase und die Länge durch eine Funktion, die ich bekommen habe, herauszufinden. Auf meinem Notebook habe ich Windows7, auf meinem alten Rechner XP. Die FUnktion sieht so aus:

    Spoiler anzeigen
    [autoit]

    Func _GetModuleBaseByName($pid, $module)
    Local $hSnapshot, $me32, $bFound, $baseAddress[3]
    $me32 = DllStructCreate("int;int;int;int;int;int;int;int;char[256];char[260]")
    DllStructSetData($me32,1,DllStructGetSize($me32))
    $hSnapshot = DllCall("kernel32.dll","hwnd","CreateToolhelp32Snapshot","int",8,"int",$pid)
    If $hSnapshot[0] = -1 Then Return 0

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

    $bFound = DllCall("kernel32.dll","int","Module32First","hwnd",$hSnapshot[0],"ptr",DllStructGetPtr($me32))
    If $bFound[0] Then
    Do
    If StringLower(DllStructGetData($me32,9)) = StringLower($module) Then
    $baseAddress[1] = DllStructGetData($me32,6)
    $baseAddress[2] = DllStructGetData($me32,7)
    ExitLoop
    EndIf
    $bFound = DllCall("kernel32.dll","int","Module32Next","hwnd",$hSnapshot[0],"ptr",DllStructGetPtr($me32))
    Until Not $bFound[0]
    EndIf
    DllCall("kernel32.dll","int","CloseHandle","int",$hSnapshot[0])
    Return $baseAddress
    EndFunc

    [/autoit]


    Das Problem: Unter Win7 wird nichts returned. Unter XP mit genau demselben Code funktioniert es.
    Unter Win7 scheitert die Funktion an diesem DLL Call

    [autoit]

    $bFound = DllCall("kernel32.dll","int","Module32First","hwnd",$hSnapshot[0],"ptr",DllStructGetPtr($me32))

    [/autoit]


    Denn $bFound[0] ist gleich 0 und nicht 1.

    Was ist das Problem unter Win7. Kann man die Funktion irgendwie so umschreiben, dass sie sowohl unter Win7 als auch noch unter Vista und XP läuft?

    Einmal editiert, zuletzt von NoName (9. Juli 2009 um 23:31)

  • Vielleicht gibt es diese Dll/Eintrag nicht .....

    man kann alles versuchen umzuschreiben :)

    Ruf doch mal bei Microsoft an :rofl: ==> nich böse sein :)

  • Wenn der DLL-Eintrag nicht existiert, würde $bFound wohl kaum ein Array sein >.>

    Einmal editiert, zuletzt von NoName (8. Juli 2009 um 20:04)

  • Ich hab keine wirkliche Ahnung, warum es nicht geht. Versuch aber mal die Unicode-Version ;)

    Spoiler anzeigen
    [autoit]

    Func _GetModuleBaseByName($pid, $module)
    Local $hSnapshot, $me32, $bFound, $baseAddress[3]
    $me32 = DllStructCreate("int;int;int;int;int;ptr;int;ptr;wchar[256];wchar[260]")
    DllStructSetData($me32,1,DllStructGetSize($me32))
    $hSnapshot = DllCall("kernel32.dll","hwnd","CreateToolhelp32Snapshot","int",8,"int",$pid)
    If $hSnapshot[0] = -1 Then Return 0

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

    $bFound = DllCall("kernel32.dll","int","Module32FirstW","hwnd",$hSnapshot[0],"ptr",DllStructGetPtr($me32))
    If $bFound[0] Then
    Do
    If StringLower(DllStructGetData($me32,9)) = StringLower($module) Or $module=="" Then
    $baseAddress[1] = DllStructGetData($me32,6)
    $baseAddress[2] = DllStructGetData($me32,7)
    ExitLoop
    EndIf
    $bFound = DllCall("kernel32.dll","int","Module32NextW","hwnd",$hSnapshot[0],"ptr",DllStructGetPtr($me32))
    Until Not $bFound[0]
    EndIf
    DllCall("kernel32.dll","int","CloseHandle","int",$hSnapshot[0])
    Return $baseAddress
    EndFunc
    $a = _GetModuleBaseByName(@AutoItPID,"")
    MsgBox(0, '', @error & @CRLF & $a[1] & @CRLF & $a[2])

    [/autoit]


    Oder es ist vielleicht ein 32 / 64 bit- Problem. Teste doch einfach mal die verschiedenen Parameter für CreateToolhelp32Snapshot.

  • Also, die Unicodeversion habe ich auch schon benutzt, nur die hat genauso wenig geklappt. Allerdings bei dir wird etwas returned, also Adresse + Size. Wenn ich jetzt als Module wieder etwas angebe findet er wiederum auch mit Unicode nichts mehr...

    Ich habe den Parameter in der Spanshotfunktion geändert und auf einmal gings. Dann habe ich ihn probeweise zurückgemacht und es ging immernoch. Ich weiß zwar nicht warum, weil die Funktion sonst nicht anders aussieht, aber irgendwie klappt es jetzt >.>

    Danke jedenfalls.

    MfG

    Einmal editiert, zuletzt von NoName (9. Juli 2009 um 23:30)