什么是正确的格式以及如何在 .bin 文件中正确组织字节以在 char 数组 [] 中设置?

What's correct format and how organize bytes correctly in a .bin file to set in a char array[]?

假设后面的字节数组包含可执行文件 (.exe) 的所有字节(在实践中,这不可能在源代码中设置,因为这种文件类型 (.exe) 中有很多字节 Visual Studio 会崩溃)

char buffer[] = { 0x60, 0x33, 0xC0, 0x33, 0xDB, 0xEB, 0x00, 0x03, 0xC3 };

然后我认为实现此目标的更好方法是 generate all bytes ( PS: like XTEA Runtime Crypter, but without variable declaration ) from .exe file 并插入 .bin 文件以便稍后在 char buffer[] 上设置,像这样:

vector<char> buffer;

ifstream infile;
infile.open("bytes.bin", ios::binary);
infile.seekg(0, ios::end);
size_t file_size_in_byte = infile.tellg();
buffer.resize(file_size_in_byte);
infile.seekg(0, ios::beg);
infile.read(&buffer[0], file_size_in_byte);
infile.close();

那我问:

生成 .bin 文件的正确字节格式是什么?

  1. 0x60, 0x33, 0xC0, 0x33, 0xDB, 0xEB, 0x00, 0x03, 0xC3 - 前面是 0x 并用逗号和 space 分隔(就像链接的 C++ 代码已经做的那样)?
  2. 0x600x330xC00x330xDB0xEB0x000x030xC3 - 没有任何 space/separation?
  3. 60, 33, C0, 33, DB, EB, 00, 03, C3 - 用逗号和 space 分隔,但前面没有 0x?
  4. Like showed in a Hex editor(不以 0x 开头且不以逗号分隔)?

你根本不格式化,只写原始字节。您正在使用

读取原始字节
infile.read(&buffer[0], file_size_in_byte);

同样,使用 ios::binary 打开输出文件,然后简单地调用

outfile.write(&buffer[0], some_number_of_bytes);