Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 13:54

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Write Memory Issue.

Discussion on Write Memory Issue. within the .NET Languages forum part of the Coders Den category.

Reply
 
Old   #1
 
summoner01's Avatar
 
elite*gold: 0
Join Date: Sep 2007
Posts: 500
Received Thanks: 146
Write Memory Issue.

So as the title states, I'm having an issue with this memory write function. It does work, but it seems to write some extra bytes into the next address above the target address. I'm not quite sure how to fix it since my knowledge in visual basic and memory in general isn't that great. I thought I would make post here for feedback while I try to find some stuff on google as well.

Here is the code I have atm. Read works fine.
Code:
Public Declare Function ReadProcessMemory Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As Integer, ByVal buffer As Byte(), ByVal size As Integer, ByVal lpNumberOfBytesRead As Integer) As Boolean
    Public Declare Function WriteProcessMemory Lib "kernel32" Alias "WriteProcessMemory" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As Integer, ByVal buffer As Byte(), ByVal size As Integer, ByVal lpNumberOfBytesWritten As Integer) As Boolean

    Private Function GetAddress(ByVal Proc As Process, ByVal Address_Offsets As String) As Integer
        On Error Resume Next
        Dim tmp As String() = Address_Offsets.Split(" ")
        Dim _Addy As Integer = -1

        ''''''Gets the base address''''''' 
        If (tmp(0).IndexOf("+", StringComparison.Ordinal) = -1) Then
            _Addy = Integer.Parse(tmp(0), System.Globalization.NumberStyles.HexNumber)
        Else
            Dim BS As String() = tmp(0).Split("+")
            For Each M As ProcessModule In Proc.Modules
                If (M.ModuleName.ToLower = BS(0).ToLower) Then
                    _Addy = M.BaseAddress.ToInt32 + Integer.Parse(BS(1), System.Globalization.NumberStyles.HexNumber)
                End If
            Next
        End If
        '''''''''''''''''''''''''''''''''' 
        If _Addy = -1 Then
            Return -1
        End If

        If (tmp.Length = 1) Then
            Return _Addy
        End If

        ''''''Gets the pointer'''''''''''' 
        Dim buff As Byte() = New Byte(3) {}
        ReadProcessMemory(Proc.Handle, _Addy, buff, 4, 0)
        _Addy = BitConverter.ToInt32(buff, 0)
        For i As Integer = 1 To tmp.Length - 1
            Dim Off As Integer = Integer.Parse(tmp(i), System.Globalization.NumberStyles.HexNumber)
            ReadProcessMemory(Proc.Handle, _Addy + Off, buff, 4, 0)
            _Addy = If(i <> (tmp.Length - 1), BitConverter.ToInt32(buff, 0), _Addy + Off)
        Next i
        '''''''''''''''''''''''''''''''''' 
        Return _Addy
    End Function

    Public Function Read(ByVal EXENAME As String, ByVal Address_Offsets As String, ByVal MemType As Object) As Object
        If (Address_Offsets <> String.Empty) Then

            Dim Proc As Process() = Process.GetProcessesByName(EXENAME)
            If Proc.Length = 0 Then
                Return -1
            End If

            Dim buff As Byte()
            Select Case Array.IndexOf(Of Object)(New Object() {GetType(Byte), GetType(Integer), GetType(UInt32), GetType(String), GetType(Single), GetType(Double), GetType(UInt16)}, MemType)
                Case 0
                    buff = New Byte(1) {}
                    ReadProcessMemory(Proc(0).Handle, GetAddress(Proc(0), Address_Offsets), buff, 1, 0)
                    Return buff(0)
                Case 1
                    buff = New Byte(3) {}
                    ReadProcessMemory(Proc(0).Handle, GetAddress(Proc(0), Address_Offsets), buff, 4, 0)
                    Return BitConverter.ToInt32(buff, 0)
                Case 2
                    buff = New Byte(3) {}
                    ReadProcessMemory(Proc(0).Handle, GetAddress(Proc(0), Address_Offsets), buff, 4, 0)
                    Return BitConverter.ToUInt32(buff, 0)
                Case 3
                    buff = New Byte(19) {}
                    ReadProcessMemory(Proc(0).Handle, GetAddress(Proc(0), Address_Offsets), buff, 20, 0)
                    Return BitConverter.ToString(buff, 0)
                Case 4
                    buff = New Byte(3) {}
                    ReadProcessMemory(Proc(0).Handle, GetAddress(Proc(0), Address_Offsets), buff, 4, 0)
                    Return BitConverter.ToSingle(buff, 0)
                Case 5
                    buff = New Byte(7) {}
                    ReadProcessMemory(Proc(0).Handle, GetAddress(Proc(0), Address_Offsets), buff, 8, 0)
                    Return BitConverter.ToDouble(buff, 0)
                Case 6
                    buff = New Byte(3) {}
                    ReadProcessMemory(Proc(0).Handle, GetAddress(Proc(0), Address_Offsets), buff, 4, 0)
                    Return BitConverter.ToUInt16(buff, 0)
                Case -1
                    Return -1
            End Select
        End If
        Return -1
    End Function

    Public Function Write(ByVal EXENAME As String, ByVal Address_Offsets As String, ByVal Value As Object, ByVal MemType As Object)
        If (Address_Offsets <> String.Empty And Value <> Nothing) Then

            Dim Proc As Process() = Process.GetProcessesByName(EXENAME)
            If Proc.Length = 0 Then
                Return -1
            End If

            Dim buff As Byte() = Nothing
            Select Case Array.IndexOf(Of Object)(New Object() {GetType(Byte), GetType(Integer), GetType(UInt16), GetType(UInt32), GetType(String), GetType(Single), GetType(Double)}, MemType)
                Case 0
                    buff = BitConverter.GetBytes(Byte.Parse(Value))
                    Exit Select
                Case 1
                    buff = BitConverter.GetBytes(Integer.Parse(Value))
                    Exit Select
                Case 2
                    buff = BitConverter.GetBytes(UInt32.Parse(Value))
                    Exit Select
                Case 3
                    buff = BitConverter.GetBytes(UInt16.Parse(Value))
                    Exit Select
                Case 4
                    buff = System.Text.ASCIIEncoding.ASCII.GetBytes(Value)
                    Exit Select
                Case 5
                    buff = BitConverter.GetBytes(Single.Parse(Value))
                    Exit Select
                Case 6
                    buff = BitConverter.GetBytes(Double.Parse(Value))
                    Exit Select
            End Select
            If Not buff Is Nothing Then
                WriteProcessMemory(Proc(0).Handle, GetAddress(Proc(0), Address_Offsets), buff, buff.LongLength, 0)
            End If

        End If
        Return -1
    End Function
