Module: Baikal
- Defined in:
- lib/baikal.rb,
lib/baikal/tweak.rb,
lib/baikal/cursor.rb,
lib/baikal/hexdump.rb
Overview
Baikal is a tool for generating, parsing and modifying binary objects.
Defined Under Namespace
Modules: Hexdump Classes: Cursor, Pool
Constant Summary collapse
- VERSION =
'1.1.1'
Class Method Summary collapse
-
.hexdump(data_source, port = $stdout, format = Hexdump::DEFAULT_HEXDUMP_FORMAT) ⇒ Object
Hexdumps bytes from
data_sourceinto the givenport(by default, $stdout) using the given format (by default,DEFAULT_HEXDUMP_FORMAT).
Class Method Details
.hexdump(data_source, port = $stdout, format = Hexdump::DEFAULT_HEXDUMP_FORMAT) ⇒ Object
Hexdumps bytes from data_source into the given port (by default, $stdout) using the given format (by default, DEFAULT_HEXDUMP_FORMAT). Uses the length method of data_source to determine byte count and the [] method with integer range arguments to extract row-sized slices. data_source being a String instance behaves as expected.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/baikal/hexdump.rb', line 9 def Baikal::hexdump data_source, port = $stdout, format = Hexdump::DEFAULT_HEXDUMP_FORMAT row = Hexdump::Row.new row.expected_size = format.bytes_per_row # iterate over rows row.offset = 0 block_row_counter = 0 while row.offset < data_source.bytesize do if format.rows_per_block != 0 then block_row_counter += 1 if block_row_counter == format.rows_per_block then port.puts # block separator block_row_counter = 0 end end row.data = data_source.unpack "@#{row.offset} C#{format.bytes_per_row}" format.format_row row, port row.offset += format.bytes_per_row end return end |