开发者

Looking for a tool to create C-arrays with data from a file [closed]

Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 8 years ago.

Improve this question

Input: filename.bin

Output:

char file_filename_data[] = {
0x47, 0x45, 0x54, 0x20, 0x2f, 0x63, 0x61, 0x6d, 
0x2e, 0x68, 0x74, 0x6d, 0x6c, 0x20, 0x48, 0x54, 
0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x0d, 0x0a, 
0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, 0x79, 0x6d, 
0x61, 0x70, 0x2e, 0x64, 0x79, 0x6e, 0x64, 0x6e, 
0x73, 0x2e, 0x6f, 0x72, 0x67, 0x0d, 0x0a, 0x55, 
0x73, 0x65, 0x72, 0x2d, 0x41, 0x67, 0x65, 0x6e, 
0x74, 0x3a, 0x20, 0x4d, 0x6f, 0x7a, 0x69, 0x6c, 
...
}; // This is the data from the file "filename.bin"

size_t file_filename_size = 1234;

I want to store some text files inside an executable file. I am using CMake and building C++ project both in linu开发者_如何学JAVAx and in windows.

Thank you!


xxd is what you're looking for. Example call could be:

xxd -i filename.bin data_output.h

data_output.h would have the contents of:

unsigned char in_file[] = {
  0x68, 0x65, 0x6c, 0x6c, 0x6f
};
unsigned int in_file_len = 5;


Most of the time you can append the information at the end of the file. It's a hack, but it's used by many apps - installers, python freeze (I think), lots of demo coders used it in the past.

Basically just do (CMD.EXE)

echo "Blah" >> myexefile.exe

How would you find this info? Well be inventive - maybe store a unique magic cookie, or just always put the last 4 or 8 bytes to tell you the size of the file, so you can find where it begins.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