When I use strings filename
, it lists all strings in a binary file. And now, I want to modify the strings that listed. But, how?
Asked
Active
Viewed 5,160 times
1 Answers
4
If you replace a string with a string with the same length, you can edit a binary file with sed
, and it will work in the context that you describe in the question and your comment.
I do it with iso files of Linux operating systems to make a persistent live drive by replacing 'quiet splash'
with 'persistent '
(12 characters) in the grub menuentry. (See this link and scroll down to 'Manual method' in my answer.)
First check with strings
that the string you want to replace does not appear somewhere, that should not be modified (some binary sequence, that happens to contain that string), and then run for example
< original-file sed 's/abc/xyz/g' > modified-file

sudodus
- 6,421
-
-
In general you can do it (for example with
sed 's/abc/wxyz/g'
), and it may or may not work depending on the kind of binary file that you modify. For example, an iso file with Linux will probably be corrupted. A program file will probably also be corrupted. Some kind of data file might still work, depending on how it is used. – sudodus Nov 26 '21 at 20:10 -
1I tried the same length string in my program, and it worked. But it's doesn't works when I try the non-same length string. – Arian Nov 26 '21 at 21:16
-
1If you change the length of a string without "padding" it to the same length you will inevitably destroy a executable file (that is not built from text, as bash or python scripts). Pad with space (SPC) characters or NUL will often work. – Hannu Nov 26 '21 at 22:17
-
@Arian, If your program is a compiled program, you should modify the source code, compile and link it in order to modify it. If it is an interpreted program (as the examples bash or python scripts by Hannu), then you can modify it freely directly in the program code, because the source code is the executable program. – sudodus Nov 26 '21 at 23:01
-
My program is a compiled program, and it was just an example. Actually, I want to change the strings in closed-source programs, like Discord. – Arian Nov 28 '21 at 07:54
-
@Arian, With closed source programs you can only replace strings with strings of the same length, but as described in my example in the answer and in the comment by Hannu, you can replace a string with a shorter string plus blanks (padding). - Some programs may have a built-in check (using a checksum), that will stop them from working, if you change some strings. – sudodus Nov 28 '21 at 13:23
abc
withxyz
in my program. So, my program will printxyz
instead ofabc
. – Arian Nov 26 '21 at 19:38