BO2 Memory Class [VB]

Posts 1–15 of 25 · Page 1 of 2
BO2 Memory Class [VB]
So, since there was an "ask/beg" for this:
Code:
Class BO2_MemoryClass
    Private GameProc As String = ""
    Private Function OpenGame() As IntPtr
        If System.Diagnostics.Process.GetProcessesByName(GameProc).Length = 1 Then
            Return System.Diagnostics.Process.GetProcessesByName(GameProc)(0).Handle
        End If
        Return New IntPtr(0)
    End Function
    Public Enum ProcessAccessFlags As UInteger
        All = &H1F0FFF
        Terminate = &H1
        CreateThread = &H2
        Operation = &H8
        Read = &H10
        Write = &H20
        DupHandle = &H40
        SetInformation = &H200
        QueryInformation = &H400
        Synchronize = &H100000
    End Enum
    <Runtime.InteropServices.DllImport("kernel32.dll")> _
    Private Shared Function OpenProcess(dwDesiredAccess As ProcessAccessFlags, <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.Bool)> bInheritHandle As Boolean, dwProcessId As Integer) As IntPtr
    End Function
    <Runtime.InteropServices.DllImport("kernel32.dll")> _
    Private Shared Function CloseHandle(hObject As IntPtr) As Boolean
    End Function
    <Runtime.InteropServices.DllImport("kernel32.dll")> _
    Private Shared Function ReadProcessMemory(hProcess As IntPtr, lpBaseAddress As IntPtr, <Runtime.InteropServices.In, Runtime.InteropServices.Out> buffer As Byte(), size As UInt32, ByRef lpNumberOfBytesWritten As IntPtr) As Int32
    End Function
    <Runtime.InteropServices.DllImport("kernel32.dll")> _
    Private Shared Function WriteProcessMemory(hProcess As IntPtr, lpBaseAddress As IntPtr, <Runtime.InteropServices.In, Runtime.InteropServices.Out> buffer As Byte(), size As UInt32, ByRef lpNumberOfBytesWritten As IntPtr) As Int32
    End Function


    Public Function Process_Handle(ProcessName As String) As Boolean
        GameProc = ProcessName
        If System.Diagnostics.Process.GetProcessesByName(ProcessName).Length = 1 Then
            Return True
        End If
        Return False
    End Function
#Region "Write Stuff"
    Public Sub WriteString(Address As Integer, Text As String, Optional Length As Integer = -1)
        If Length = -1 Then
            Length = Text.Length
        End If
        Dim Buffer As Byte() = New System.Text.ASCIIEncoding().GetBytes(Text)
        Dim Zero As IntPtr = IntPtr.Zero
        WriteProcessMemory(OpenGame(), New IntPtr(Address), Buffer, CUInt(Length), Zero)
    End Sub
    Public Sub WriteInt(Address As Integer, Value As Integer)
        Dim buffer As Byte() = BitConverter.GetBytes(Value)
        Dim R As IntPtr
        WriteProcessMemory(OpenGame(), New IntPtr(Address), buffer, CUInt(4), R)
    End Sub
    Public Sub WriteUInt(Address As UInteger, Value As UInteger)
        Dim buffer As Byte() = BitConverter.GetBytes(Value)
        Dim R As IntPtr
        WriteProcessMemory(OpenGame(), New IntPtr(Address), buffer, CUInt(4), R)
    End Sub
    Public Sub WriteFloat(Address As Integer, Value As Single)
        Dim buffer As Byte() = BitConverter.GetBytes(Value)
        Dim R As IntPtr
        WriteProcessMemory(OpenGame(), New IntPtr(Address), buffer, CUInt(4), R)
    End Sub
    Public Sub WriteBytes(Address As Integer, ByteArray As Byte())
        Dim buffer As Byte() = ByteArray
        Dim R As IntPtr
        WriteProcessMemory(OpenGame(), New IntPtr(Address), buffer, CUInt(buffer.Length), R)
    End Sub
#End Region
#Region "Read Stuff"
    Public Function ReadString(Address As Integer, Length As Integer) As String
        Dim buffer As Byte() = New Byte(Length - 1) {}
        Dim R As IntPtr
        ReadProcessMemory(OpenGame(), New IntPtr(Address), buffer, CUInt(buffer.Length), R)
        Return New System.Text.ASCIIEncoding().GetString(buffer, 0, Length)
    End Function
    Public Function ReadInt(Address As Integer) As Integer
        Dim buffer As Byte() = New Byte(3) {}
        Dim R As IntPtr
        ReadProcessMemory(OpenGame(), New IntPtr(Address), buffer, CUInt(4), R)
        Return BitConverter.ToInt32(buffer, 0)
    End Function
    Public Function ReadUInt(Address As UInteger) As UInteger
        Dim buffer As Byte() = New Byte(3) {}
        Dim R As IntPtr
        ReadProcessMemory(OpenGame(), New IntPtr(Address), buffer, CUInt(4), R)
        Return BitConverter.ToUInt32(buffer, 0)
    End Function
    Public Function ReadFloat(Address As UInteger) As Single
        Dim buffer As Byte() = New Byte(7) {}
        Dim R As IntPtr
        ReadProcessMemory(OpenGame(), New IntPtr(Address), buffer, CUInt(4), R)
        Return BitConverter.ToSingle(buffer, 0)
    End Function
    Public Function ReadBytes(Address As Integer, BytesLength As Integer) As Byte()
        Dim buffer As Byte() = New Byte(BytesLength - 1) {}
        Dim R As IntPtr
        ReadProcessMemory(OpenGame(), New IntPtr(Address), buffer, CUInt(buffer.Length), R)
        Return buffer
    End Function
#End Region
#Region "Pointers"
    Public Function BaseAddress(Module_Name As String) As Integer
        Try
            If System.Diagnostics.Process.GetProcessesByName(GameProc).Length <> 0 Then
                For Each [Mod] As System.Diagnostics.ProcessModule In System.Diagnostics.Process.GetProcessesByName(GameProc)(0).Modules
                    If [Mod].ModuleName = Module_Name Then
                        Return [Mod].BaseAddress.ToInt32()
                    End If
                Next
                Return 0
            Else
                Return 0
            End If
        Catch
            Console.WriteLine("Base Address Error")
            Return 0
        End Try
    End Function
    Public Function Pointers([Module] As String, PointersX As Integer()) As Integer
        Dim Base As Integer = BaseAddress([Module]) + PointersX(0)
        Dim Runner As Integer = ReadInt(Base) + PointersX(1)
        Dim i As Integer = 2
        While i <> PointersX.Length - 2
            Runner = ReadInt(Runner) + PointersX(i)
            i += 1
        End While

        Return Runner
    End Function
#End Region
End Class
Quote Originally Posted by Jorndel View Post
So, since there was an "ask/beg" for this:
Code:
Class BO2_MemoryClass
    Private GameProc As String = ""
    Private Function OpenGame() As IntPtr
        If System.Diagnostics.Process.GetProcessesByName(GameProc).Length = 1 Then
            Return System.Diagnostics.Process.GetProcessesByName(GameProc)(0).Handle
        End If
        Return New IntPtr(0)
    End Function
    Public Enum ProcessAccessFlags As UInteger
        All = &H1F0FFF
        Terminate = &H1
        CreateThread = &H2
        Operation = &H8
        Read = &H10
        Write = &H20
        DupHandle = &H40
        SetInformation = &H200
        QueryInformation = &H400
        Synchronize = &H100000
    End Enum
    <Runtime.InteropServices.DllImport("kernel32.dll")> _
    Private Shared Function OpenProcess(dwDesiredAccess As ProcessAccessFlags, <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.Bool)> bInheritHandle As Boolean, dwProcessId As Integer) As IntPtr
    End Function
    <Runtime.InteropServices.DllImport("kernel32.dll")> _
    Private Shared Function CloseHandle(hObject As IntPtr) As Boolean
    End Function
    <Runtime.InteropServices.DllImport("kernel32.dll")> _
    Private Shared Function ReadProcessMemory(hProcess As IntPtr, lpBaseAddress As IntPtr, <Runtime.InteropServices.In, Runtime.InteropServices.Out> buffer As Byte(), size As UInt32, ByRef lpNumberOfBytesWritten As IntPtr) As Int32
    End Function
    <Runtime.InteropServices.DllImport("kernel32.dll")> _
    Private Shared Function WriteProcessMemory(hProcess As IntPtr, lpBaseAddress As IntPtr, <Runtime.InteropServices.In, Runtime.InteropServices.Out> buffer As Byte(), size As UInt32, ByRef lpNumberOfBytesWritten As IntPtr) As Int32
    End Function


    Public Function Process_Handle(ProcessName As String) As Boolean
        GameProc = ProcessName
        If System.Diagnostics.Process.GetProcessesByName(ProcessName).Length = 1 Then
            Return True
        End If
        Return False
    End Function
