misc: making a trainer in vb6

Post here about scripting and programming for HaloPC (audio, network, ai, etc.)
Post Reply
modder4321





Posts: 118
Joined: Wed Mar 30, 2005 5:35 pm

misc: making a trainer in vb6

Post by modder4321 »

well i saw a tut on how to make a trainer with tmk(sucks) so heres a tut on how to make it in vb6 instead

1. make a form
2. create a button u change the caption to "set" make a text box and a label and have the label say score.
3. here is the code u need in the module

Code: Select all

Private Const PROCESS_ALL_ACCESS As Long = &H1F0FFF

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 ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal 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
ok these are the api's
Private Const PROCESS_ALL_ACCESS As Long = &H1F0FFF
isnt an api but is a value later used for attaching to the process

then u have Private Declare Function GetWindowThreadProcessId Lib "User32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long which gets the process id

next Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
which allows are trainer to attach to the process

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
allows the trainer to write a value to an address

Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
which instead of writing reads a value from a address

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
releases handle from teh program(pinball)

Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal Classname As String, ByVal WindowName As String) As Long
allows are program to find the window so it can attach to the program(pinball)

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
another api to read memory from the program(pinball)

Code: Select all

'||-------------------------------------------------------------------------------------------------||
'|| The two next functions read\write BYTE values.                                                  ||
'|| BYTE is an 8-bit datatype that can store values from 0 to 255.                                  ||
'||-------------------------------------------------------------------------------------------------||

Public Function ReadByte(Offset As Long, WindowName As String) As Byte

    Dim hwnd As Long
    Dim ProcessID As Long
    Dim ProcessHandle As Long
    Dim Value As Byte
    
    'Try to find the window that was passed in the variable WindowName to this function.
    hwnd = FindWindow(vbNullString, WindowName)
    
    If hwnd = 0 Then
        
        'This is executed if the window cannot be found.
        'You can add or write own code here to customize your program.
        
        MsgBox "Could not find process window!", vbCritical, "Read error"
        
        Exit Function
    
    End If
    
    'Get the window's process ID.
    GetWindowThreadProcessId hwnd, ProcessID
    
    'Get a process handle.
    ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, False, ProcessID)
    
    If ProcessHandle = 0 Then
        
        'This is executed if a process handle cannot be found.
        'You can add or write your own code here to customize your program.
        
        MsgBox "Could not get a process handle!", vbCritical, "Read error"
        
        Exit Function
    
    End If

    
    'Read a BYTE value from the specified memory offset.
    ReadProcessMem ProcessHandle, Offset, Value, 1, 0&
    
    'Return the found memory value.
    ReadByte = Value
    
    'It is important to close the current process handle.
    CloseHandle ProcessHandle
           
End Function

Public Function WriteByte(Offset As Long, WindowName As String, Value As Byte) As Boolean

    Dim hwnd As Long
    Dim ProcessID As Long
    Dim ProcessHandle As Long
    
    'Try to find the window that was passed in the variable WindowName to this function.
    hwnd = FindWindow(vbNullString, WindowName)
    
    If hwnd = 0 Then
        
        'This is executed if the window cannot be found.
        'You can add or write own code here to customize your program.
        
        MsgBox "Could not find process window!", vbCritical, "Write error"
        
        Exit Function
    
    End If
    
    'Get the window's process ID.
    GetWindowThreadProcessId hwnd, ProcessID
    
    'Get a process handle.
    ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, False, ProcessID)
    
    If ProcessHandle = 0 Then
        
        'This is executed if a process handle cannot be found.
        'You can add or write your own code here to customize your program.
        
        MsgBox "Could not get a process handle!", vbCritical, "Write error"
        
        Exit Function
    
    End If
    
    'Write a specified BYTE value to the specified memory offset.
    WriteProcessMemory ProcessHandle, Offset, Value, 1, 0&
    
    'It is important to close the current process handle.
    CloseHandle ProcessHandle
    
End Function


'||-------------------------------------------------------------------------------------------------||
'|| The two next functions read\write INTEGER values.                                               ||
'|| INTEGER is a 16-bit(2 byte) datatype and can store values from -32768 to 32767                  ||
'||-------------------------------------------------------------------------------------------------||

