Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # My First Ruby - I LOVE HEX!
- # Large file will get slow speed.
- # I guess I should use File.open for such a case.
- if ARGV.length == 0 then
- puts "No file input"
- exit 1
- end
- if File.exist?(ARGV[0]) then
- printf "%s (%d bytes)\n", ARGV[0], File.size(ARGV[0])
- else
- STDERR.printf "No such file: %s\n", ARGV[0]
- exit 1
- end
- Align = 16
- offset = 0
- dump_s = ""
- File.binread(ARGV[0]).bytes { |c|
- if offset % Align == 0 then
- printf "%08X: ", offset
- end
- printf "%02X", c
- offset += 1
- print " "
- if /[[:print:]]/ === c.chr then
- dump_s << c
- else
- dump_s << "."
- end
- if offset % 16 == 0 then
- puts " " << dump_s
- dump_s = ""
- end
- }
- if offset % Align != 0 then
- puts " " * (Align - (offset % Align)) << " " + dump_s
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement