试图在exe文件中输出所有内容
Trying to output everything inside an exe file
我试图输出这个。exe文件的明文内容。它有明文的东西,比如"以这种方式改变代码不会影响最终优化代码的质量",所有这些东西都被微软放在。exe文件中。当我运行下面的代码时,我得到M Z E
的输出,后面跟着一个红心和一个菱形。我做错了什么?
ifstream file;
char inputCharacter;
file.open("test.exe", ios::binary);
while ((inputCharacter = file.get()) != EOF)
{
cout << inputCharacter << "n";
}
file.close();
我会使用std::isprint之类的东西来确保字符是可打印的,而不是在打印之前使用一些奇怪的控制代码。
像这样:
#include <cctype>
#include <fstream>
#include <iostream>
int main()
{
std::ifstream file("test.exe", std::ios::binary);
char c;
while(file.get(c)) // don't loop on EOF
{
if(std::isprint(c)) // check if is printable
std::cout << c;
}
}
您已经以二进制格式打开了流,这对于预期的目的是很好的。但是,您可以按原样打印每个二进制数据:其中一些字符不可打印,从而产生奇怪的输出。
可能的解决方案:
如果你想打印一个exe文件的内容,你会得到更多的不可打印字符而不是可打印字符。因此,一种方法是打印十六进制值:
while ( file.get(inputCharacter ) )
{
cout << setw(2) << setfill('0') << hex << (int)(inputCharacter&0xff) << "n";
}
或者您可以使用调试器方法来显示十六进制值,然后在可打印或'时显示char。
while (file.get(inputCharacter)) {
cout << setw(2) << setfill('0') << hex << (int)(inputCharacter&0xff)<<" ";
if (isprint(inputCharacter & 0xff))
cout << inputCharacter << "n";
else cout << ".n";
}
嗯,为了人机工程学的缘故,如果exe文件包含任何真正的exe,你最好选择在每行显示几个字符;-)
二进制文件是字节的集合。字节的取值范围是0..255。可以安全地"打印"的可打印字符的范围要窄得多。假设最基本的ASCII编码
- 32 . . 63 64 . . 95 96 . . 126
- 加上,如果你的代码页有 ,可能会比128高一些
参见ASCII表
超出该范围的每个字符至少可以:
- 打印为不可见
- 打印成一些奇怪的垃圾
- 实际上是一个控制字符,它将改变终端的设置
一些终端支持"end of text"字符,并在此之后停止打印任何文本。也许你击中了。
我想说,如果你只对文本感兴趣,那么只打印可打印的,忽略其他的。或者,如果你想要所有的东西,那就把它们写成十六进制吧?
成功了:
ifstream file;
char inputCharacter;
string Result;
file.open("test.exe", ios::binary);
while (file.get(inputCharacter))
{
if ((inputCharacter > 31) && (inputCharacter < 127))
Result += inputCharacter;
}
cout << Result << endl;
cout << "These are the ascii characters in the exe file" << endl;
file.close();
相关文章:
- VI工作室代码错误无法打开输出文件主.exe
- 是否可以在C++中基于程序集输出(.dll或.exe)定义变量
- 无法在代码块 IDE 中打开输出文件.exe
- CMD:程序.exe 1< "A:/input.txt"产生无输出
- 在 Windows 命令行中运行.exe在使用 2 种相同方式执行时会产生不同的输出
- C ShellexeCuteex不会通过未从该EXE产生输出来执行参数
- 从 Java 运行C++ .exe程序没有输出,也没有接收输入
- 如何将.EXE从C 项目复制到C#项目的输出目录
- 从 exe 获取输出C++并在 Python 中实时处理它
- 无法打开输出文件___.exe:权限被拒绝
- Delphi 2007 EXE和C++DLL:调试输出:027D4FF8处的堆块在027D5009处修改,超过了请求的9
- 无法读取在cmd.exe管道下启动的进程的输出
- 当我尝试运行此代码输出时"merge.exe has stopped working"?
- 获得程序输出(无错误),但程序.exe在使用 graphics.h 时不起作用
- 将PowerShell.exe的输入和输出重定向到C 中的管道
- 从.exe输出到 cmd
- 如何将opencv和其他dll文件链接到visual studio 2013的输出exe
- CMD.EXE中的控制台输出,通过C 进行powershell.exe
- C++ - 将 ASCII 输出到 cmd.exe
- 如何禁用visual studio或输出exe上的调试断言对话框