EXE Edit
Posted: Sun May 15, 2011 1:06 pm
Ok, so i wan't to be able to change certain text - String in my .exe file using stream reader/writer, but i don't want my app to get messed up !
Sharing, Teaching and Supporting coders of all ages and levels since 2009
https://www.codenstuff.com/forum/
Dim fs As FileStream = New FileStream("test.exe", FileMode.Open)
fs.Position = &HFFA0 'an example offset of the text
Dim changed As String = "new text" 'must be equal or shorter than the original text
' ASCII encoding is assumed
For i As Integer = 0 To changed.Length - 1
fs.WriteByte(Asc(changed(i)))
Next
fs.Close()
Dim input As Byte() = File.ReadAllBytes("file.txt")
Dim lookFor As Byte() = Encoding.ASCII.GetBytes("old text")
Dim temp(lookFor.Length - 1) As Byte
Dim offset As Integer = -1
For i As Integer = 0 To input.Length - lookFor.Length
System.Buffer.BlockCopy(input, i, temp, 0, lookFor.Length)
If temp.SequenceEqual(lookFor) Then
Dim dr As DialogResult = MessageBox.Show("Found 'old text' at offset " & i & ", finish search?", "", MessageBoxButtons.YesNo)
If dr = Windows.Forms.DialogResult.Yes Then
offset = i
Exit For
End If
'else keep looking
End If
Next