-
-
Save carstene1ns/666a7bca1c9879da6dca to your computer and use it in GitHub Desktop.
`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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned char hello_world_txt[] = { | |
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x4f, 0x52, 0x4c, 0x44, 0x21 | |
}; | |
unsigned int hello_world_txt_len = 12; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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