mercredi 28 octobre 2015

Correct way to extract array data from binary?

There is a classic way to embed resource files as a C language array into a binary file, so that we can store some external resource files such as .jpeg or .txt files into a binary.

For example, in the header file we can define an array:

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
};

which contains the contents of the resource file, and it will be compile into the final binary.

There are lots of tools and tutorials on the web about this old trick, such as: http://ift.tt/1MUITot, http://ift.tt/1N9mpop and http://ift.tt/1N9mpot.

However, looks like most of these pages are talking about how to embed the data into binary file using C style array.

My question is, what is the correct way to find the start address of the resource files in the final binary in order to extract them?

Aucun commentaire:

Enregistrer un commentaire