Class: OneGadget::Emulators::Instruction
- Inherits:
-
Object
- Object
- OneGadget::Emulators::Instruction
- Defined in:
- lib/one_gadget/emulators/instruction.rb
Overview
Define instruction name and it’s argument count.
Instance Attribute Summary collapse
-
#argc ⇒ Range
readonly
Count of arguments.
-
#inst ⇒ String
readonly
The instruction name.
Instance Method Summary collapse
-
#fetch_args(cmd) ⇒ Array<String>
Extract arguments from command.
-
#initialize(inst, argc) ⇒ Instruction
constructor
Instantiate a Instruction object.
-
#match?(cmd) ⇒ Boolean
If the command contains this instruction.
Constructor Details
#initialize(inst, argc) ⇒ Instruction
Instantiate a OneGadget::Emulators::Instruction object.
17 18 19 20 21 22 23 24 |
# File 'lib/one_gadget/emulators/instruction.rb', line 17 def initialize(inst, argc) @inst = inst @argc = case argc when -1 then 0..Float::INFINITY when Range then argc when Integer then argc..argc end end |
Instance Attribute Details
#argc ⇒ Range (readonly)
Returns Count of arguments.
10 11 12 |
# File 'lib/one_gadget/emulators/instruction.rb', line 10 def argc @argc end |
#inst ⇒ String (readonly)
Returns The instruction name.
9 10 11 |
# File 'lib/one_gadget/emulators/instruction.rb', line 9 def inst @inst end |
Instance Method Details
#fetch_args(cmd) ⇒ Array<String>
Extract arguments from command.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/one_gadget/emulators/instruction.rb', line 30 def fetch_args(cmd) idx = cmd.index(inst) cmd = cmd[0...cmd.rindex('//')] if cmd.rindex('//') cmd = cmd[0...cmd.rindex('#')] if cmd.rindex('#') args = parse_args(cmd[idx + inst.size..-1]) unless argc.include?(args.size) raise OneGadget::Error::InstructionArgumentError, "Incorrect argument number in #{cmd}, expect: #{argc}" end args.map do |arg| arg.gsub(/XMMWORD|QWORD|DWORD|WORD|BYTE|PTR/, '').strip end end |
#match?(cmd) ⇒ Boolean
If the command contains this instruction.
47 48 49 |
# File 'lib/one_gadget/emulators/instruction.rb', line 47 def match?(cmd) (cmd =~ /#{inst}\s/) != nil end |