#Region "Write Stuff"
    Public Sub WriteString(Address As Integer, Text As String, Optional Length As Integer = -1)
        If Length = -1 Then
            Length = Text.Length
        End If
        Dim Buffer As Byte() = New System.Text.ASCIIEncoding().GetBytes(Text)
        Dim Zero As IntPtr = IntPtr.Zero
        WriteProcessMemory(OpenGame(), New IntPtr(Address), Buffer, CUInt(Length), Zero)
    End Sub
    Public Sub WriteInt(Address As Integer, Value As Integer)
        Dim buffer As Byte() = BitConverter.GetBytes(Value)
        Dim R As IntPtr
        WriteProcessMemory(OpenGame(), New IntPtr(Address), buffer, CUInt(4), R)
    End Sub
    Public Sub WriteUInt(Address As UInteger, Value As UInteger)
        Dim buffer As Byte() = BitConverter.GetBytes(Value)
        Dim R As IntPtr
        WriteProcessMemory(OpenGame(), New IntPtr(Address), buffer, CUInt(4), R)
    End Sub
    Public Sub WriteFloat(Address As Integer, Value As Single)
        Dim buffer As Byte() = BitConverter.GetBytes(Value)
        Dim R As IntPtr
        WriteProcessMemory(OpenGame(), New IntPtr(Address), buffer, CUInt(4), R)
    End Sub
    Public Sub WriteBytes(Address As Integer, ByteArray As Byte())
        Dim buffer As Byte() = ByteArray
        Dim R As IntPtr
        WriteProcessMemory(OpenGame(), New IntPtr(Address), buffer, CUInt(buffer.Length), R)
    End Sub
#End Region
#Region "Read Stuff"
    Public Function ReadString(Address As Integer, Length As Integer) As String
        Dim buffer As Byte() = New Byte(Length - 1) {}
        Dim R As IntPtr
        ReadProcessMemory(OpenGame(), New IntPtr(Address), buffer, CUInt(buffer.Length), R)
        Return New System.Text.ASCIIEncoding().GetString(buffer, 0, Length)
    End Function
    Public Function ReadInt(Address As Integer) As Integer
        Dim buffer As Byte() = New Byte(3) {}
        Dim R As IntPtr
        ReadProcessMemory(OpenGame(), New IntPtr(Address), buffer, CUInt(4), R)
        Return BitConverter.ToInt32(buffer, 0)
    End Function
    Public Function ReadUInt(Address As UInteger) As UInteger
        Dim buffer As Byte() = New Byte(3) {}
        Dim R As IntPtr
        ReadProcessMemory(OpenGame(), New IntPtr(Address), buffer, CUInt(4), R)
        Return BitConverter.ToUInt32(buffer, 0)
    End Function
    Public Function ReadFloat(Address As UInteger) As Single
        Dim buffer As Byte() = New Byte(7) {}
        Dim R As IntPtr
        ReadProcessMemory(OpenGame(), New IntPtr(Address), buffer, CUInt(4), R)
        Return BitConverter.ToSingle(buffer, 0)
    End Function
    Public Function ReadBytes(Address As Integer, BytesLength As Integer) As Byte()
        Dim buffer As Byte() = New Byte(BytesLength - 1) {}
        Dim R As IntPtr
        ReadProcessMemory(OpenGame(), New IntPtr(Address), buffer, CUInt(buffer.Length), R)
        Return buffer
    End Function