Credits for the code: Pingo @

EDIT: So I thought I fixed the problem, by looking at the code and changing
Code:
WriteProcessMemory(Proc(0).Handle, GetAddress(Proc(0), Address_Offsets), buff, buff.LongLength, 0)
to
Code:
WriteProcessMemory(Proc(0).Handle, GetAddress(Proc(0), Address_Offsets), buff, buff.LongLength - 1, 0)
... But it only made one thing work, and everything else not work properly.
summoner01 is offline  
Old 11/13/2012, 07:03   #2
 
summoner01's Avatar
 
elite*gold: 0
Join Date: Sep 2007
Posts: 500
Received Thanks: 146
Forget it, i'm using Autoit.

#Request Thread Deletion
summoner01 is offline  
Reply


Similar Threads Similar Threads
Memory write
09/25/2012 - .NET Languages - 2 Replies
Hallo, ich bräuchte mal bitte eure hilfe ;D Mit programmieren kenn ich mich nicht so aus... meine ersten hack für mw3 hab ich mir Cheat Engine gemacht ... das Design war grauenhaft -.- ... nun wollte ich einen mit VB Express 2010 machen ... hab keine ahnung wie ich die memory/speicher bearbeiten kann ... Habe ein paar module getestet klappt aber nicht-.- Benutze VB Express 2010. Wäre schön wenn jmd. mir hilft ^^ Mfg
Memory Write
01/12/2012 - C/C++ - 8 Replies
Moin, ich mach grad ein c++ trainer tutorial durch, hab auch alles bis auf eine kleine sache verstanden ... Nur von der logik her: hier mit deklariere ich doch was der neue wert sein soll : BYTE AmmoValue = {0xA3,0x1C,0x0,0x0};
[VB]Write Memory bzw Read Memory
06/26/2010 - .NET Languages - 8 Replies
Hi Ich hab das TuT von *Guidman* benütz um einen hack zu machen. So aber nun hab ihc ein paar fragen könnte man memory teil kürzer machen und am besten wie kann man das selber machen weil ich will nihct immer C&P machen. Und zu Read Memory kann man das auch machen das ein Label immer die Bestimmte Ahnzahl angiebt von dem Pointer?.(Wenn das Read Memory ist ?) Bitte helf mir Danke
Injection vs. Memory Write
12/15/2009 - Aion - 11 Replies
Hallo, kann mir einer da mal den genauen Unterschied erklären bitte. Ich weiß nur das Injection hohe Banngefahr hat und Memory Write wohl nicht ? Danke Maxx.



All times are GMT +1. The time now is 13:55.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.