Files
metasploit-gs/lib/metasm/misc/hexdump.rb
T
HD Moore 4a204efaa1 Import the new METASM code
git-svn-id: file:///home/svn/framework3/trunk@5008 4d416f70-5f16-0410-b530-b9f4589650da
2007-06-30 21:53:26 +00:00

37 lines
780 B
Ruby

#!/usr/bin/env ruby
# This file is part of Metasm, the Ruby assembly manipulation suite
# Copyright (C) 2007 Yoann GUILLOT
#
# Licence is LGPL, see LICENCE in the top-level directory
require 'enumerator'
class String
def hexdump
o = -16
lastl = []
lastdpl = false
unpack('C*').each_slice(16) { |s|
o += 16
if s != lastl
lastdpl = false
print '%04x ' % o
print s.map { |b| '%02x' % b }.join(' ').ljust(3*16-1) + ' '
print s.pack('C*').unpack('L*').map { |bb| '%08x' % bb }.join(' ').ljust(9*4-1) + ' '
puts s.map { |c| (32..126).include?(c) ? c : ?. }.pack('C*')
elsif not lastdpl
lastdpl = true
puts '*'
end
lastl = s
}
puts '%04x' % length
end
end
if $0 == __FILE__
File.open(ARGV.first, 'rb') { |fd| fd.read }.hexdump
end