Class: Ronin::CLI::Commands::Strings Private

Inherits:
FileProcessorCommand show all
Includes:
Ronin::CLI::CharSetOptions
Defined in:
lib/ronin/cli/commands/strings.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.

Finds all strings within a file/stream with a certain character set.

Usage

ronin strings [options] [FILE ...]

Options

-N, --numeric                    Searches for numeric characters (0-9)
-O, --octal                      Searches for octal characters (0-7)
-X, --upper-hex                  Searches for uppercase hexadecimal (0-9, A-F)
-x, --lower-hex                  Searches for lowercase hexadecimal (0-9, a-f)
-H, --hex                        Searches for hexadecimal chars (0-9, a-f, A-F)
    --upper-alpha                Searches for uppercase alpha chars (A-Z)
    --lower-alpha                Searches for lowercase alpha chars (a-z)
-A, --alpha                      Searches for alpha chars (a-z, A-Z)
    --alpha-num                  Searches for alpha-numeric chars (a-z, A-Z, 0-9)
-P, --punct                      Searches for punctuation chars
-S, --symbols                    Searches for symbolic chars
-s, --space                      Searches for all whitespace chars
-v, --visible                    Searches for all visible chars
-p, --printable                  Searches for all printable chars
-C, --control                    Searches for all control chars (\x00-\x1f, \x7f)
-a, --signed-ascii               Searches for all signed ASCII chars (\x00-\x7f)
    --ascii                      Searches for all ASCII chars (\x00-\xff)
-c, --chars CHARS                Searches for all chars in the custom char-set
-i, --include-chars CHARS        Include the additional chars to the char-set
-e, --exclude-chars CHARS        Exclude the additional chars from the char-set
-n, --min-length LEN             Minimum length of strings to print (Default: 4)

Arguments

[FILE ...]                       The file(s) to read

Examples

ronin strings --hex -n 32 file.bin

Since:

  • 2.0.0

Instance Attribute Summary

Attributes included from Ronin::CLI::CharSetOptions

#char_set

Instance Method Summary collapse

Methods included from Ronin::CLI::CharSetOptions

define_char_sets, included, #initialize

Methods inherited from FileProcessorCommand

#process_file, #run

Instance Method Details

#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.

Yields:

  • (file)

    If a block is given, the newly opened file will be yielded. Once the block returns the file will automatically be closed.

Yield Parameters:

  • file (File)

    The newly opened file.

Returns:

  • (File, nil)

    If no block is given, the newly opened file object will be returned. If no block was given, then nil will be returned.

Since:

  • 2.0.0



107
108
109
# File 'lib/ronin/cli/commands/strings.rb', line 107

def open_file(file,&block)
  super(file,'rb',&block)
end

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.

Prints a buffer to STDOUT.

Parameters:

  • buffer (String)

Since:

  • 2.0.0



139
140
141
142
143
144
145
146
# File 'lib/ronin/cli/commands/strings.rb', line 139

def print_buffer(buffer)
  if options[:null_byte]
    stdout.write(buffer)
    putc("\0")
  else
    puts buffer
  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.

Scans the input stream for printable strings.

Parameters:

  • input (IO, StringIO)

    The input string.

Since:

  • 2.0.0



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/ronin/cli/commands/strings.rb', line 117

def process_input(input)
  buffer     = String.new
  min_length = options[:min_length]

  input.each_char do |char|
    if @char_set.include_char?(char)
      buffer << char
    else
      print_buffer(buffer) if buffer.length >= min_length
      buffer.clear
    end
  end

  # print any remaining chars
  print_buffer(buffer) if buffer.length >= min_length
end