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.


11
12
13
14
# File 'lib/one_gadget/emulators/x86.rb', line 11

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

Instance Method Details

#instructionsArray<Instruction>

Supported instruction set.

Returns:


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

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)
  ]
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.


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

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