Public Function ReadInteger(Offset As Long, WindowName As String) As Integer

    Dim hwnd As Long
    Dim ProcessID As Long
    Dim ProcessHandle As Long
    Dim Value As Integer
    
    'Try to find the window that was passed in the variable WindowName to this function.
    hwnd = FindWindow(vbNullString, WindowName)
    
    If hwnd = 0 Then
        
        'This is executed if the window cannot be found.
        'You can add or write your own code here to customize your program.
        
        MsgBox "Could not find process window!", vbCritical, "Read error"
            
        Exit Function
    
    End If
    
    'Get the window's process ID.
    GetWindowThreadProcessId hwnd, ProcessID
    
    'Get a process handle.
    ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, False, ProcessID)
    
    If ProcessHandle = 0 Then

        'This is executed if a process handle cannot be found.
        'You can add or write your own code here to customize your program.

        MsgBox "Could not get a process handle!", vbCritical, "Read error"
        
        Exit Function
        
    End If
    
    'Read an INTEGER value from the specified memory offset.
    ReadProcessMem ProcessHandle, Offset, Value, 2, 0&
    
    'Return the found memory value.
    ReadInteger = Value
    
    'It is important to close the current process handle.
    CloseHandle ProcessHandle
    
End Function

Public Function WriteInteger(Offset As Long, WindowName As String, Value As Integer) As Boolean

    Dim hwnd As Long
    Dim ProcessID As Long
    Dim ProcessHandle As Long
    
    'Try to find the window that was passed in the variable WindowName to this function.
    hwnd = FindWindow(vbNullString, WindowName)
    
    If hwnd = 0 Then
    
        'This is executed if the window cannot be found.
        'You can add or write your own code here to customize your program.
        
        MsgBox "Could not find process window!", vbCritical, "Write error"
        
        Exit Function
    
    End If
    
    'Get the window's process ID.
    GetWindowThreadProcessId hwnd, ProcessID
    
    'Get a process handle.
    ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, False, ProcessID)
    
    If ProcessHandle = 0 Then
    
        'This is executed if a process handle cannot be found.
        'You can add or write your own code here to customize your program.
    
        MsgBox "Could not get a process handle!", vbCritical, "Write error"
        
        Exit Function
        
    End If
    
    'Write a specified INTEGER value to the specified memory offset.
    WriteProcessMemory ProcessHandle, Offset, Value, 2, 0&
    
    'It is important to close the current process handle.
    CloseHandle ProcessHandle
    
End Function


'||-------------------------------------------------------------------------------------------------||
'|| The two next functions read\write LONG values.                                                  ||
'|| LONG is a 32-bit(4 byte) datatype and can store values from -2,147,483,648 to 2,147,483,647     ||
'||-------------------------------------------------------------------------------------------------||

Public Function ReadLong(Offset As Long, WindowName As String) As Long

    Dim hwnd As Long
    Dim ProcessID As Long
    Dim ProcessHandle As Long
    Dim Value As Long
    
    'Try to find the window that was passed in the variable WindowName to this function.
    hwnd = FindWindow(vbNullString, WindowName)
    
    If hwnd = 0 Then
    
            'This is executed if the window cannot be found.
            'You can add or write your own code here to customize your program.
                        
            MsgBox "Could not find process window!", vbCritical, "Read error"
            
            Exit Function
        
    End If
    
    'Get the window's process ID.
    GetWindowThreadProcessId hwnd, ProcessID
    
    'Get a process handle
    ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, False, ProcessID)
    
    If ProcessHandle = 0 Then
    
        'This is executed if a process handle cannot be found.
        'You can add or write your own code here to customize your program.
    
        MsgBox "Could not get a process handle!", vbCritical, "Read error"
        
        Exit Function
        
    End If
    
    'Read a LONG from the specified memory offset.
    ReadProcessMem ProcessHandle, Offset, Value, 4, 0&
    
    'Return the found memory value.
    ReadLong = Value
    
    'It is important to close the current process handle.
    CloseHandle ProcessHandle
    
End Function

Public Function WriteLong(Offset As Long, WindowName As String, Value As Long) As Boolean

    Dim hwnd As Long
    Dim ProcessID As Long
    Dim ProcessHandle As Long
    
    'Try to find the window that was passed in the variable WindowName to this function.
    hwnd = FindWindow(vbNullString, WindowName)
    
    If hwnd = 0 Then
    
            'This is executed if the window cannot be found.
            'You can add or write your own code here to customize your program.
                        
            MsgBox "Could not find process window!", vbCritical, "Write error"
            
            Exit Function
        
    End If
    
    'Get the window's process ID.
    GetWindowThreadProcessId hwnd, ProcessID
    
    'Get a process handle
    ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, False, ProcessID)
    
    If ProcessHandle = 0 Then
    
        'This is executed if a process handle cannot be found.
        'You can add or write your own code here to customize your program.
    
        MsgBox "Could not get a process handle!", vbCritical, "Write error"
        
        Exit Function
        
    End If
    
    'Read a LONG from the specified memory offset.
    WriteProcessMemory ProcessHandle, Offset, Value, 4, 0&

    'It is important to close the current process handle.
    CloseHandle ProcessHandle

