Page 1 of 1

EXE Edit

Posted: Sun May 15, 2011 1:06 pm
by M1z23R
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 !

Re: EXE Edit

Posted: Sun May 15, 2011 1:17 pm
by Napster1488
Maybe try it with Hex Edit,there is a Lib to use HexEdit in VB.
Name is HexBox.

Re: EXE Edit

Posted: Sun May 15, 2011 1:19 pm
by smashapps
hex editors are of course good for this as napster has said

off topic: Napster talk on Dropbox want to talk to you

Re: EXE Edit

Posted: Sun May 15, 2011 3:27 pm
by mandai
If you know the offset of the text, you can use a FileStream to change or shorten the text.

Re: EXE Edit

Posted: Mon May 16, 2011 2:11 pm
by M1z23R
How can i use file stream ? I know exactly what text is "in" exe file, i just want to be able to change it !

Re: EXE Edit

Posted: Mon May 16, 2011 8:20 pm
by mandai
You could change it with this:
Code: Select all
        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()

Re: EXE Edit

Posted: Mon May 16, 2011 8:36 pm
by M1z23R
tnx man, but how can i do some thing like this ?
Dim rfs = Read file stream
rfs = rfs.replace(oldstr,newstr)

?
If you can understand me it would be great :D

Re: EXE Edit

Posted: Mon May 16, 2011 9:28 pm
by mandai
There are many methods for finding a string in a stream. You could use this to find the offset:
Code: Select all
        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

Re: EXE Edit

Posted: Tue May 17, 2011 12:56 pm
by M1z23R
how can i edit it when i find it ?

Re: EXE Edit

Posted: Tue May 17, 2011 10:44 pm
by mandai
The first code block deals with changing the original string.