Class: Ronin::CLI::Commands::Hexdump Private
- Inherits:
-
FileProcessorCommand
- Object
- Core::CLI::Command
- Ronin::CLI::Command
- FileProcessorCommand
- Ronin::CLI::Commands::Hexdump
- Defined in:
- lib/ronin/cli/commands/hexdump.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Hexdumps data in a variety of encodings and formats.
Usage
ronin hexdump [] [FILE ...]
Options
-t int8|uint8|char|uchar|byte|int16|int16_le|int16_be|int16_ne|uint16|uint16_le|uint16_be|uint16_ne|short|short_le|short_be|short_ne|ushort|ushort_le|ushort_be|ushort_ne|int32|int32_le|int32_be|int32_ne|uint32|uint32_le|uint32_be|uint32_ne|int|long|long_le|long_be|long_ne|uint|ulong|ulong_le|ulong_be|ulong_ne|int64|int64_le|int64_be|int64_ne|uint64|uint64_le|uint64_be|uint64_ne|long_long|long_long_le|long_long_be|long_long_ne|ulong_long|ulong_long_le|ulong_long_be|ulong_long_ne|float|float_le|float_be|float_ne|double|double_le|double_be|double_ne, --type The binary data type to decode the data as (Default: byte) -O, --offset INDEX Offset within the data to start hexdumping at -L, --length LEN Length of data to hexdump -Z, --zero-pad Enables zero-padding the input data -c, --columns WIDTH The number of bytes to hexdump per line -g, --group-columns WIDTH Groups columns together -G, --group-chars WIDTH|type Group characters into columns -r, --[no-]repeating Allows repeating lines in hexdump output -b, --base 2|8|10|16 Base to print numbers in -B, --index-base 2|8|10|16 Base to print the index addresses in -I, --index-offset INT Starting number for the index addresses -C, --[no-]chars-column Enables/disables the characters column -E, --encoding ascii|utf8 Encoding to display the characters in (Default: ascii) --style-index STYLE ANSI styles the index column --style-numeric STYLE ANSI styles the numeric columns --style-chars STYLE ANSI styles the characters column --highlight-index PATTERN:STYLE Applies ANSI highlighting to the index column --highlight-numeric PATTERN:STYLE Applies ANSI highlighting to the numeric column --highlight-chars PATTERN:STYLE Applies ANSI highlighting to the characters column -h, --help Print help information
Arguments
[FILE] Optional file to hexdump
Constant Summary collapse
- TYPES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Supported types for the
-t,--type
option. [ :int8, :uint8, :char, :uchar, :byte, # default :int16, :int16_le, :int16_be, :int16_ne, :uint16, :uint16_le, :uint16_be, :uint16_ne, :short, :short_le, :short_be, :short_ne, :ushort, :ushort_le, :ushort_be, :ushort_ne, :int32, :int32_le, :int32_be, :int32_ne, :uint32, :uint32_le, :uint32_be, :uint32_ne, :int, :long, :long_le, :long_be, :long_ne, :uint, :ulong, :ulong_le, :ulong_be, :ulong_ne, :int64, :int64_le, :int64_be, :int64_ne, :uint64, :uint64_le, :uint64_be, :uint64_ne, :long_long, :long_long_le, :long_long_be, :long_long_ne, :ulong_long, :ulong_long_le, :ulong_long_be, :ulong_long_ne, :float, :float_le, :float_be, :float_ne, :double, :double_le, :double_be, :double_ne ]
- BASES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Mapping of supported values for the
-b,--base
option. {'2' => 2, '8' => 8, '10' => 10, '16' => 16}
- STYLES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Mapping of style names to Symbols.
{ # font styling 'bold' => :bold, 'faint' => :faint, 'italic' => :italic, 'underline' => :underline, 'invert' => :invert, 'strike' => :strike, # foreground colors 'black' => :black, 'red' => :red, 'green' => :green, 'yellow' => :yellow, 'blue' => :blue, 'magenta' => :magenta, 'cyan' => :cyan, 'white' => :white, # background colors 'on_black' => :on_black, 'on_red' => :on_red, 'on_green' => :on_green, 'on_yellow' => :on_yellow, 'on_blue' => :on_blue, 'on_magenta' => :on_magenta, 'on_cyan' => :on_cyan, 'on_white' => :on_white }
- HEXDUMP_OPTIONS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
List of command
options
that directly map to the keyword arguments ofHexdump.hexdump
. [ :type, :format, :offset, :length, :zero_pad, :columns, :group_columns, :group_chars, :repeating, :base, :index_base, :index_offset, :chars_column, :encoding ]
Instance Attribute Summary collapse
-
#highlight_chars ⇒ Array<(Regexp, Array<Symbol>)>, Array<(String, Array<Symbol>)>
readonly
private
The highlighting rules to apply to the characters column.
-
#highlight_index ⇒ Array<(Regexp, Array<Symbol>)>, Array<(String, Array<Symbol>)>
readonly
private
The highlighting rules to apply to the index column.
-
#highlight_numeric ⇒ Array<(Regexp, Array<Symbol>)>, Array<(String, Array<Symbol>)>
readonly
private
The highlighting rules to apply to the numeric column.
Instance Method Summary collapse
-
#hexdump_highlights_kwargs ⇒ Hash{Symbol => Object}
private
The hexdump
highlights:
keyword arguments. -
#hexdump_kwargs ⇒ Hash{Symbol => Object}
private
Creates a keyword arguments
Hash
of all commandoptions
that will be directly passed toHexdump.hexdump
. -
#hexdump_style_kwargs ⇒ Hash{Symbol => Object}
private
The hexdump
style:
keyword arguments. -
#initialize(**kwargs) ⇒ Hexdump
constructor
private
Initializes the
hexdump
command. -
#open_file(file) {|file| ... } ⇒ File?
private
Opens the file in binary mode.
-
#parse_group_chars(value) ⇒ Integer, :type
private
Parses the value passed to the
-G,--group-chars
option. -
#parse_highlight(value) ⇒ (Regexp, Array<Symbol>), (String, Array<Symbol>)
private
Parses a highlight rule of the form
/REGEXP/:STYLE
orSTRING:STYLE
. -
#parse_style(value) ⇒ Array<Symbol>
private
Parses a style string.
-
#process_input(input) ⇒ Object
private
Hexdumps the input stream.
-
#run(*files) ⇒ Object
private
Runs the
ronin hexdump
command.
Methods inherited from FileProcessorCommand
Constructor Details
#initialize(**kwargs) ⇒ Hexdump
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes the hexdump
command.
270 271 272 273 274 275 276 |
# File 'lib/ronin/cli/commands/hexdump.rb', line 270 def initialize(**kwargs) super(**kwargs) @highlight_index = {} @highlight_numeric = {} @highlight_chars = {} end |
Instance Attribute Details
#highlight_chars ⇒ Array<(Regexp, Array<Symbol>)>, Array<(String, Array<Symbol>)> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The highlighting rules to apply to the characters column.
265 266 267 |
# File 'lib/ronin/cli/commands/hexdump.rb', line 265 def highlight_chars @highlight_chars end |
#highlight_index ⇒ Array<(Regexp, Array<Symbol>)>, Array<(String, Array<Symbol>)> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The highlighting rules to apply to the index column.
253 254 255 |
# File 'lib/ronin/cli/commands/hexdump.rb', line 253 def highlight_index @highlight_index end |
#highlight_numeric ⇒ Array<(Regexp, Array<Symbol>)>, Array<(String, Array<Symbol>)> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The highlighting rules to apply to the numeric column.
259 260 261 |
# File 'lib/ronin/cli/commands/hexdump.rb', line 259 def highlight_numeric @highlight_numeric end |
Instance Method Details
#hexdump_highlights_kwargs ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The hexdump highlights:
keyword arguments.
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 |
# File 'lib/ronin/cli/commands/hexdump.rb', line 492 def hexdump_highlights_kwargs highlights = {} unless @highlight_index.empty? highlights[:index] = @highlight_index end unless @highlight_numeric.empty? highlights[:numeric] = @highlight_numeric end unless @highlight_chars.empty? highlights[:chars] = @highlight_chars end return highlights end |
#hexdump_kwargs ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a keyword arguments Hash
of all command options
that will
be directly passed to Hexdump.hexdump
.
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
# File 'lib/ronin/cli/commands/hexdump.rb', line 442 def hexdump_kwargs kwargs = {} HEXDUMP_OPTIONS.each do |key| kwargs[key] = [key] if .has_key?(key) end if .has_key?(:style_index) || .has_key?(:style_numeric) || .has_key?(:style_chars) kwargs[:style] = hexdump_style_kwargs end if !@highlight_index.empty? || !@highlight_numeric.empty? || !@highlight_chars.empty? kwargs[:highlights] = hexdump_highlights_kwargs end return kwargs end |
#hexdump_style_kwargs ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The hexdump style:
keyword arguments.
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
# File 'lib/ronin/cli/commands/hexdump.rb', line 469 def hexdump_style_kwargs style = {} if (index_style = [:style_index]) style[:index] = index_style end if (numeric_style = [:style_numeric]) style[:numeric] = numeric_style end if (chars_style = [:style_chars]) style[:chars] = chars_style end return style end |
#open_file(file) {|file| ... } ⇒ File?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Opens the file in binary mode.
304 305 306 |
# File 'lib/ronin/cli/commands/hexdump.rb', line 304 def open_file(file,&block) File.open(file,'rb',&block) end |
#parse_group_chars(value) ⇒ Integer, :type
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parses the value passed to the -G,--group-chars
option.
327 328 329 330 331 332 333 334 |
# File 'lib/ronin/cli/commands/hexdump.rb', line 327 def parse_group_chars(value) case value when 'type' then :type when /^\d+$/ then value.to_i else raise(OptionParser::InvalidArgument,"invalid value: #{value}") end end |
#parse_highlight(value) ⇒ (Regexp, Array<Symbol>), (String, Array<Symbol>)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parses a highlight rule of the form /REGEXP/:STYLE
or
STRING:STYLE
.
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/ronin/cli/commands/hexdump.rb', line 395 def parse_highlight(value) if value.start_with?('/') unless (index = value.rindex('/:')) raise(OptionParser::InvalidArgument,"argument must be of the form /REGEXP/:STYLE but was: #{value}") end regexp = Regexp.new(value[1...index]) style = parse_style(value[(index + 2)..]) return [regexp, style] else unless (index = value.rindex(':')) raise(OptionParser::InvalidArgument,"argument must be of the form STRING:STYLE but was: #{value}") end pattern = value[0...index] style = parse_style(value[(index + 1)..]) return [pattern, style] end end |
#parse_style(value) ⇒ Array<Symbol>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parses a style string.
376 377 378 379 380 381 382 |
# File 'lib/ronin/cli/commands/hexdump.rb', line 376 def parse_style(value) value.split(/\s*,\s*/).map do |style_name| STYLES.fetch(style_name) do raise(OptionParser::InvalidArgument,"unknown style name: #{style_name}") end end end |
#process_input(input) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Hexdumps the input stream.
314 315 316 |
# File 'lib/ronin/cli/commands/hexdump.rb', line 314 def process_input(input) @hexdump.hexdump(input) end |
#run(*files) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Runs the ronin hexdump
command.
284 285 286 287 288 |
# File 'lib/ronin/cli/commands/hexdump.rb', line 284 def run(*files) @hexdump = ::Hexdump::Hexdump.new(**hexdump_kwargs) super(*files) end |