Quantcast
Channel: D3Scene
Viewing all articles
Browse latest Browse all 21080

[VB.NET] Processes Memory Editing Class

$
0
0
Hi Guys ,,,,
I would like to introduce my memory editing class for vb.net coders and i am gonna port it soon to c# and post it

it has lots of useful functions in reading and writing data to processes like floats - doubles - integers ,,, etc

here it is :


Code:

Imports System.Runtime.InteropServices
Imports System.Text

''' <summary>
''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' 'Class  : ProcessMemoryReaderWriter                                '
''' 'Coder  : Simon-Benyo                                              '
''' 'Date    : 8\18\2013                                                '
''' 'Purpose : ReadWrite Processes Memory And Read Multi Level Pointers '
''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' </summary>
''' <remarks></remarks>
Public Class ProcessMemoryReaderWriter
    <DllImport("kernel32.dll")> _
    Public Shared Function OpenProcess(ByVal dwDesiredAccess As UInt32, ByVal bInheritHandle As Integer, ByVal dwProcessId As UInt32) As IntPtr
    End Function
    <DllImport("kernel32.dll")> _
    Public Shared Function ReadProcessMemory(ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, <[In], Out> ByVal buffer As Byte(), ByVal size As UInt32, <Out> ByRef lpNumberOfBytesRead As IntPtr) As Integer
    End Function
    <DllImport("kernel32.dll", SetLastError:=True)> _
    Private Shared Function WriteProcessMemory(ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, ByVal lpBuffer As Byte(), ByVal nSize As UInteger, ByVal lpNumberOfBytesWritten As Integer) As Boolean
    End Function
    Public Handle As Integer
    Public Sub New(ByVal pid As Integer)
        Handle = OpenProcess(&H38, 1, pid)
    End Sub
    Public Function MultiLevelPointerReader(ByVal Address As Integer, ByVal offsets As Integer()) As Integer
        Dim cur_level As Integer = 0
        Dim level As Integer = offsets.Length
        Dim CurrentAddress As Integer = Address
        Dim bAddr(3) As Byte
        Dim FinalAddress As Integer
        For cur = 0 To level - 1
            ReadProcessMemory(Handle, CurrentAddress, bAddr, 4, Nothing)
            CurrentAddress = BitConverter.ToInt32(bAddr, 0) + offsets(cur)
        Next
        FinalAddress = CurrentAddress
        Return FinalAddress
    End Function
    Public Function ReadByteArray(ByVal Address As Integer, ByVal Size As Integer) As Byte()
        Dim bArray(0 To Size - 1) As Byte
        Dim ret As Integer
        ReadProcessMemory(Handle, Address, bArray, Size, ret)
        Return bArray
    End Function

    Public Function ReadInteger(ByVal Address As Integer) As Integer
        Dim bArray(3) As Byte
        Dim rInt As Integer
        ReadProcessMemory(Handle, Address, bArray, 4, Nothing)
        rInt = BitConverter.ToInt32(bArray, 0)
        Return rInt
    End Function
    Public Function ReadDouble(ByVal Address As Integer) As Double
        Dim bArray(7) As Byte
        Dim rDbl As Integer
        ReadProcessMemory(Handle, Address, bArray, 8, Nothing)
        rDbl = BitConverter.ToDouble(bArray, 0)
        Return rDbl
    End Function
    Public Function ReadFloat(ByVal Address As Integer) As Single
        Dim bArray(3) As Byte
        Dim rFlt As Integer
        ReadProcessMemory(Handle, Address, bArray, 4, Nothing)
        rFlt = BitConverter.ToSingle(bArray, 0)
        Return rFlt
    End Function
    Public Function WriteByteArray(ByVal Address As Integer, ByVal bArray As Byte()) As Boolean
        Return WriteProcessMemory(Handle, Address, bArray, bArray.Length, Nothing)
    End Function
    Public Function WriteInteger(ByVal Address As Integer, ByVal Value As Integer) As Boolean
        Dim bArray As Byte() = BitConverter.GetBytes(Value)
        Return WriteProcessMemory(Handle, Address, bArray, 4, Nothing)
    End Function
    Public Function WriteDouble(ByVal Address As Integer, ByVal Value As Double) As Boolean
        Dim bArray As Byte() = BitConverter.GetBytes(Value)
        Return WriteProcessMemory(Handle, Address, bArray, 8, Nothing)
    End Function
    Public Function WriteFloat(ByVal Address As Integer, ByVal Value As Single) As Boolean
        Dim bArray As Byte() = BitConverter.GetBytes(Value)
        Return WriteProcessMemory(Handle, Address, bArray, 4, Nothing)
    End Function
End Class

This is the first beta release

if you found any problems ,, issues please inform me about them so i can fix them

and if you want from me to add new functions also PM Me

and please credit me if u used this class

Thank you.

Simon.

Viewing all articles
Browse latest Browse all 21080

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>