问题描述
我需要一个脚本/工具来读取二进制文件并输出 C/C++ 源代码数组(代表文件内容).有吗?
I need a script/tool which reads a binary file and outputs a C/C++ source code array (which represents the file content). Are there any?
(这个问题之前被删除了.我把这个问题放回去了,因为它很有价值.我正在谷歌上搜索这个并没有找到任何东西.当然自己编写代码很简单,但我会保存一些如果我能找到这么简单的脚本,几分钟就可以了.因此它很有价值.
(This question was deleted earlier. I put this question back in because it is valuable. I was searching for exactly this on Google and didn't found anything. Of course it is trivial to code myself but I would have saved some minutes if I would have found such a simple script. Thus it is valuable.
这个问题也有很多反对票,没有太多解释.请在投反对票之前发表评论,为什么您认为这没有价值或价值不高.
This questions also had a lot of down-votes without much explanation. Please comment before you down-vote why you think this is of no value or of bad value.
这个问题也让我对我所问的问题产生了很多困惑.如果有不清楚的地方,请询问.我真的不知道如何说得更清楚.有关示例,请参阅答案.
This question also caused a lot of confusion about what I am asking about. If something is unclear, please ask. I don't really know how to make it more clear. See the answers for examples.
另外(在这里提出问题之后),我已经有了几个答案.我只想将它们(再次)放在这里/链接它们,因为我认为它可能对其他搜索此内容的人有用.)
Also (after putting the question here), I already have several answers. I just want to put/link them here (again) because I think it might be useful for someone else searching for this.)
推荐答案
在 Debian 和其他 Linux 发行版上默认安装(连同 vim
)xxd
工具,哪个,给定 -i
选项,可以做你想做的事:
On Debian and other Linux distros is installed by default (along with vim
) the xxd
tool, which, given the -i
option, can do what you want:
matteo@teodeb:~/Desktop$ echo Hello World! > temp
matteo@teodeb:~/Desktop$ xxd -i temp
unsigned char temp[] = {
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21,
0x0a
};
unsigned int temp_len = 13;
这篇关于将文件转换为 C/C++ 源代码数组的脚本/工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!