Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello!
I got a little bit struggle into this.
The thing I want should work like this:

- open the .exe file
- read it and get it into a textbox (somehow exactly how notepad/notepad++ does)
- if "string" is found into textbox, then replace it with "gnirts"
- save the new executable with "gnirts" instead of "string"

I'd like to do it because it will save a lot of time, for now, I do this manually with Notepad++

Thanks!

What I have tried:

Dim lines() As String = IO.File.ReadAllLines(pathTxt.Text, Encoding.Default)
For Each line As String In lines
valueTxt.AppendText(line & vbCrLf)
Next
Posted
Updated 13-Oct-20 3:08am

Don't.

The first thing that will happen is your app will be flagged as showing virus-like activity: anything that changes EXE files will be at some point.
You also can't add bytes to a string in an EXE without damaging the application: binary files expect coide to be at certain places, and if you move them code will "randomly" stop working.

And you cannot open an EXE file as text, read it, change it, and save it again without corrupting the EXE very significantly: EXE files are binary data, not text.
 
Share this answer
 
Comments
Piticu97 13-Oct-20 5:46am    
As I said, I want to do it with vb.net like I'm doing with n++, if it is possible, I don't want to add a string, I want to replace a string with another with same lenght, to avoid corrupting it
Ralf Meier 13-Oct-20 6:52am    
You should carefully read what Griff has written.
Most important for you is the first line of the statement.
It is independant if you use a text-editor oder vb.net or something different - the result is allways the same ...
Piticu97 13-Oct-20 7:32am    
I don't really care about it'll be flagged as a virus...
OriginalGriff 13-Oct-20 7:55am    
Why are you changing strings in executable files anyway? Just change it in your source code and recompile.
You cannot use ReadAllLines on a binary file. If you want to edit a .exe file then you need to use a hex editor, or write your own. And to do it properly you need to understand PE Format - Win32 apps | Microsoft Docs[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900