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 


[VB.NET]WriteProcessMemory string

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

Joined: 11 Aug 2009
Posts: 6

PostPosted: Fri Mar 18, 2011 3:54 am    Post subject: [VB.NET]WriteProcessMemory string Reply with quote

Hi, i'm looking for a code to Write string to an address but i can't find any sample i searched all over the google and nothing found Shocked

help Confused
Back to top
View user's profile Send private message
Krähne
Expert Cheater
Reputation: 0

Joined: 06 Jun 2010
Posts: 108
Location: Inside of my Kernel

PostPosted: Fri Mar 18, 2011 6:06 am    Post subject: Re: [VB.NET]WriteProcessMemory string Reply with quote

KaMeR wrote:
Hi, i'm looking for a code to Write string to an address but i can't find any sample i searched all over the google and nothing found Shocked

help Confused


Just convert the string array into a byte array, and use it for edit the memory.

That's not so hard:

Code:
Imports System.Text
Imports System.Runtime.InteropServices

Public Class Form1
    <DllImport("kernel32.dll", SetLastError:=True)> _
    Public Shared Function WriteProcessMemory(ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, ByVal lpBuffer As Byte(), ByVal nSize As System.UInt32, <Out()> ByRef lpNumberOfBytesWritten As Int32) As Boolean
    End Function

    Public Shared Function StrToByteArray(ByVal str As String) As Byte()
        Dim encoding As New System.Text.UTF8Encoding()
        Return encoding.GetBytes(str)
    End Function

    Public Shared Function Poke(ByVal proc As Process, ByVal target As Integer, ByVal data As Byte()) As Boolean
        Return WriteProcessMemory(proc.Handle, New IntPtr(target), data, data.Length, 0)
    End Function

    Private Sub PokeMemory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PokeMemory.Click
        Try
            Dim p As Process() = Process.GetProcessesByName(AppName.Text)
            Dim Written As Boolean = False

            Written = Poke(p(0), &H1009020, StrToByteArray(TxtVal.Text))

            If Written = True Then
                MsgBox("WriteProcessMemory Sucess!", MsgBoxStyle.OkOnly, "Poke Memory Status")
            ElseIf Written = False Then
                MsgBox("WriteProcessMemory Failed!", MsgBoxStyle.OkOnly, "Poke Memory Status")
            End If

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

End Class


the result should seems like this:

Before edit the memory of notepad:



After edit the memory of notepad:



i'm not a VB.NET programmer so... isn't a perfect code, but... that's a basic example, modify as you need.

hope this helps.

_________________
Excuse me if you don't understand what I just said, but "english" isn't my native language.


Last edited by Krähne on Fri Mar 18, 2011 6:42 am; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
KaMeR
How do I cheat?
Reputation: 0

Joined: 11 Aug 2009
Posts: 6

PostPosted: Fri Mar 18, 2011 6:27 am    Post subject: Reply with quote

thanks it work
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 163

Joined: 25 Jan 2006
Posts: 8161
Location: 127.0.0.1

PostPosted: Fri Mar 18, 2011 4:23 pm    Post subject: Reply with quote

Keep in mind you may need to not write in Unicode for some processes. So be careful when using:
Code:
Dim encoding As New System.Text.UTF8Encoding()


You may need to use Ascii encoding instead.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
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