Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Getting Base Address Module - VB6/VBA

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
ElBartoDeLaMurte
How do I cheat?
Reputation: 0

Joined: 13 Nov 2016
Posts: 2

PostPosted: Sun Nov 13, 2016 7:31 am    Post subject: Getting Base Address Module - VB6/VBA Reply with quote

Hi all,

Before everything else, I know VB6 is a dead language and it is now better to use .NET - C# - C++. No need to boo me. But i do it out of curiosity.

Here is a VB.Net code to get the base address of a module :

Code:
Function ReturnClient() As System.IntPtr
        Try
            Dim pc As Process = Process.GetProcessesByName("hl2")( 0 )
            For Each pm As ProcessModule In pc.Modules
                If pm.ModuleName = "client.dll" Then Return pm.BaseAddress
            Next
        Catch ex As Exception
            Return IntPtr.Zero
        End Try
    End Function


Do you guys know how i could do it with VB6? Because at the moment, the only thingi can do is dealing with processes, but not their modules....

See you soon guys
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sun Nov 13, 2016 1:32 pm    Post subject: Reply with quote

Here are two functions from my old trainer toolkit I wrote for VB6:
Code:

'-------------------------------------------------------------------------------------------
' Module Returns
'
' The following section of code contains functions used to obtain
' module information such as the size and base address of the loaded
' module inside the given process or window.
'-------------------------------------------------------------------------------------------

'//
' @Function: GetModuleBaseFromProcessName
' @Purpose : Returns the process Id of the given process name.
'\\
Public Function GetModuleBaseFromProcessName(ByVal szProcessName As String, ByVal szModuleName As String) As Long

    Dim dwProcId As Long
    dwProcId = GetProcessIdByName(szProcessName)
    If dwProcId = 0 Then
        GetModuleBaseFromProcessName = 0
        Exit Function
    End If
   
    Dim me32            As MODULEENTRY32
    Dim hSnapshot       As Long
    Dim bFoundModule    As Boolean
    Dim dwModuleBase    As Long
   
    me32.dwSize = Len(me32)
    hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcId)
    bFoundModule = Module32First(hSnapshot, me32)
   
    Do While bFoundModule
        If LCase$(Left(me32.szModule, InStr(me32.szModule, Chr(0)) - 1)) = LCase$(szModuleName) Then
            dwModuleBase = me32.modBaseAddr
            Exit Do
        End If
        bFoundModule = Module32Next(hSnapshot, me32)
    Loop
   
    Call CloseHandle(hSnapshot)
   
    GetModuleBaseFromProcessName = dwModuleBase
   
End Function

'//
' @Function: GetModuleSizeFromProcessName
' @Purpose : Returns the process Id of the given process name.
'\\
Public Function GetModuleSizeFromProcessName(ByVal szProcessName As String, ByVal szModuleName As String) As Long

    Dim dwProcId As Long
    dwProcId = GetProcessIdByName(szProcessName)
    If dwProcId = 0 Then
        GetModuleSizeFromProcessName = 0
        Exit Function
    End If
   
    Dim me32            As MODULEENTRY32
    Dim hSnapshot       As Long
    Dim bFoundModule    As Boolean
    Dim dwModuleSize    As Long
   
    me32.dwSize = Len(me32)
    hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcId)
    bFoundModule = Module32First(hSnapshot, me32)
   
    Do While bFoundModule
        If LCase$(Left(me32.szModule, InStr(me32.szModule, Chr(0)) - 1)) = LCase$(szModuleName) Then
            dwModuleSize = me32.modBaseSize
            Exit Do
        End If
        bFoundModule = Module32Next(hSnapshot, me32)
    Loop
   
    Call CloseHandle(hSnapshot)
   
    GetModuleSizeFromProcessName = dwModuleSize
   
End Function

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
ElBartoDeLaMurte
How do I cheat?
Reputation: 0

Joined: 13 Nov 2016
Posts: 2

PostPosted: Tue Nov 15, 2016 3:25 pm    Post subject: Reply with quote

Sorry for the delay, i had some troubles with my laptop.


And thank you, your code works totally fine! Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites