Class: OneGadget::Emulators::X86

Inherits:
Processor show all
Defined in:
lib/one_gadget/emulators/x86.rb

Overview

Super class for amd64 and i386 processor.

Direct Known Subclasses

Amd64, I386

Instance Attribute Summary

Attributes inherited from Processor

#pc, #registers, #sp, #stack

Instance Method Summary collapse

Methods inherited from Processor

#argument, bits, #constraints, #parse, #process

Constructor Details

#initialize(registers, sp, pc) ⇒ X86

Constructor for a x86 processor.



13
14
15
16
# File 'lib/one_gadget/emulators/x86.rb', line 13

def initialize(registers, sp, pc)
  super(registers, sp)
  @pc = pc
end

Instance Method Details

#instructionsArray<Instruction>

Supported instruction set.

Returns:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/one_gadget/emulators/x86.rb', line 35

def instructions
  [
    Instruction.new('add', 2),
    Instruction.new('call', 1),
    Instruction.new('jmp', 1),
    Instruction.new('lea', 2),
    Instruction.new('mov', 2),
    Instruction.new('nop', -1),
    Instruction.new('push', 1),
    Instruction.new('sub', 2),
    Instruction.new('xor', 2),
    Instruction.new('movq', 2),
    Instruction.new('movaps', 2),
    Instruction.new('movhps', 2),
    Instruction.new('punpcklqdq', 2)
  ]
end

#process!(cmd) ⇒ Boolean

Process one command. Will raise exceptions when encounter unhandled instruction.

Parameters:

  • cmd (String)

    One line from result of objdump.

Returns:

  • (Boolean)

    If successfully processed.



24
25
26
27
28
29
30
31
# File 'lib/one_gadget/emulators/x86.rb', line 24

def process!(cmd)
  inst, args = parse(cmd)
  # return registers[pc] = args[0] if inst.inst == 'call'
  return true if inst.inst == 'jmp' # believe the fetcher has handled jmp.

  sym = "inst_#{inst.inst}".to_sym
  __send__(sym, *args) != :fail
end