您可以将有效负载写入文件并使用std::ifstream
来读取它。这将允许您更改有效内容,而无需重新编译。
如果你真的希望将其存储为二进制数据,你可以使用一个字符数组,并初始化它这样:
const unsigned char raw_data[] = {
0x21, 0x20, 0xc2, 0xa6, 0xc3, 0xb4, 0xc2, 0xbf,
0xc3, 0x82, 0xc3, 0x8b, 0xc2, 0xa4, 0x20, 0xc3,
0x8d, 0xc3, 0x8c, 0x4c, 0x3f, 0x20, 0x20, 0xc3,
0x80, 0xc3, 0xbf, 0x20, 0x20, 0xc3, 0x80, 0xc3,
0xbf, 0xc2, 0xa5, 0x20, 0xc5, 0xa1, 0xe2, 0x84,
0xa2, 0xc2, 0xa9, 0x40, 0x20, 0x20, 0xc3, 0x80,
0xc3, 0xbf, 0x20, 0x20, 0xc3, 0x80, 0xc3, 0xbf,
0x60, 0x20, 0x6f, 0x72, 0x20, 0x60, 0x21, 0x20,
0x48, 0xc2, 0xb7, 0xc3, 0xb4, 0xc2, 0xbf, 0xc3,
0x82, 0xc3, 0x8b, 0xc2, 0xa4, 0x20, 0xc3, 0x8d,
0xc3, 0x8c, 0x4c, 0x3f, 0x20, 0x20, 0xc3, 0x80,
0xc3, 0xbf, 0x33, 0x33, 0x33, 0x3f, 0xc2, 0xa5,
0x20, 0xc5, 0xa1, 0xe2, 0x84, 0xa2, 0xc2, 0xa9,
0x40, 0x20, 0x20, 0xc3, 0x80, 0xc3, 0xbf, 0x66,
0x66, 0xc2, 0xa6, 0x40, 0x0a,
};
std::string data(
reinterpret_cast< const char* >(raw_data),
reinterpret_cast< const char* >(raw_data) + sizeof(raw_data));
哦,顺便说一句,我使用转换你的有效载荷,以缓冲以下简单的Python代码:
#!/usr/bin/python
def convert_file(path, stream):
data = open(path, 'rb').read()
stream.write('const unsigned char raw_data[] = {')
for i, char in enumerate(data):
if i % 8 == 0:
stream.write('\n ')
stream.write(' 0x%02x,' % (ord(char),))
stream.write('\n};\n')
if __name__ == '__main__':
import sys
convert_file(sys.argv[1], sys.stdout)
我想的有效载荷存储在一个文件,但接缝像我必须把不同的有效载荷在不同的文件,因为我不知道该用什么分隔符。你也知道,如果我能得到一个脚本或命令从二进制数据中获取char数组?谢谢 – Arthur 2011-02-02 10:55:22