Skip to content

Instantly share code, notes, and snippets.

@carstene1ns carstene1ns/ unxxd.rb
Last active Jun 5, 2018

Embed
What would you like to do?
`xxd -i` creates header files with hexdumps of any raw file. This simple ruby script saves the content of the header file in raw form.
#!/usr/bin/env ruby
# read
xxd = IO.read('file.xxd')
# values are comma separated
chars = xxd.split(',')
# with whitespaces
chars.map! {|c| c.strip}
# in hex
chars.map! {|c| c.to_i(16)}
# put back together
xxd = chars.pack('c*')
# write
File.open('file.raw','w') {|f| f.write xxd}
unsigned char hello_world_txt[] = {
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x4f, 0x52, 0x4c, 0x44, 0x21
};
unsigned int hello_world_txt_len = 12;
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x4f, 0x52, 0x4c, 0x44, 0x21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.