Class: Ronin::Code::ASM::Syntax::Common

Inherits:
Object
  • Object
show all
Defined in:
lib/ronin/code/asm/syntax/common.rb

Overview

Abstract base-class for all Assembly Syntax classes.

Direct Known Subclasses

ATT, Intel

Constant Summary collapse

BITS =

Bit sizes for various architectures

{
  x86:   32,
  amd64: 64,
}

Class Method Summary collapse

Class Method Details

.emit_float(value) ⇒ String

This method is abstract.

Emits a floating point number.

Parameters:

  • value (Float)

    The number.

Returns:

  • (String)

    The formatted float.



92
93
# File 'lib/ronin/code/asm/syntax/common.rb', line 92

def self.emit_float(value)
end

.emit_immediate_operand(op) ⇒ String

This method is abstract.

Emits an immediate operand.

Parameters:

Returns:

  • (String)

    The formatted immediate operand.



106
107
# File 'lib/ronin/code/asm/syntax/common.rb', line 106

def self.emit_immediate_operand(op)
end

.emit_instruction(ins) ⇒ String

This method is abstract.

Emits an instruction.

Parameters:

Returns:

  • (String)

    The formatted instruction.



178
179
# File 'lib/ronin/code/asm/syntax/common.rb', line 178

def self.emit_instruction(ins)
end

.emit_integer(value) ⇒ String

Emits an integer.

Parameters:

  • value (Integer)

    The integer.

Returns:

  • (String)

    The formatted integer.



75
76
77
78
79
# File 'lib/ronin/code/asm/syntax/common.rb', line 75

def self.emit_integer(value)
  if value >= 0 then "0x%x" % value
  else               "-0x%x" % value.abs
  end
end

.emit_keyword(name) ⇒ String

Emits a keyword.

Parameters:

  • name (Symbol)

    Name of the keyword.

Returns:

  • (String)

    The formatted keyword.



49
50
51
# File 'lib/ronin/code/asm/syntax/common.rb', line 49

def self.emit_keyword(name)
  name.to_s
end

.emit_label(name) ⇒ String

Emits a label.

Parameters:

  • name (Symbol)

    The name of the label.

Returns:

  • (String)

    The formatted label.



163
164
165
# File 'lib/ronin/code/asm/syntax/common.rb', line 163

def self.emit_label(name)
  "#{name}:"
end

.emit_memory_operand(op) ⇒ String

This method is abstract.

Emits an memory operand.

Parameters:

Returns:

  • (String)

    The formatted memory operand.



120
121
# File 'lib/ronin/code/asm/syntax/common.rb', line 120

def self.emit_memory_operand(op)
end

.emit_operand(op) ⇒ String

Emits an operand.

Parameters:

Returns:

  • (String)

    The formatted operand.



132
133
134
135
136
137
138
139
# File 'lib/ronin/code/asm/syntax/common.rb', line 132

def self.emit_operand(op)
  case op
  when ImmediateOperand then emit_immediate_operand(op)
  when MemoryOperand    then emit_memory_operand(op)
  when Register         then emit_register(op)
  when Symbol           then emit_keyword(op)
  end
end

.emit_operands(ops) ⇒ String

Emits multiple operands.

Parameters:

Returns:

  • (String)

    The formatted operands.



150
151
152
# File 'lib/ronin/code/asm/syntax/common.rb', line 150

def self.emit_operands(ops)
  ops.map { |op| emit_operand(op) }.join(",\t")
end

.emit_program(program) ⇒ String

Emits a program.

Parameters:

  • program (Program)

    The program.

Returns:

  • (String)

    The formatted program.



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/ronin/code/asm/syntax/common.rb', line 218

def self.emit_program(program)
  lines = [
    emit_prologue(program),
    emit_section(:text),
    emit_label(:_start)
  ].compact

  program.instructions.each do |ins|
    case ins
    when Symbol      then lines << emit_label(ins)
    when Instruction then lines << "\t#{emit_instruction(ins)}"
    end
  end

  lines << ''

  return lines.join($/)
end

.emit_prologue(program) ⇒ String

Emits the program's prologue.

Parameters:

  • program (Program)

    The program.

Returns:

  • (String)

    The formatted prologue.

Since:

  • 0.2.0



206
207
# File 'lib/ronin/code/asm/syntax/common.rb', line 206

def self.emit_prologue(program)
end

.emit_register(reg) ⇒ String

This method is abstract.

Emits a register.

Parameters:

Returns:

  • (String)

    The formatted register.



63
64
# File 'lib/ronin/code/asm/syntax/common.rb', line 63

def self.emit_register(reg)
end

.emit_section(name) ⇒ String

Emits a section name.

Parameters:

  • name (Symbol)

    The section name.

Returns:

  • (String)

    The formatted section name.

Since:

  • 0.2.0



192
193
# File 'lib/ronin/code/asm/syntax/common.rb', line 192

def self.emit_section(name)
end