End Function




Public Function Readstring(Offset As Long, WindowName As String) As Long

    Dim hwnd As Long
    Dim ProcessID As Long
    Dim ProcessHandle As Long
    Dim Value As String
    
    'Try to find the window that was passed in the variable WindowName to this function.
    hwnd = FindWindow(vbNullString, WindowName)
    
    If hwnd = 0 Then
    
            'This is executed if the window cannot be found.
            'You can add or write your own code here to customize your program.
                        
            MsgBox "Could not find process window!", vbCritical, "Read error"
            
            Exit Function
        
    End If
    
    'Get the window's process ID.
    GetWindowThreadProcessId hwnd, ProcessID
    
    'Get a process handle
    ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, False, ProcessID)
    
    If ProcessHandle = 0 Then
    
        'This is executed if a process handle cannot be found.
        'You can add or write your own code here to customize your program.
    
        MsgBox "Could not get a process handle!", vbCritical, "Read error"
        
        Exit Function
        
    End If
    
    'Read a LONG from the specified memory offset.
    ReadProcessMem ProcessHandle, Offset, Value, 4, 0&
    
    'Return the found memory value.
    ReadLong = Value
    
    'It is important to close the current process handle.
    CloseHandle ProcessHandle
    
End Function

Public Function Writestring(Offset As Long, WindowName As String, Value As String) As Boolean

    Dim hwnd As Long
    Dim ProcessID As Long
    Dim ProcessHandle As Long
    
    'Try to find the window that was passed in the variable WindowName to this function.
    hwnd = FindWindow(vbNullString, WindowName)
    
    If hwnd = 0 Then
    
            'This is executed if the window cannot be found.
            'You can add or write your own code here to customize your program.
                        
            MsgBox "Could not find process window!", vbCritical, "Write error"
            
            Exit Function
        
    End If
    
    'Get the window's process ID.
    GetWindowThreadProcessId hwnd, ProcessID
    
    'Get a process handle
    ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, False, ProcessID)
    
    If ProcessHandle = 0 Then
    
        'This is executed if a process handle cannot be found.
        'You can add or write your own code here to customize your program.
    
        MsgBox "Could not get a process handle!", vbCritical, "Write error"
        
        Exit Function
        
    End If
    
    'Read a LONG from the specified memory offset.
    WriteProcessMemory ProcessHandle, Offset, Value, 4, 0&

    'It is important to close the current process handle.
    CloseHandle ProcessHandle

End Function
4. now double click on the command button and type in

Code: Select all

Private Sub Command1_Click()
WriteLong &HB00C62, "3d pinball for windows - space cadet", Text1.Text
End Sub

ok i explained the api's and tomorrow i will explain the rest right now i g2g school tomorrow
Last edited by modder4321 on Sun Sep 11, 2005 5:00 pm, edited 2 times in total.
User avatar
Excal




Socialist Pyre

Posts: 1779
Joined: Fri Jan 02, 2004 9:55 am
Location: Bronx, NY

Post by Excal »

Well you didn't really teach anybody anything... more like gave us the source code.
Image
User avatar
Locke




Socialist Advisor Translator

Posts: 2225
Joined: Fri Aug 06, 2004 1:42 am
Location: Woot.com
Contact:

Post by Locke »

Excalibur wrote:Well you didn't really teach anybody anything... more like gave us the source code.
Thats because its not his code. He cant explain any of it. All he can do is show us the code of someone elses work.
Image
Feel free to send me an instant message if you need anything.
modder4321





Posts: 118
Joined: Wed Mar 30, 2005 5:35 pm

Post by modder4321 »

well if u want me to i can explain each part of it
User avatar
kornman00




ONI New Age

Posts: 146
Joined: Fri Dec 12, 2003 6:30 pm
Contact:

Post by kornman00 »

LOL @ that code...
Post Reply