Results 1 to 8 of 8
  1. #1
    Silent's Avatar
    Join Date
    Jan 2015
    Gender
    male
    Location
    Melbourne, Australia
    Posts
    5,070
    Reputation
    2172
    Thanks
    8,474
    My Mood
    Bitchy

    Post VB Memory Class x86

    Hello people, I made a C# memory class a few weeks ago, I just thought I would make a version available for Visual Basic.

    Please not that I used a online converter for this and I haven't tested it. https://converter.telerik.com/(Please note, I haven't looked through the website for download links. So if there's a download link, And you download it, It's your own risk and problem if anything happens to you.)


    Features:
    WriteBytes
    WriteByte
    WriteInt
    WriteString
    WriteFloat
    ReadBytes
    ReadByte
    ReadInt
    ReadString
    ReadString Advanced
    ReadFloat
    PatternScan


    Code:
    Class Memory
        Private pHandel As IntPtr = IntPtr.Zero
        Private attachedProcess As Process = Nothing
        Private buffer As Byte()
    
        Public Function Open_pHandel(processName As String) As Boolean
            Dim proc As Process() = Process.GetProcessesByName(processName)
    
            If proc.Length = 0 Then
                Return False
            ElseIf proc.Length > 1 Then
                Throw New Exception("More then one process found.")
            Else
                attachedProcess = proc(0)
                pHandel = proc(0).Handle
                Return True
            End If
        End Function
    
    #Region "x86"
    #Region "Write"
        Public Function WriteBytes(address As Integer, value As Byte(), Optional virtualProtect As Boolean = False) As Boolean
            Dim countOfUsed As Integer = 0
            Dim result As Boolean = False
            Dim oldProtection As UInteger = 0
    
    
            If virtualProtect Then
                Win32.x86.VirtualProtectEx(pHandel, address, CUInt(value.Length), &H40, oldProtection)
            End If
    
            result = Win32.x86.WriteProcessMemory(pHandel, address, value, CUInt(value.Length), countOfUsed)
    
            If virtualProtect Then
                Win32.x86.VirtualProtectEx(pHandel, address, CUInt(value.Length), oldProtection, oldProtection)
            End If
    
            Return result
        End Function
    
        Public Function WriteInt(address As Integer, value As Integer, Optional virtualProtect As Boolean = False) As Boolean
            buffer = BitConverter.GetBytes(value)
            Return WriteBytes(address, buffer, virtualProtect)
        End Function
    
        Public Function WriteByte(address As Integer, value As Byte, Optional virtualProtect As Boolean = False) As Boolean
            buffer = New Byte() {value}
            Return WriteBytes(address, buffer, virtualProtect)
        End Function
    
        Public Function WriteString(address As Integer, value As String, Optional virtualProtect As Boolean = False) As Boolean
            buffer = Encoding.ASCII.GetBytes(value)
            'No unicode support atm
            Return WriteBytes(address, buffer, virtualProtect)
        End Function
    
        Public Function WriteFloat(address As Integer, value As Single, Optional virtualProtect As Boolean = False) As Boolean
            buffer = BitConverter.GetBytes(value)
            Return WriteBytes(address, buffer, virtualProtect)
        End Function
    #End Region
    #Region "Read"
        Public Function ReadBytes(address As Integer, length As Integer) As Byte()
            Dim readBytes__1 As Byte() = New Byte(length - 1) {}
            Dim numBytesChanged As Integer = 0
    
            Win32.x86.ReadProcessMemory(pHandel, address, readBytes__1, CUInt(length), numBytesChanged)
    
            Return readBytes__1
        End Function
    
        Public Function ReadInt(address As Integer) As Integer
            Return BitConverter.ToInt32(ReadBytes(address, 4), 0)
        End Function
    
        Public Function ReadByte(address As Integer) As Byte
            Return ReadBytes(address, 1)(0)
        End Function
    
        Public Function ReadString(address As Integer, length As Integer) As String
            'No unicode support
            Return Encoding.ASCII.GetString(ReadBytes(address, length))
        End Function
    
        Public Function ReadStringAdvanced(address As Integer, Optional maxStringLength As Integer = 1000) As String
            'No unicode support
            Dim result As String = Nothing
            Dim currentByte As Byte = 0
    
            For i As Integer = 0 To maxStringLength - 1
                currentByte = ReadByte(address + i)
    
                If currentByte = &H0 Then
                    Exit For
                Else
                    result += ChrW(currentByte)
    
                End If
            Next
    
            Return result
        End Function
    
        Public Function ReadFloat(address As Integer) As Single
            Return BitConverter.ToSingle(ReadBytes(address, 4), 0)
        End Function
    #End Region
    #Region "Scans"
        Public Function PatternScan(pattern As String) As Integer
            Dim splitPattern As String() = pattern.Split(" "c)
            Dim indexValid As Boolean() = New Boolean(splitPattern.Length - 1) {}
            Dim indexValue As Byte() = New Byte(splitPattern.Length - 1) {}
    
            Dim tempByte As Byte = CByte(&H0)
    
            For i As Integer = 0 To splitPattern.Length - 1
                indexValid(i) = Not (splitPattern(i) = "??" OrElse splitPattern(i) = "?")
                If [Byte].TryParse(splitPattern(i), tempByte) Then
                    indexValue(i) = tempByte
                Else
                    indexValid(i) = False
                End If
            Next
    
            Dim startOfMemory As Integer = attachedProcess.MainModule.BaseAddress.ToInt32()
            Dim endOfMemory As Integer = attachedProcess.MainModule.ModuleMemorySize
    
            For currentMemAddy As Integer = startOfMemory To endOfMemory - 1
                Dim complete As Boolean = False
                For i As Integer = 0 To splitPattern.Length - 1
                    If Not indexValid(i) Then
                        Continue For
                    End If
    
                    tempByte = ReadByte(currentMemAddy + i)
    
                    If tempByte <> indexValue(i) Then
                        Exit For
                    End If
    
                    If i = splitPattern.Length - 1 Then
                        complete = True
                    End If
    
                    If complete Then
                        Exit For
                    End If
                Next
    
                If complete Then
                    Return currentMemAddy
                End If
            Next
    
            Throw New Exception("Pattern not found!")
            Return 0
        End Function
    #End Region
    #End Region
    
        Private NotInheritable Class Win32
            Private Sub New()
            End Sub
            Public NotInheritable Class NativeMethods
                Private Sub New()
                End Sub
    #Region "IsWow64Process"
                Public Shared Function IsWow64Process(handel As IntPtr) As Boolean
                    Dim isTarget64Bit As Boolean = False
                    IsWow64Process(handel, isTarget64Bit)
                    Return isTarget64Bit
                End Function
    
                <DllImport("kernel32.dll", SetLastError:=True, CallingConvention:=CallingConvention.Winapi)> _
                Private Shared Function IsWow64Process(<[In]> process As IntPtr, <Out> ByRef wow64Process As Boolean) As <MarshalAs(UnmanagedType.Bool)> Boolean
                End Function
    #End Region
            End Class
    
            Public NotInheritable Class x64
                Private Sub New()
                End Sub
                <DllImport("kernel32.dll", SetLastError:=True)> _
                Public Shared Function VirtualProtectEx(hProcess As IntPtr, lpAddress As Long, dwSize As UInt32, flNewProtect As UInteger, ByRef lpflOldProtect As UInteger) As Boolean
                End Function
    
                <DllImport("kernel32.dll")> _
                Public Shared Function ReadProcessMemory(hProcess As IntPtr, lpBaseAddress As Long, <[In], Out> buffer As Byte(), size As UInt32, ByRef lpNumberOfBytesWritten As Integer) As Boolean
                End Function
    
                <DllImport("kernel32.dll")> _
                Public Shared Function WriteProcessMemory(hProcess As IntPtr, lpBaseAddress As Long, <[In], Out> buffer As Byte(), size As UInt32, ByRef lpNumberOfBytesWritten As Integer) As Boolean
                End Function
            End Class
    
            Public NotInheritable Class x86
                Private Sub New()
                End Sub
                <DllImport("kernel32.dll", SetLastError:=True)> _
                Public Shared Function VirtualProtectEx(hProcess As IntPtr, lpAddress As Integer, dwSize As UInt32, flNewProtect As UInteger, ByRef lpflOldProtect As UInteger) As Boolean
                End Function
    
                <DllImport("kernel32.dll")> _
                Public Shared Function ReadProcessMemory(hProcess As IntPtr, lpBaseAddress As Integer, <[In], Out> buffer As Byte(), size As UInt32, ByRef lpNumberOfBytesWritten As Integer) As Boolean
                End Function
    
                <DllImport("kernel32.dll")> _
                Public Shared Function WriteProcessMemory(hProcess As IntPtr, lpBaseAddress As Integer, <[In], Out> buffer As Byte(), size As UInt32, ByRef lpNumberOfBytesWritten As Integer) As Boolean
                End Function
            End Class
        End Class
    End Class
    usage:
    Code:
            Dim mem = New Memory()
            If mem.Open_pHandel("processName") Then
                Dim address = mem.PatternScan("02 255 12 41 ?? 54 ? 12 ? 52 ?? 23")
                mem.WriteBytes(address, New Byte() {&H0, &H0})
            End If
    (Usage took me like 10 minutes to do. Stupid VB syntax)


    Don't forget to press thanks if you find this useful!
    Click Here to visit the official MPGH wiki! Keep up with the latest news and information on games and MPGH! To check out pages dedicated to games, see the links below!











    dd/mm/yyyy
    Member - 31/01/2015
    Premium - 12/09/2016
    Call of Duty minion - 05/11/2016 - 05/11/2019
    BattleOn minion - 28/02/2017 - 05/11/2019
    Battlefield minion - 30/05/2017 - 05/11/2019
    Other Semi-Popular First Person Shooter Hacks minion - 21/09/2017 - 17/09/2019
    Publicist - 07/11/2017 - 02/08/2018
    Cock Sucker - 01/12/2017 - Unknown
    Minion+ - 06/03/2018 - 05/11/2019
    Fortnite minion - 08/05/2018 - 05/11/2019
    Head Publicist - 08/10/2018 - 10/01/2020
    Developer Team - 26/10/2019 - 10/01/2020
    Former Staff - 10/01/2020



  2. The Following User Says Thank You to Silent For This Useful Post:

    Nine11 (02-12-2017)

  3. #2
    HacxXcoder_Death's Avatar
    Join Date
    Feb 2017
    Gender
    male
    Posts
    12
    Reputation
    10
    Thanks
    2
    My Mood
    Lonely
    Noice JamesBond

  4. The Following User Says Thank You to HacxXcoder_Death For This Useful Post:

    Silent (02-15-2017)

  5. #3
    Sazor98's Avatar
    Join Date
    Jan 2013
    Gender
    male
    Location
    X:13 Y:3 Z:7
    Posts
    154
    Reputation
    23
    Thanks
    64
    i can't get the pattern scanner to work, it always returned pattern not found even tho cheat engine can find the pattern
    EDIT : it works now, made a little mistake
    Last edited by Sazor98; 02-22-2017 at 07:50 PM.

  6. The Following User Says Thank You to Sazor98 For This Useful Post:

    Silent (02-23-2017)

  7. #4
    Sazor98's Avatar
    Join Date
    Jan 2013
    Gender
    male
    Location
    X:13 Y:3 Z:7
    Posts
    154
    Reputation
    23
    Thanks
    64
    well kinda having another prob with :
    currentMemAddy = startOfMemory to endOfMemory - 1

    sometimes the base address is bigger than the end of memory, or vice versa. thus it can't go "To it"
    which results in patternScan to return 0.
    what i did was : For currentMemAddy As Integer = startOfMemory To startOfMemory + endOfMemory
    just so i can have a little range to scan into. is their a better way?
    Last edited by Sazor98; 02-24-2017 at 02:44 AM.

  8. #5
    Biesi's Avatar
    Join Date
    Dec 2011
    Gender
    male
    Posts
    4,993
    Reputation
    374
    Thanks
    8,808
    My Mood
    Twisted
    Quote Originally Posted by Sazor98 View Post
    sometimes the base address is bigger than the end of memory, or vice versa. thus it can't go "To it"
    That's because endOfMemory actually refers to the size of the module not the end in memory. The size is relative and not absulute so your solution is actually the correct way to go.
    Last edited by Biesi; 02-24-2017 at 04:06 AM.

  9. The Following User Says Thank You to Biesi For This Useful Post:

    Silent (02-24-2017)

  10. #6
    Ethede's Avatar
    Join Date
    Feb 2017
    Gender
    male
    Posts
    91
    Reputation
    10
    Thanks
    37
    My Mood
    Cheerful
    Works for mono?

  11. #7
    Silent's Avatar
    Join Date
    Jan 2015
    Gender
    male
    Location
    Melbourne, Australia
    Posts
    5,070
    Reputation
    2172
    Thanks
    8,474
    My Mood
    Bitchy
    Quote Originally Posted by Ethede View Post
    Works for mono?
    What's mono?
    Click Here to visit the official MPGH wiki! Keep up with the latest news and information on games and MPGH! To check out pages dedicated to games, see the links below!











    dd/mm/yyyy
    Member - 31/01/2015
    Premium - 12/09/2016
    Call of Duty minion - 05/11/2016 - 05/11/2019
    BattleOn minion - 28/02/2017 - 05/11/2019
    Battlefield minion - 30/05/2017 - 05/11/2019
    Other Semi-Popular First Person Shooter Hacks minion - 21/09/2017 - 17/09/2019
    Publicist - 07/11/2017 - 02/08/2018
    Cock Sucker - 01/12/2017 - Unknown
    Minion+ - 06/03/2018 - 05/11/2019
    Fortnite minion - 08/05/2018 - 05/11/2019
    Head Publicist - 08/10/2018 - 10/01/2020
    Developer Team - 26/10/2019 - 10/01/2020
    Former Staff - 10/01/2020



  12. #8
    Biesi's Avatar
    Join Date
    Dec 2011
    Gender
    male
    Posts
    4,993
    Reputation
    374
    Thanks
    8,808
    My Mood
    Twisted
    Quote Originally Posted by 1000 View Post


    What's mono?
    A cross platform port for the .NET Framework.

    But to answer the question.

    Quote Originally Posted by Ethede View Post
    Works for mono?
    I doubt that it will work as it uses Win32 API which is Windows specific.. (obviously)

  13. The Following User Says Thank You to Biesi For This Useful Post:

    Silent (02-25-2017)

Similar Threads

  1. [Source Code] C# Memory class x86
    By Silent in forum C# Programming
    Replies: 30
    Last Post: 10-13-2019, 10:47 AM
  2. C# Memory Class (Writen by Jorndel)
    By Jorndel in forum Call of Duty Modern Warfare 3 Coding, Programming & Source Code
    Replies: 12
    Last Post: 03-03-2019, 08:45 AM
  3. VB.Net Memory Class (Writen by Jorndel)
    By Jorndel in forum Call of Duty Modern Warfare 3 Coding, Programming & Source Code
    Replies: 25
    Last Post: 11-02-2017, 09:59 PM
  4. [Help] c# memory class
    By xXFleshpoundXx in forum C# Programming
    Replies: 8
    Last Post: 01-12-2013, 05:24 AM
  5. [Help Request] memory class
    By Coper in forum Call of Duty Black Ops 2 Help
    Replies: 5
    Last Post: 01-04-2013, 03:19 AM