Scanner la mémoire sur une plage d'offset défini

Contenu du snippet

Cette source vous permet de scanner la mémoire à partir de l'offset X jusqu'à l'offset Y et la met dans un fichier Z.
Si vous voulez laisser un commentaire vous les êtes le bienvenue du moment que c'est constructif :-)

Source / Exemple :


'Mettez tout dans votre Form
'---------------- Déclaration des divers fonction necessaire pour lire la mémoire--------------
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Declare Function Sleep Lib "kernel32" (ByVal DureeMS As Long)

Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal Classname As String, ByVal WindowName As String) As Long
Private Declare Function ReadProcessMem Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByRef lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long

Private Function WriteAByte(gamewindowtext As String, address As Long, value As Byte)
Dim hwnd As Long
Dim pid As Long
Dim phandle As Long
hwnd = FindWindow(vbNullString, gamewindowtext)
If (hwnd = 0) Then
Exit Function
End If
GetWindowThreadProcessId hwnd, pid
phandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
If (phandle = 0) Then
Exit Function
End If
WriteProcessMemory phandle, address, value, 1, 0&
CloseHandle hProcess
End Function

Private Function WriteAnInt(gamewindowtext As String, address As Long, value As Integer)
Dim hwnd As Long
Dim pid As Long
Dim phandle As Long
hwnd = FindWindow(vbNullString, gamewindowtext)
If (hwnd = 0) Then
Exit Function
End If
GetWindowThreadProcessId hwnd, pid
phandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
If (phandle = 0) Then
Exit Function
End If
WriteProcessMemory phandle, address, value, 2, 0&
CloseHandle hProcess
End Function

Private Function WriteALong(gamewindowtext As String, address As Long, value As Long)
Dim hwnd As Long
Dim pid As Long
Dim phandle As Long
hwnd = FindWindow(vbNullString, gamewindowtext)
If (hwnd = 0) Then
Exit Function
End If
GetWindowThreadProcessId hwnd, pid
phandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
If (phandle = 0) Then
Exit Function
End If
WriteProcessMemory phandle, address, value, 4, 0&
CloseHandle hProcess
End Function

Private Function ReadAByte(gamewindowtext As String, address As Long, valbuffer As Byte)
Dim hwnd As Long
Dim pid As Long
Dim phandle As Long
hwnd = FindWindow(vbNullString, gamewindowtext)
If (hwnd = 0) Then
Exit Function
End If
GetWindowThreadProcessId hwnd, pid
phandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
If (phandle = 0) Then
Exit Function
End If
ReadProcessMem phandle, address, valbuffer, 1, 0&
CloseHandle hProcess
End Function

Private Function ReadAnInt(gamewindowtext As String, address As Long, valbuffer As Integer)
Dim hwnd As Long
Dim pid As Long
Dim phandle As Long
hwnd = FindWindow(vbNullString, gamewindowtext)
If (hwnd = 0) Then
Exit Function
End If
GetWindowThreadProcessId hwnd, pid
phandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
If (phandle = 0) Then
Exit Function
End If
ReadProcessMem phandle, address, valbuffer, 2, 0&
CloseHandle hProcess
End Function

Private Function ReadAShort(gamewindowtext As String, address As Long, valbuffer As Integer)
Dim hwnd As Long
Dim pid As Long
Dim phandle As Long
hwnd = FindWindow(vbNullString, gamewindowtext)
If (hwnd = 0) Then
Exit Function
End If
GetWindowThreadProcessId hwnd, pid
phandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
If (phandle = 0) Then
Exit Function
End If
ReadProcessMem phandle, address, valbuffer, 2, 0&
CloseHandle hProcess
End Function

Private Function ReadALong(gamewindowtext As String, address As Long, valbuffer As Long)
Dim hwnd As Long
Dim pid As Long
Dim phandle As Long
hwnd = FindWindow(vbNullString, gamewindowtext)
If (hwnd = 0) Then
Exit Function
End If
GetWindowThreadProcessId hwnd, pid
phandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
If (phandle = 0) Then
Exit Function
End If
ReadProcessMem phandle, address, valbuffer, 4, 0&
CloseHandle hProcess
End Function

'Là on va commencer à s'attaquer à lire la mémoire et à changer l'offset à chaque fois
'(attention si jamais votre plage de scan est trop grande vous allez ramer...)

Private Sub Command1_Click()
Dim valeurhex1, valeurhex2, valeurhex3, valeurhex4, valeurhex5, valeurhex6, valeurhex7, value, offsettemp As Variant

offsettemp = "00000021" 'Offset de départ, vous pouvez le changer à votre guise

