Class: OneGadget::Emulators::AArch64

Inherits:
Processor
  • Object
show all
Defined in:
lib/one_gadget/emulators/aarch64.rb

Overview

Emulator of aarch64.

Instance Attribute Summary

Attributes inherited from Processor

#pc, #registers, #sp, #stack

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Processor

#constraints, #parse, #process

Constructor Details

#initializeAArch64

Instantiate a OneGadget::Emulators::AArch64 object.


10
11
12
13
14
15
# File 'lib/one_gadget/emulators/aarch64.rb', line 10

def initialize
  super(OneGadget::ABI.aarch64, 'sp')
  # Constant registers
  %w[xzr wzr].each { |r| @registers[r] = 0 }
  @pc = 'pc'
end

Class Method Details

.bitsObject

AArch64 is 64-bit.


170
171
172
# File 'lib/one_gadget/emulators/aarch64.rb', line 170

def bits
  64
end

Instance Method Details

#argument(idx) ⇒ Lambda, Integer

Return the argument value of calling a function.

Parameters:

  • idx (Integer)

Returns:


41
42
43
# File 'lib/one_gadget/emulators/aarch64.rb', line 41

def argument(idx)
  registers["x#{idx}"]
end

#instructionsArray<Instruction>

Supported instruction set.

Returns:


26
27
28
29
30
31
32
33
34
35
36
# File 'lib/one_gadget/emulators/aarch64.rb', line 26

def instructions
  [
    Instruction.new('add', 3..4),
    Instruction.new('adrp', 2),
    Instruction.new('bl', 1),
    Instruction.new('ldr', 2..3),
    Instruction.new('mov', 2),
    Instruction.new('stp', 3),
    Instruction.new('str', 2..3)
  ]
end

#process!(cmd) ⇒ Object

See Also:


18
19
20
21
22
# File 'lib/one_gadget/emulators/aarch64.rb', line 18

def process!(cmd)
  inst, args = parse(cmd.gsub(/#-?(0x)?[0-9a-f]+/) { |v| v[1..-1] })
  sym = "inst_#{inst.inst}".to_sym
  __send__(sym, *args) != :fail
end