Class: Ronin::Code::ASM::Syntax::Intel

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

Constant Summary collapse

WIDTHS =

Data sizes and their identifiers

{
  1 => 'BYTE',
  2 => 'WORD',
  4 => 'DWORD',
  8 => 'QWORD'
}

Constants inherited from Common

Common::BITS

Class Method Summary collapse

Methods inherited from Common

emit_float, emit_integer, emit_keyword, emit_label, emit_operand, emit_operands, emit_program

Class Method Details

.emit_immediate_operand(op) ⇒ String

Emits an immediate operand.

Parameters:

Returns:

  • (String)

    The formatted immediate operand.



59
60
61
# File 'lib/ronin/code/asm/syntax/intel.rb', line 59

def self.emit_immediate_operand(op)
  "#{WIDTHS[op.width]} #{emit_integer(op.value)}"
end

.emit_instruction(ins) ⇒ String

Emits an instruction.

Parameters:

Returns:

  • (String)

    The formatted instruction.



106
107
108
109
110
111
112
113
114
# File 'lib/ronin/code/asm/syntax/intel.rb', line 106

def self.emit_instruction(ins)
  line = emit_keyword(ins.name)

  unless ins.operands.empty?
    line << "\t" << emit_operands(ins.operands)
  end

  return line
end

.emit_memory_operand(op) ⇒ String

Emits a memory operand.

Parameters:

Returns:

  • (String)

    The formatted memory operand.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/ronin/code/asm/syntax/intel.rb', line 72

def self.emit_memory_operand(op)
  asm = emit_register(op.base)

  if op.index
    asm << '+' << emit_register(op.index)
    asm << '*' << emit_integer(op.scale) if op.scale > 1
  end

  if op.offset != 0
    sign = if op.offset >= 0 then '+'
           else                   '-'
           end

    asm << sign << emit_integer(op.offset)
  end

  asm = "[#{asm}]"

  unless op.width == op.base.width
    asm = "#{WIDTHS[op.width]} #{asm}"
  end

  return asm
end

.emit_prologue(program) ⇒ String

Emits the program's prologue.

Parameters:

  • program (Program)

    The program.

Returns:

  • (String)

    The formatted prologue.

Since:

  • 0.2.0



142
143
144
# File 'lib/ronin/code/asm/syntax/intel.rb', line 142

def self.emit_prologue(program)
  "BITS #{BITS[program.arch]}"
end

.emit_register(reg) ⇒ String

Emits a register.

Parameters:

Returns:

  • (String)

    The register name.



46
47
48
# File 'lib/ronin/code/asm/syntax/intel.rb', line 46

def self.emit_register(reg)
  reg.name.to_s
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



127
128
129
# File 'lib/ronin/code/asm/syntax/intel.rb', line 127

def self.emit_section(name)
  "section .#{name}"
end