Skip to content

Instantly share code, notes, and snippets.

@wilkie
Created February 25, 2013 00:08
Show Gist options
  • Save wilkie/5026371 to your computer and use it in GitHub Desktop.
Save wilkie/5026371 to your computer and use it in GitHub Desktop.
A demostration of what xxd -i will do: It takes any binary file and generates a C-compatible file defining a static array of the contents which can then be #included in.
xxd -i foo.txt > output.txt
Lorem ipsum dolor sit amet, con­secte­tur adip­isc­ing elit. Duis vulpu­tate
nisi non mi adip­isc­ing vulpu­tate. Donec eges­tas inter­dum blandit.
Phasel­lus lec­tus mas­sa, var­ius vel var­ius in, congue a lacus. Nunc
mau­ris purus, pul­v­inar vel blandit non, vestibu­lum in ante. Sed molestie,
leo ac facil­i­sis ornare, odio nulla accum­san purus, vitae adip­isc­ing
velit elit vitae nisl. Pel­len­tesque odio nisi, male­suada in sus­cipit sit
amet, lacinia ut tel­lus. Pel­len­tesque feu­giat enim a justo tem­por
ultricies.
unsigned char moo_txt[] = {
0x4c, 0x6f, 0x72, 0x65, 0x6d, 0x20, 0x69, 0x70, 0x73, 0x75, 0x6d, 0x20,
0x64, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x73, 0x69, 0x74, 0x20, 0x61, 0x6d,
0x65, 0x74, 0x2c, 0x20, 0x63, 0x6f, 0x6e, 0xc2, 0xad, 0x73, 0x65, 0x63,
0x74, 0x65, 0xc2, 0xad, 0x74, 0x75, 0x72, 0x20, 0x61, 0x64, 0x69, 0x70,
0xc2, 0xad, 0x69, 0x73, 0x63, 0xc2, 0xad, 0x69, 0x6e, 0x67, 0x20, 0x65,
0x6c, 0x69, 0x74, 0x2e, 0x20, 0x44, 0x75, 0x69, 0x73, 0x20, 0x76, 0x75,
0x6c, 0x70, 0x75, 0xc2, 0xad, 0x74, 0x61, 0x74, 0x65, 0x0a, 0x6e, 0x69,
0x73, 0x69, 0x20, 0x6e, 0x6f, 0x6e, 0x20, 0x6d, 0x69, 0x20, 0x61, 0x64,
0x69, 0x70, 0xc2, 0xad, 0x69, 0x73, 0x63, 0xc2, 0xad, 0x69, 0x6e, 0x67,
0x20, 0x76, 0x75, 0x6c, 0x70, 0x75, 0xc2, 0xad, 0x74, 0x61, 0x74, 0x65,
0x2e, 0x20, 0x44, 0x6f, 0x6e, 0x65, 0x63, 0x20, 0x65, 0x67, 0x65, 0x73,
0xc2, 0xad, 0x74, 0x61, 0x73, 0x20, 0x69, 0x6e, 0x74, 0x65, 0x72, 0xc2,
0xad, 0x64, 0x75, 0x6d, 0x20, 0x62, 0x6c, 0x61, 0x6e, 0x64, 0x69, 0x74,
0x2e, 0x0a, 0x50, 0x68, 0x61, 0x73, 0x65, 0x6c, 0xc2, 0xad, 0x6c, 0x75,
0x73, 0x20, 0x6c, 0x65, 0x63, 0xc2, 0xad, 0x74, 0x75, 0x73, 0x20, 0x6d,
0x61, 0x73, 0xc2, 0xad, 0x73, 0x61, 0x2c, 0x20, 0x76, 0x61, 0x72, 0xc2,
0xad, 0x69, 0x75, 0x73, 0x20, 0x76, 0x65, 0x6c, 0x20, 0x76, 0x61, 0x72,
0xc2, 0xad, 0x69, 0x75, 0x73, 0x20, 0x69, 0x6e, 0x2c, 0x20, 0x63, 0x6f,
0x6e, 0x67, 0x75, 0x65, 0x20, 0x61, 0x20, 0x6c, 0x61, 0x63, 0x75, 0x73,
0x2e, 0x20, 0x4e, 0x75, 0x6e, 0x63, 0x0a, 0x6d, 0x61, 0x75, 0xc2, 0xad,
0x72, 0x69, 0x73, 0x20, 0x70, 0x75, 0x72, 0x75, 0x73, 0x2c, 0x20, 0x70,
0x75, 0x6c, 0xc2, 0xad, 0x76, 0xc2, 0xad, 0x69, 0x6e, 0x61, 0x72, 0x20,
0x76, 0x65, 0x6c, 0x20, 0x62, 0x6c, 0x61, 0x6e, 0x64, 0x69, 0x74, 0x20,
0x6e, 0x6f, 0x6e, 0x2c, 0x20, 0x76, 0x65, 0x73, 0x74, 0x69, 0x62, 0x75,
0xc2, 0xad, 0x6c, 0x75, 0x6d, 0x20, 0x69, 0x6e, 0x20, 0x61, 0x6e, 0x74,
0x65, 0x2e, 0x20, 0x53, 0x65, 0x64, 0x20, 0x6d, 0x6f, 0x6c, 0x65, 0x73,
0x74, 0x69, 0x65, 0x2c, 0x0a, 0x6c, 0x65, 0x6f, 0x20, 0x61, 0x63, 0x20,
0x66, 0x61, 0x63, 0x69, 0x6c, 0xc2, 0xad, 0x69, 0xc2, 0xad, 0x73, 0x69,
0x73, 0x20, 0x6f, 0x72, 0x6e, 0x61, 0x72, 0x65, 0x2c, 0x20, 0x6f, 0x64,
0x69, 0x6f, 0x20, 0x6e, 0x75, 0x6c, 0x6c, 0x61, 0x20, 0x61, 0x63, 0x63,
0x75, 0x6d, 0xc2, 0xad, 0x73, 0x61, 0x6e, 0x20, 0x70, 0x75, 0x72, 0x75,
0x73, 0x2c, 0x20, 0x76, 0x69, 0x74, 0x61, 0x65, 0x20, 0x61, 0x64, 0x69,
0x70, 0xc2, 0xad, 0x69, 0x73, 0x63, 0xc2, 0xad, 0x69, 0x6e, 0x67, 0x0a,
0x76, 0x65, 0x6c, 0x69, 0x74, 0x20, 0x65, 0x6c, 0x69, 0x74, 0x20, 0x76,
0x69, 0x74, 0x61, 0x65, 0x20, 0x6e, 0x69, 0x73, 0x6c, 0x2e, 0x20, 0x50,
0x65, 0x6c, 0xc2, 0xad, 0x6c, 0x65, 0x6e, 0xc2, 0xad, 0x74, 0x65, 0x73,
0x71, 0x75, 0x65, 0x20, 0x6f, 0x64, 0x69, 0x6f, 0x20, 0x6e, 0x69, 0x73,
0x69, 0x2c, 0x20, 0x6d, 0x61, 0x6c, 0x65, 0xc2, 0xad, 0x73, 0x75, 0x61,
0x64, 0x61, 0x20, 0x69, 0x6e, 0x20, 0x73, 0x75, 0x73, 0xc2, 0xad, 0x63,
0x69, 0x70, 0x69, 0x74, 0x20, 0x73, 0x69, 0x74, 0x0a, 0x61, 0x6d, 0x65,
0x74, 0x2c, 0x20, 0x6c, 0x61, 0x63, 0x69, 0x6e, 0x69, 0x61, 0x20, 0x75,
0x74, 0x20, 0x74, 0x65, 0x6c, 0xc2, 0xad, 0x6c, 0x75, 0x73, 0x2e, 0x20,
0x50, 0x65, 0x6c, 0xc2, 0xad, 0x6c, 0x65, 0x6e, 0xc2, 0xad, 0x74, 0x65,
0x73, 0x71, 0x75, 0x65, 0x20, 0x66, 0x65, 0x75, 0xc2, 0xad, 0x67, 0x69,
0x61, 0x74, 0x20, 0x65, 0x6e, 0x69, 0x6d, 0x20, 0x61, 0x20, 0x6a, 0x75,
0x73, 0x74, 0x6f, 0x20, 0x74, 0x65, 0x6d, 0xc2, 0xad, 0x70, 0x6f, 0x72,
0x0a, 0x75, 0x6c, 0x74, 0x72, 0x69, 0x63, 0x69, 0x65, 0x73, 0x2e, 0x0a
};
unsigned int moo_txt_len = 564;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment