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.



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

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.



164
165
166
# File 'lib/one_gadget/emulators/aarch64.rb', line 164

def bits
  64
end

Instance Method Details

#argument(idx) ⇒ Lambda, Integer

Return the argument value of calling a function.

Parameters:

  • idx (Integer)

Returns:



43
44
45
# File 'lib/one_gadget/emulators/aarch64.rb', line 43

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

#instructionsArray<Instruction>

Supported instruction set.

Returns:



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

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:



20
21
22
23
24
# File 'lib/one_gadget/emulators/aarch64.rb', line 20

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