Hallöchen zusammen. Ich werkle schon seit Tagen daran und hole mir jegliche Unterstützung.... Google kennt meine Suchbegriffe langsam auch schon auswendig, ich komme nicht zum Ergebnis.
Ich möcht in VB.NET die Adresse einer DLL auslesen und zwar mit der Funktion GetModuleBaseAddress()....
Bin schon die ganze Zeit am Versuchen aber nix da... kein Plan... nix läuft. Ich glaube ich spring aus dem Fenster wenn das mal klappt... (vor Freude, versteht sich) so viel Zeit in den Scheiß investiert und ich bin nochimmer zu keinem Ergebnis gekommen.
Kann mir da jemand helfen...... [img]/sad.gif[/img] [img]/sad.gif[/img]
Auch schon versucht das nach VB.NET zu übersetzen nur weiß ich nicht so richtig, wie das mit dem MODULEENTRY32 ist, ich komm auch nicht weit weil mich immer eine "AccessViolationException" daran hindert...........................
Ich akzeptiere Hilfe in allen Varianten.................................................................*verzweifel*
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
KleinesVoodoo Coder
Anmeldedatum: 17.04.2008 Beiträge: 78
Verfasst am: 22.05.2008, 20:16
Der Typ ist dieser:
Visual Basic: [code]Private Type MODULEENTRY32 dwSize As Long th32ModuleID As Long th32ProcessID As Long GlblcntUsage As Long ProccntUsage As Long modBaseAddr As Long modBaseSize As Long hModule As Long szModule As String * MAX_MODULE_NAME32 szExeFile As String * MAX_PATH End Type[/code] Die eine Konstante diese:
Visual Basic: [code] Private Const TH32CS_SNAPMODULE As Long = &H8 [/code] Nun kannst du übersetzen, oder?
// Edit //
Falls du Probleme mit den Datentypen hast, nimm Long statt DWORD und HANDLE und String statt Char.
// Edit //
Ich übersetze die Funktion eben für dich.
Visual Basic: [code]Function GetModuleBaseAddress(ByVal iProcId As Long, ByVal DLLName As String) As Long Dim hSnap As Long Dim xModule As MODULEENTRY32
If Module32First(hSnap, xModule) Then Do While Module32Next(hSnap, xModule) If xModule.szModule = DLLName Then CloseHandle(hSnap) GetModuleBaseAddress = xModule.modBaseAddr Exit Function End If Loop End If
CloseHandle(hSnap) GetModuleBaseAddress = 0 End Function[/code]
x0X0x Newbie
Anmeldedatum: 02.05.2008 Beiträge: 12
Verfasst am: 23.05.2008, 14:52
(c0re;2704)
Der Typ ist dieser:
Visual Basic: [code]Private Type MODULEENTRY32 dwSize As Long th32ModuleID As Long th32ProcessID As Long GlblcntUsage As Long ProccntUsage As Long modBaseAddr As Long modBaseSize As Long hModule As Long szModule As String * MAX_MODULE_NAME32 szExeFile As String * MAX_PATH End Type[/code]
Danke für die Übersetzung, ich hatte es ziemlich ähnlich und bin auch auf den zitierten Teil im Internet gestoßen nur haut das nicht so hin. Also entweder weiß ich nicht wo diese Methode (bin mir nicht mal sicher ob´s eine ist) rein soll, oder das ist nicht für VB .Net gesehen... Abgesehen davon, dass Private Type laut meinem Compiler nicht mehr unterstützt wird und ich stattdessen "Structure" anwenden soll, ist ihm die Deklarationsart der Variablen auch völlig fremd.... ("Deklaration erwartet.") Weiters kann weder ich, noch mein Compiler mir nicht erklären was der folgende Teil hier machen soll.
Visual Basic: [code]szModule As String * MAX_MODULE_NAME32 szExeFile As String * MAX_PATH [/code]
Ich nehme an ich werde einfach ein einfaches "Dim" vor alle Deklarationen hauen um das halbwegs hinzubiegen, wobei ich dann immer noch das Problem mit den letzten Zwei Strings habe.... bitte um Hilfe.
Vielen Dank für die Antworten sag ich schon mal. Schöne Grüße, x0X0x
KleinesVoodoo Coder
Anmeldedatum: 17.04.2008 Beiträge: 78
Verfasst am: 24.05.2008, 18:44
Ja, die Typendeklaration in VB.NET sieht ein Wenig anders aus. Habe nicht auf die Sektion geachtet, tut mir Leid.
Visual Basic: [code]Private Structure MODULEENTRY32 Dim dwSize As Long Dim th32ModuleID As Long Dim th32ProcessID As Long Dim GlblcntUsage As Long Dim ProccntUsage As Long Dim modBaseAddr As Long Dim modBaseSize As Long Dim hModule As Long Dim szModule As String * MAX_MODULE_NAME32 Dim szExeFile As String * MAX_PATH End Structure[/code] Außerdem fehlen dir noch die Konstanten MAX_MODULE_NAME32 und MAX_PATH. Das sind diese:
Die Funktion oben hatte 'nen kleinen Fehler. Hab den Post oben aber auch editiert.
// Edit //
Diese Stringerweiterung brauchst du nicht. Sie ist aus diesem Grund in VB.NET sogar gar nicht mehr möglich. Ich glaube, das Limit ist seit dem .NET Framework aufgehoben.
Nun kannst du die 2 Konstanten also weglassen. Der Typ sieht dann auch dementsprechend aus.
Visual Basic: [code]Private Structure MODULEENTRY32 Dim dwSize As Long Dim th32ModuleID As Long Dim th32ProcessID As Long Dim GlblcntUsage As Long Dim ProccntUsage As Long Dim modBaseAddr As Long Dim modBaseSize As Long Dim hModule As Long Dim szModule As String Dim szExeFile As String End Structure[/code]
// Edit //
Ach so, die APIs brauchst du ja auch noch.
Visual Basic: [code] _ Shared Function CloseHandle(ByVal hObject As Long) As Long End Function
_ Shared Function CreateToolhelp32Snapshot(ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long End Function
_ Shared Function Module32First(ByVal hSnapshot As Long, ByRef lppe As MODULEENTRY32) As Long End Function
_ Shared Function Module32Next(ByVal hSnapshot As Long, ByRef lpme As MODULEENTRY32) As Long End Function[/code] Und ganz oben im Codefenster noch eine Import.
_ Shared Function CloseHandle(ByVal hObject As Long) As Long End Function
_ Shared Function CreateToolhelp32Snapshot(ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long End Function
_ Shared Function Module32First(ByVal hSnapshot As Long, ByRef lppe As MODULEENTRY32) As Long End Function
_ Shared Function Module32Next(ByVal hSnapshot As Long, ByRef lpme As MODULEENTRY32) As Long End Function
Private Const TH32CS_SNAPMODULE As Long = &H8
Structure MODULEENTRY32 Dim dwSize As Long Dim th32ModuleID As Long Dim th32ProcessID As Long Dim GlblcntUsage As Long Dim ProccntUsage As Long Dim modBaseAddr As Long Dim modBaseSize As Long Dim hModule As Long Dim szModule As String Dim szExeFile As String End Structure
Function GetModuleBaseAddress(ByVal iProcId As Long, ByVal DLLName As String) As Long Dim hSnap As Long Dim xModule As MODULEENTRY32
If Module32First(hSnap, xModule) Then Do While Module32Next(hSnap, xModule) If xModule.szModule = DLLName Then CloseHandle(hSnap) GetModuleBaseAddress = xModule.modBaseAddr Exit Function End If Loop End If
CloseHandle(hSnap) GetModuleBaseAddress = 0 End Function
End Class[/code] Fertig.
x0X0x Newbie
Anmeldedatum: 02.05.2008 Beiträge: 12
Verfasst am: 24.05.2008, 22:34
Erstmal: Ich danke Dir für die bisherigen Antworten!
Das gleiche Problem hatte ich aber bisher schonmal...
Code:
Imports System.Runtime.InteropServices<br /><br />Public Class Form1<br /><br /> Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer<br /> Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Integer) As Integer<br /> Declare Function Module32Next Lib "kernel32.dll" (ByVal hSnapshot As Integer, ByRef lpme As MODULEENTRY32) As Integer<br /> Declare Function Module32First Lib "kernel32.dll" (ByVal hSnapshot As Integer, ByVal uProcess As MODULEENTRY32) As Integer<br /> Declare Function CreateToolhelp32Snapshot Lib "kernel32.dll" (ByVal dwFlags As Integer, ByVal th32ProcessID As Integer) As Integer<br /><br /> Const TH32CS_SNAPMODULE As Long = &H8<br /> Const PROCESS_ALL_ACCESS = &H1F0FFF<br /><br /> Dim myProcesses As Process()<br /> Dim processHandle As IntPtr<br /><br /> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br /> If Process.GetProcessesByName("BF2").Length = 0 Then<br /> MessageBox.Show("Prozess nicht gefunden, Programm wird beendet")<br /> Application.Exit()<br /> Exit Sub<br /> End If<br /><br /> myProcesses = Process.GetProcessesByName("BF2") 'keine Sorge, das Auslesen des Handles ist kein Problem, das klappt...<br /> processHandle = OpenProcess(PROCESS_ALL_ACCESS, 0, myProcesses(0).Id)<br /><br /> Button1.Text += " -" & processHandle.ToString()<br /> End Sub<br /><br /> Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click<br /> GetModuleBaseAddress(processHandle, "---.dll")<br /> End Sub<br /><br /> Public Structure MODULEENTRY32<br /> Dim dwSize As Long<br /> Dim th32ModuleID As Long<br /> Dim th32ProcessID As Long<br /> Dim GlblcntUsage As Long<br /> Dim ProccntUsage As Long<br /> Dim modBaseAddr As Long<br /> Dim modBaseSize As Long<br /> Dim hModule As Long<br /> Dim szModule As String<br /> Dim szExeFile As String<br /> End Structure<br /><br /> Public Function GetModuleBaseAddress(ByVal iProcId As Long, ByVal DLLName As String) As Long<br /> Dim hSnap As Long<br /> Dim xModule As MODULEENTRY32<br /><br /> hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, iProcId)<br /> xModule.dwSize = Len(xModule)<br /><br /> If Module32First(hSnap, xModule) Then<br /> Do While Module32Next(hSnap, xModule)<br /> If xModule.szModule = DLLName Then<br /> CloseHandle(hSnap)<br /> GetModuleBaseAddress = xModule.modBaseAddr<br /> Exit Function<br /> End If<br /> Loop<br /> End If<br /><br /> CloseHandle(hSnap)<br /> GetModuleBaseAddress = 0<br /> End Function<br /><br />End Class
Was da los? (passiert beim Aufruf der Methode GetModuleBaseAddress()...)
KleinesVoodoo Coder
Anmeldedatum: 17.04.2008 Beiträge: 78
Verfasst am: 25.05.2008, 16:02
Du wirst die Funktion warscheinlich nicht bei jeder Anwendung problemlos verwenden können. Klappt es denn mit der C++ Func?
x0X0x Newbie
Anmeldedatum: 02.05.2008 Beiträge: 12
Verfasst am: 25.05.2008, 17:18
Das kann ich Dir ehrlich gesagt nicht sagen, weil ich von C++ wenig bis keine Ahnung habe.. Aber diese Funktion in C++ ist aus einem Source der angeblich klappt. Ziel ist es die Adresse von RendDx9.dll vom Spiel Battlefield2 auszulesen.... schadet bestimmt nicht wenn ich das mal erwähne... Ich glaube aber dass da was nicht zu 100% eins zu eins übersetzt wurde, denn sonst müsste es ja klappen. Mir scheint als ob eine Variable nicht denselben "Wert" (Eigenschaften, etc.) haben würde wie sie in C++ normal haben sollte.
PS, Core, nimm bitte meine ICQ-Kontaktanfrage an.
KleinesVoodoo Coder
Anmeldedatum: 17.04.2008 Beiträge: 78
Verfasst am: 25.05.2008, 17:38
Ich hab' keine Kontaktanfrage bekommen. Lad dir doch mal 'nen Cpp Compiler und teste ob es mit der C++ Funktion funktioniert. _________________
x0X0x Newbie
Anmeldedatum: 02.05.2008 Beiträge: 12
Verfasst am: 26.05.2008, 20:58
Habe es testen lassen... An BF2.exe und an RendDx9.dll..... Klappte einwandfrei... [img]/sad.gif[/img]