无法复制可执行文件的内容?(Contents of executable files cannot be copied?)

编程入门 行业动态 更新时间:2024-10-09 06:25:51
无法复制可执行文件的内容?(Contents of executable files cannot be copied?)

因此,通过将原始文件的内容复制到空白文本文件中,可以将文本文件复制并粘贴到其他位置。 这可以使用文本编辑器完成。 突出显示文本文件的内容,复制,创建新的空白文本文件,粘贴到其中。

但是,为什么不能像这样复制和粘贴图像,音频,视频,可执行文件等? 例如,我用文本编辑器打开一个可执行文件,复制它的所有内容,创建一个新的空白文本文件,将扩展名更改为.exe,然后粘贴到它(通过文本编辑器)。 但是,该文件无法运行。 为什么?

此外,我希望能够像编辑文本文件一样编辑这些类型的文件。 有办法吗?

So, text files can be copied and pasted to another location by copying the contents of the original file into a blank text file. This can be done with a text editor. Highlight contents of text file, copy, create new blank text file, paste in to it.

But, why can't image, audio, video, executable files, etc., be copied and pasted like this? For example, I open an executable file with a text editor, copy all of it's contents, create a new blank text file, change the extension to .exe, and paste into it (through a text editor). But, the file cannot be run. Why?

Also, I would like to be able to edit these types of files like I do with text files. Is there a way?

最满意答案

因为可执行文件和媒体文件是“二进制”文件。 文本文件也是二进制文件,但不同。 所有文件都是二进制创建的,但有些文件比其他文件更加二进制。

您正在文本编辑器中打开二进制文件。 这会立即改变字节的语义。 主要问题是字节包含一个恰好与换行符相对应的值,如果它是一个文本文件( 0x0A和0x0D ),它将呈现为依赖于平台的换行符(例如,在Windows上为\r\n ) 。 复制时,您已将0x0A或0x0D更改为0x0D 0x0A 。

然后是控制字符或不可打印的字符。 并非0x00和0xFF之间的所有字节都可以表示为字符。 它们将被省略或替换为可显示的字符。

因此,当您复制包含这些内容的文本时,它们将被省略或以其他方式损坏。

总之:除非您选择对字节值进行编码,否则您无法可靠地使用文本来显示所有可能的字节值,就像使用Base64编码一样。

如果要编辑二进制文件,请使用知道这些字节的编辑器:“十六进制编辑器”。 请注意,更改二进制文件中的随机字节值并不能保证该文件的完整性:格式中可能存在校验和,您的编辑将使该校验和无效。

Because executable and media files are "binary" files. Text files are binary as well, but different. All files are created binary, but some are created more binary than others.

You're opening a binary file in a text editor. This immediately changes the semantics of the bytes. The main problem is bytes containing a value that happens to correspond to those of newline characters if it were a text file (0x0A and 0x0D), which will be rendered as a platform-dependent newline (\r\n on Windows, for example). When you copy that, you've changed either 0x0A or 0x0D to 0x0D 0x0A.

Then there's control characters or non-printable characters. Not all bytes between 0x00 and 0xFF can be represented as a character. They'll either be omitted or replaced with a displayable character.

So when you copy a text containing those, they'll be omitted or otherwise mangled.

In conclusion: you cannot reliably use text to display all possible byte values, unless you choose to encode the bytes' values, as is done using for example Base64 encoding.

If you want to edit a binary file, use an editor that is aware of those bytes: a "hex editor". Do note that changing random byte values in a binary file does not guarantee the sanity of that file: there may be checksums built into the format, and your edit will invalidate that checksum.

更多推荐

本文发布于:2023-08-06 10:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1448353.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可执行文件   内容   Contents   copied   files

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!