Module: Ronin::CLI::BinaryTemplate Private

Included in:
Commands::Pack, Commands::Unpack
Defined in:
lib/ronin/cli/binary_template.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Module for commands that uses Ronin::Support::Binary::Template.

Since:

  • 2.1.0

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(command) ⇒ 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.

Adds the --endian, --arch, and --os options to the command class including Ronin::CLI::BinaryTemplate.

Parameters:

Since:

  • 2.1.0



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ronin/cli/binary_template.rb', line 38

def self.included(command)
  command.option :endian, short: '-E',
                          value: {
                            type: [:little, :big, :net]
                          },
                          desc: 'Sets the endianness'

  command.option :arch, short: '-A',
                        value: {
                          type: [
                            :x86, :x86_64,
                            :ppc, :ppc64,
                            :mips, :mips_le, :mips_be,
                            :mips64, :mips64_le, :mips64_be,
                            :arm, :arm_le, :arm_be,
                            :arm64, :arm64_le, :arm64_be
                          ]
                        },
                        desc: 'Sets the architecture'

  command.option :os, short: '-O',
                      value: {
                        type: [
                          :linux,
                          :macos,
                          :windows,
                          :android,
                          :apple_ios,
                          :bsd,
                          :freebsd,
                          :openbsd,
                          :netbsd
                        ]
                      },
                      desc: 'Sets the OS'
end

Instance Method Details

#build_template(types) ⇒ Ronin::Support::Binary::Template

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.

Builds a binary template for the given types and for the optional --endian, --arch, and --os options.

Parameters:

  • types (Array<Symbol, (Symbol, Integer)>)

    The types for each field in the binary template.

Returns:

  • (Ronin::Support::Binary::Template)

    The binary template.

Since:

  • 2.1.0



114
115
116
117
118
119
120
121
# File 'lib/ronin/cli/binary_template.rb', line 114

def build_template(types)
  Support::Binary::Template.new(types, endian: options[:endian],
                                       arch:   options[:arch],
                                       os:     options[:os])
rescue ArgumentError => error
  print_error(error.message)
  exit(1)
end

#parse_type(string) ⇒ Symbol, (Symbol, Integer)

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 type string.

Parameters:

  • string (String)

    The raw type signature to parse.

Returns:

  • (Symbol, (Symbol, Integer))

    The parsed type signature.

Since:

  • 2.1.0



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/ronin/cli/binary_template.rb', line 84

def parse_type(string)
  unless (match = string.match(/\A(?<type>[a-z0-9_]+)(?:\[(?<array_size>\d*)\])?\z/))
    print_error "invalid type: #{string}"
    exit(-1)
  end

  type       = match[:type].to_sym
  array_size = match[:array_size]

  if array_size && array_size.empty?
    # unbounded array
    type = (type..)
  elsif array_size
    # sized array
    type = [type, array_size.to_i]
  end

  return type
end