在记事本中打开.exe并将其保存回.exe [英] Opening .exe in notepad and saving it back to .exe

查看:97
本文介绍了在记事本中打开.exe并将其保存回.exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿所有,

我有.exe文件,我在我的C ++程序中打开并转换为十六进制。然后我想做一些更改并将其保存回一些file.exe。然而这种保存不起作用,这不是我的代码问题,因为我也用记事本检查了整个事情。



如果你在记事本中打开.exe,即使没有改变任何东西,并保存回来,那么.exe将不再打开!我正在使用Windows 8,它说这个应用程序无法在我的计算机上运行...。



为什么会这样?如何将.txt文件成功保存为.exe? (假设,txt中的代码对于.exe是正确的)

Hey all,
I have .exe file which I open in my C++ program and convert to hex. Then I would like to make some changes and save it back to some file.exe. This saving however doesn't work and that's not my code's problem since I checked whole thing using notepad too.

If you open .exe in notepad, even without changing anything, and save it back then the .exe won't open anymore! I'm using Windows 8 and it says that "This application won't work on my computer blabla...".

Why is that happening? How can I successfully save a .txt file as .exe? (assuming, the code in txt is correct for .exe)

推荐答案

记事本是一个文本编辑器,在编辑二进制文件时永远不会有用。 br />
我不确定你为什么要那样做,但这是不可能的。

改为使用二进制编辑器。
Notepad is a text editor, and will never be useful when it comes to edit binary files.
I'm not sure why you want to do that, but it is not possible.
Use a binary editor instead.


引用:

这不是我代码的问题因为我用记事本检查了整件事

and that's not my code's problem since I checked whole thing using notepad too



那只是表明记事本和程序都没有正确保存内容。对于记事本而言,它并不像专门用于编辑文本文件那样令人惊讶。记事本希望将文件视为由< cr>分隔的行< LF取代。它可能会尝试保存一些内容。



如果没有看到源代码,为什么你的程序没有成功很难猜到。如果您修改了您的问题(使用原始问题下面的绿色改善问题按钮),我愿意看看它。



作为phil。 o已经指出,你正在尝试重新发明一个二进制编辑器(有时也称为十六进制编辑器)。有几个很好的十六进制编辑器,你可以免费下载,这可能会让你更快。


That just shows that neither Notepad nor your program saved the contents correctly. For Notepad that doesn't come as a surprise as it specialized to edit text files. Notepad wants to see a file as line that are separated by <cr> <lf>. And it probably tries to save some of the contents just like that.

Why your program did not succeed is hard to guess without seeing the source code. If you'd amend your question (use the green Improve question button below your original question) I'd be willing to take a look at it.

As phil.o already pointed out, you are trying to re-invent a binary editor (sometimes named also hex editor). There are several good hex editors around that you could download for free and that would probably get you there faster.


其他答案清楚地告诉你,你不能(或不应该)这样做,但没有真正解释原因,这里是:



编译应用程序时,存在对可执行文件部分的静态引用,计算方式如下:以字节为单位的偏这些可以与可执行文件的.text和.data部分一样广泛,或者更像低级函数调用地址和跳转。



你应该打开一个exe在一个真正的反汇编程序中,找出为什么你不能只是将数据添加到可执行文件并告诉它运行。您将看到存在以字节为单位的硬编码跳转,以字节为单位的函数地址等。当您添加数据时,这些跳转会使处理器开始运行随机代码,从而导致异常。在您的情况下,我认为您正在编辑标题中的某些内容,导致Windows认为它不再是有效的可执行文件。
The other answers tell you pretty clearly that you can't (or shouldn't) do that, but don't really explain why, here it is:

When an application is compiled, there are static references to parts of the executable, calculated as offset in bytes. These can be as broad as the .text and .data sections of the executable, or more low-level like function call addresses and jumps.

You should open an exe in a real disassembler once to figure out why you can't just add data to an executable and tell it to run. You'll see that there are hard coded jumps in bytes, function addresses in bytes, etc. When you add data, these jumps make the processor start running random code, which causes an exception. In your case I think you are editing something in the header that causes Windows to believe its not a valid executable anymore.


这篇关于在记事本中打开.exe并将其保存回.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