While offsettemp <> "000FFFFF" 'On arrête de scanner à cet offset

    Call ReadAnInt("NomDeL'application", offsettemp, value)
    Sleep 1& 'permet de libérer offsettemp, sinon il ne peut pas actualiser la valeur étant
    'donné qu'il est en cours d'utilisation.
    'Notez bien que j'ai rajouté Private Declare Function Sleep Lib "kernel32" (ByVal DureeMS 
    'As Long) dans les déclarations

    'Remplacez NomDeL'application par le nom de votre application (logique), laissez
    'Laissez offsettemp, value comme ils sont. Offsettemp est l'offset (qui augmente à chaque
    'fois grace au code çi-dessous) et value est la valeur de l'offset actuel.
    
    Open App.Path & "resultat.txt" For Append As #1
    Print #1, offsettemp & " : " & value
    Close #1

    valeurhex1 = Mid$(offsettemp, 8, 1) 'Récupère la dernier chiffre de offsettemp (1)
    valeurhex2 = Mid$(offsettemp, 7, 1) 'Récupère la dernier chiffre de offsettemp (2)
    valeurhex3 = Mid$(offsettemp, 6, 1) 'Récupère la dernier chiffre de offsettemp (0)
    valeurhex4 = Mid$(offsettemp, 5, 1) '...
    valeurhex5 = Mid$(offsettemp, 4, 1)
    valeurhex6 = Mid$(offsettemp, 3, 1)
    valeurhex7 = Mid$(offsettemp, 2, 1)
    
    'On commence à changer d'offsets, ici c'est le dernier chiffre (1 au départ)
    If valeurhex1 = "F" Then valeurhex1 = "G"
    If valeurhex1 = "E" Then valeurhex1 = "F"
    If valeurhex1 = "D" Then valeurhex1 = "E"
    If valeurhex1 = "C" Then valeurhex1 = "D"
    If valeurhex1 = "B" Then valeurhex1 = "C"
    If valeurhex1 = "A" Then valeurhex1 = "B"
    If valeurhex1 = "9" Then valeurhex1 = "A"
    If IsNumeric(valeurhex1) Then valeurhex1 = valeurhex1 + 1
    If valeurhex1 = "G" Then
    valeurhex1 = 0
        
        'Avant dernier chiffre (2 au départ)
        If valeurhex2 = "F" Then valeurhex2 = "G"
        If valeurhex2 = "E" Then valeurhex2 = "F"
        If valeurhex2 = "D" Then valeurhex2 = "E"
        If valeurhex2 = "C" Then valeurhex2 = "D"
        If valeurhex2 = "B" Then valeurhex2 = "C"
        If valeurhex2 = "A" Then valeurhex2 = "B"
        If valeurhex2 = "9" Then valeurhex2 = "A"
        If IsNumeric(valeurhex2) Then valeurhex2 = valeurhex2 + 1
        If valeurhex2 = "G" Then
        valeurhex2 = 0

            'Ainsi de suite ...
            If valeurhex3 = "F" Then valeurhex3 = "G"
            If valeurhex3 = "E" Then valeurhex3 = "F"
            If valeurhex3 = "D" Then valeurhex3 = "E"
            If valeurhex3 = "C" Then valeurhex3 = "D"
            If valeurhex3 = "B" Then valeurhex3 = "C"
            If valeurhex3 = "A" Then valeurhex3 = "B"
            If valeurhex3 = "9" Then valeurhex3 = "A"
            If IsNumeric(valeurhex3) Then valeurhex3 = valeurhex3 + 1
            If valeurhex3 = "G" Then
            valeurhex3 = 0
        
                If valeurhex4 = "F" Then valeurhex4 = "G"
                If valeurhex4 = "E" Then valeurhex4 = "F"
                If valeurhex4 = "D" Then valeurhex4 = "E"
                If valeurhex4 = "C" Then valeurhex4 = "D"
                If valeurhex4 = "B" Then valeurhex4 = "C"
                If valeurhex4 = "A" Then valeurhex4 = "B"
                If valeurhex4 = "9" Then valeurhex4 = "A"
                If IsNumeric(valeurhex4) Then valeurhex4 = valeurhex4 + 1
                If valeurhex4 = "G" Then
                valeurhex4 = 0
                
                    If valeurhex5 = "F" Then valeurhex5 = "G"
                    If valeurhex5 = "E" Then valeurhex5 = "F"
                    If valeurhex5 = "D" Then valeurhex5 = "E"
                    If valeurhex5 = "C" Then valeurhex5 = "D"
                    If valeurhex5 = "B" Then valeurhex5 = "C"
                    If valeurhex5 = "A" Then valeurhex5 = "B"
                    If valeurhex5 = 9 Then valeurhex5 = "A"
                    If IsNumeric(valeurhex5) Then valeurhex5 = valeurhex5 + 1
                    If valeurhex5 = "G" Then
                    valeurhex5 = 0
                    MsgBox "blabl"
                    Exit Sub
                        If valeurhex6 = "F" Then valeurhex6 = "G"
                        If valeurhex6 = "E" Then valeurhex6 = "F"
                        If valeurhex6 = "D" Then valeurhex6 = "E"
                        If valeurhex6 = "C" Then valeurhex6 = "D"
                        If valeurhex6 = "B" Then valeurhex6 = "C"
                        If valeurhex6 = "A" Then valeurhex6 = "B"
                        If valeurhex6 = 9 Then valeurhex6 = "A"
                        If IsNumeric(valeurhex6) Then valeurhex6 = valeurhex6 + 1
                        If valeurhex6 = "G" Then
                        valeurhex6 = 0
                        
                            If valeurhex7 = "F" Then valeurhex7 = "G"
                            If valeurhex7 = "E" Then valeurhex7 = "F"
                            If valeurhex7 = "D" Then valeurhex7 = "E"
                            If valeurhex7 = "C" Then valeurhex7 = "D"
                            If valeurhex7 = "B" Then valeurhex7 = "C"
                            If valeurhex7 = "A" Then valeurhex7 = "B"
                            If valeurhex7 = 9 Then valeurhex7 = "A"
                            If IsNumeric(valeurhex7) Then valeurhex7 = valeurhex7 + 1
                            If valeurhex7 = "G" Then
                            valeurhex7 = 0
                            valeurhex6 = 0
                            valeurhex5 = 0
                            valeurhex4 = 0
                            valeurhex3 = 0
                            valeurhex2 = 0
                            valeurhex1 = 0
                            Exit Sub
                            End If
                        End If
                    End If
                End If
            End If
        End If
    End If

    offsettemp = "1" & valeurhex7 & valeurhex6 & valeurhex5 & valeurhex4 & valeurhex3 & valeurhex2 & valeurhex1

Wend

Conclusion :


Je n'ai pas mis pas la 8eme valeur de l'offset à cause du lag causé par un scan trop grand...

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.