Krähne Expert Cheater
Reputation: 0
Joined: 06 Jun 2010 Posts: 108 Location: Inside of my Kernel
|
Posted: Fri Mar 18, 2011 6:06 am Post subject: Re: [VB.NET]WriteProcessMemory string |
|
|
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
help  |
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 |
|