What happens when you save an exe file in a text editor?

I remember a long time ago opening an executable file (.exe) in a text editor and saving it to my hard drive. The executable, of course, did not open.

I understand that a file is a sequence of bytes. In the case of a text file, these bytes encode letters. In the case of an executable file, these bytes encode instructions.

Both text files and executables are just a series of bytes, and I understand that those bytes are only given by how you interpret them. The "a" can be a letter in apple or one byte in a legitimate program that encodes some low-level operation. Likewise, all program instructions can be interpreted as talisman symbols in the context of a text document.

So, so my question is why, since I didn't change anything in the file before saving it, it won't work as a program anymore. Does a series of bytes have to be exact?

What exactly changes in this file when I use a text editor that makes it no longer execute, even if the file name and content are the same?

+3


source to share


1 answer


This can be caused by many factors, including the following:

  • Not all characters can be printed. Non-printable characters may not be saved correctly.
  • Some text editors guarantee that the file is newline-terminated by default (ie: vi).
  • Changing even one character accidentally can make the program no longer executable.
  • Some text editors change OS newlines by default.
  • Autocorrection can change characters unintentionally.
  • If the file was saved in a different encoding, the characters may be saved in a different way.


For further exploration, try comparing before and after with a text editor or hex editor. You may find clues as to what actually changed.

+3


source







All Articles