gpt4 book ai didi

c++ - 从二进制中提取数组数据的正确方法?

转载 作者:太空狗 更新时间:2023-10-29 23:00:35 25 4
gpt4 key购买 nike

有一种经典的方法是将资源文件作为C语言的数组嵌入到二进制文件中,这样我们就可以存储一些外部资源文件如.jpeg.txt 文件转换为二进制文件。

比如在头文件中我们可以定义一个数组:

const unsigned char xd_data[] = {
77,90,144,0,3,0,0,0,4,0,0,0,255,255,0,0,184,0,0,0,0,0,0,0,64,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,0,0,
0,14,31,186,14,0,180,9,205,33,184,1,76,205,33,84,104,105,115,32,112,114,
111,103,114,97,109,32,99,97,110,110,111,116,32,98,101,32,114,117,110,
32,105,110,32,68,79,83,32,109,111,100,101,46,13,13,10,36,0,0,0,0,0,0,
0,66,163,223,218,6,194,177,137,6,194,177,137,6,194,177,137,105,221,187,
137,13,194,177,137,133,222,191,137,3,194,177,137,105,221,181,137,4,194,
177,137,136,202,238,137,4,194,177,137,6,194,176,137,73,194,177,137,133,
202,236,137,13,194,177,137,48,228,187,137,11,194,177,137,193,196,183,
137,7,194,177,137,82,105,99,104,6,194,177,137,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,80,69,0,0,76,1,4,0,65,162,32,86,0,0,0,0,0,0,0,
0,224,0,47,1,11,1,6,0,0,100,0,0,0,74,0,0,0,0,0,0,228,113,0,0,0,16,0,0,
0,128,0,0,0,0,64,0,0,16,0,0,0,2,0,0,4,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,
224,0,0,0,4,0,0,0,0,0,0,2,0,0,0,0,0,16,0,0,16,0,0,0,0,16,0,0,16,0,0,0,
0,0,0,16,0,0,0,0,0,0,0,0,0,0,0,124,140,0,0,140,0,0,0,0,208,0,0,0,16,0
};

其中包含资源文件的内容,将被编译成最终的二进制文件。

网络上有很多关于这个老把戏的工具和教程,例如:http://www.rowleydownload.co.uk/arm/documentation/index.htm?http://www.rowleydownload.co.uk/arm/documentation/embed.htm , https://www.fourmilab.ch/xd/http://gareus.org/wiki/embedding_resources_in_executables#c_include_method .

但是,看起来大多数这些页面都在谈论如何使用 C 样式数组将数据嵌入到二进制文件中。

我的问题是,在已编译的二进制文件中找到资源文件的起始地址以便提取它们的正确方法是什么?即,如何在编译后的二进制文件中找到 xd_data 的起始地址?

最佳答案

如果您的意思是像 objdump 那样以编程方式查找数据 block 开始的文件中的字节地址,那么您可以使用二进制文件描述符库 (BFD),请参阅 herehere .

关于c++ - 从二进制中提取数组数据的正确方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33402972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com