#End Region
#Region "Pointers"
    Public Function BaseAddress(Module_Name As String) As Integer
        Try
            If System.Diagnostics.Process.GetProcessesByName(GameProc).Length <> 0 Then
                For Each [Mod] As System.Diagnostics.ProcessModule In System.Diagnostics.Process.GetProcessesByName(GameProc)(0).Modules
                    If [Mod].ModuleName = Module_Name Then
                        Return [Mod].BaseAddress.ToInt32()
                    End If
                Next
                Return 0
            Else
                Return 0
            End If
        Catch
            Console.WriteLine("Base Address Error")
            Return 0
        End Try
    End Function
    Public Function Pointers([Module] As String, PointersX As Integer()) As Integer
        Dim Base As Integer = BaseAddress([Module]) + PointersX(0)
        Dim Runner As Integer = ReadInt(Base) + PointersX(1)
        Dim i As Integer = 2
        While i <> PointersX.Length - 2
            Runner = ReadInt(Runner) + PointersX(i)
            i += 1
        End While

        Return Runner
    End Function
#End Region
End Class
Thx jorndel now get ready for my new black ops 2 hack yea!!
wtf is this xd
Quote Originally Posted by HiMM4 View Post
wtf is this xd


If you don't know what this is, then you're in the wrong section mate

This is for coders/hackers.
This is a class that will allow coders to write hacks, and hack the game with memory editing.
looks very complicated
Quote Originally Posted by HiMM4 View Post
looks very complicated
That's why I did the "hardcore" work, and you can have fun :P

What you do now is just: WriteInteger(&H12345, 9999)
For 9999 ammo for your current weapon. (Fake address: Address = &H12345 )


---------- Post added at 07:59 PM ---------- Previous post was at 07:59 PM ----------

Quote Originally Posted by HiMM4 View Post
looks very complicated
If you want to learn: I'm able to help
Quote Originally Posted by Jorndel View Post

That's why I did the "hardcore" work, and you can have fun :P
Yeah cause WriteProcessMemory is so hardcore.
 
.
Just kidding, lub you


Quote Originally Posted by HiMM4 View Post
looks very complicated
It isn't after you learn the basics ^^
Quote Originally Posted by MarkHC View Post
Yeah cause WriteProcessMemory is so hardcore.
 
.
Just kidding, lub you



It isn't after you learn the basics ^^

Why I used: " "

Btw, just something I noticed, you're P/Invoking OpenProcess but not even using it Not that it'd make any difference to remove it but oh well.. I just wanted to point that out
Quote Originally Posted by MarkHC View Post
Btw, just something I noticed, you're P/Invoking OpenProcess but not even using it Not that it'd make any difference to remove it but oh well.. I just wanted to point that out
Hmmmzzzz
Fine then..

I'll do a new one then
Quote Originally Posted by MarkHC View Post
Btw, just something I noticed, you're P/Invoking OpenProcess but not even using it Not that it'd make any difference to remove it but oh well.. I just wanted to point that out
*Using old memory class of jorni*
I saw it once, no idea what it does
Quote Originally Posted by Horror View Post

*Using old memory class of jorni*
I saw it once, no idea what it does
Wasn't I to update it for you?
Or you don't want that? :S
Quote Originally Posted by Jorndel View Post


Wasn't I to update it for you?
Or you don't want that? :S
Im fine with the old one
ahah no ty dont want to learn it just want to use them
Posts 1–15 of 25 · Page 1 of 2

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?