Class: OneGadget::Emulators::Lambda
- Inherits:
-
Object
- Object
- OneGadget::Emulators::Lambda
- Defined in:
- lib/one_gadget/emulators/lambda.rb
Overview
Instance Attribute Summary collapse
-
#deref_count ⇒ Integer
The times of dereference.
-
#immi ⇒ Integer
The immidiate value currently added.
-
#obj ⇒ String, Lambda
The object currently related to.
Class Method Summary collapse
-
.parse(argument, predefined: {}) ⇒ OneGadget::Emulators::Lambda, Integer
Target: parse string like
[rsp+0x50]
into a Lambda object.
Instance Method Summary collapse
-
#+(other) ⇒ Lambda
Implement addition with
Numeric
. -
#-(other) ⇒ Lambda
Implement subtract with
Numeric
. -
#deref ⇒ Lambda
A new Lambda object with dereference count increase 1.
-
#deref! ⇒ void
Increase dereference count by 1.
-
#evaluate(context) ⇒ Integer
Evaluates the value of lambda.
-
#initialize(obj) ⇒ Lambda
constructor
Instantiate a Lambda object.
-
#ref! ⇒ self
Decrease dereference count by 1.
-
#to_s ⇒ String
Expand the lambda presentation.
Constructor Details
#initialize(obj) ⇒ Lambda
Instantiate a OneGadget::Emulators::Lambda object.
20 21 22 23 24 |
# File 'lib/one_gadget/emulators/lambda.rb', line 20 def initialize(obj) @immi = 0 @obj = obj @deref_count = 0 end |
Instance Attribute Details
#deref_count ⇒ Integer
Returns The times of dereference.
16 17 18 |
# File 'lib/one_gadget/emulators/lambda.rb', line 16 def deref_count @deref_count end |
#immi ⇒ Integer
Returns The immidiate value currently added.
15 16 17 |
# File 'lib/one_gadget/emulators/lambda.rb', line 15 def immi @immi end |
#obj ⇒ String, Lambda
Returns The object currently related to.
14 15 16 |
# File 'lib/one_gadget/emulators/lambda.rb', line 14 def obj @obj end |
Class Method Details
.parse(argument, predefined: {}) ⇒ OneGadget::Emulators::Lambda, Integer
Target: parse string like [rsp+0x50]
into a OneGadget::Emulators::Lambda object.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/one_gadget/emulators/lambda.rb', line 118 def parse(argument, predefined: {}) arg = argument.dup return 0 if arg.empty? || arg == '!' return Integer(arg) if OneGadget::Helper.integer?(arg) # nested [] if arg[0] == '[' ridx = arg.rindex(']') immi = parse(arg[(ridx + 1)..-1]) lm = parse(arg[1...ridx], predefined: predefined).deref lm += immi unless immi.zero? return lm end base, disp = mem_obj(arg) obj = predefined[base] || Lambda.new(base) obj += disp unless disp.zero? obj end |
Instance Method Details
#+(other) ⇒ Lambda
Implement addition with Numeric
.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/one_gadget/emulators/lambda.rb', line 29 def +(other) raise Error::InstructionArgumentError, "Expect other(#{other}) to be numeric." unless other.is_a?(Numeric) if deref_count.positive? ret = Lambda.new(self) else ret = Lambda.new(obj) ret.immi = immi end ret.immi += other ret end |
#-(other) ⇒ Lambda
Implement subtract with Numeric
.
45 46 47 |
# File 'lib/one_gadget/emulators/lambda.rb', line 45 def -(other) self.+(-other) end |
#deref ⇒ Lambda
A new OneGadget::Emulators::Lambda object with dereference count increase 1.
67 68 69 70 71 72 |
# File 'lib/one_gadget/emulators/lambda.rb', line 67 def deref ret = Lambda.new(obj) ret.immi = immi ret.deref_count = deref_count + 1 ret end |
#deref! ⇒ void
This method returns an undefined value.
Increase dereference count by 1.
51 52 53 |
# File 'lib/one_gadget/emulators/lambda.rb', line 51 def deref! @deref_count += 1 end |
#evaluate(context) ⇒ Integer
Evaluates the value of lambda. Only supports rsp0x30+ form.
94 95 96 97 98 99 100 |
# File 'lib/one_gadget/emulators/lambda.rb', line 94 def evaluate(context) if deref_count.positive? || (obj && !context.key?(obj)) raise Error::InstructionArgumentError, "Can't eval #{self}" end context[obj] + immi end |
#ref! ⇒ self
Decrease dereference count by 1.
58 59 60 61 62 63 |
# File 'lib/one_gadget/emulators/lambda.rb', line 58 def ref! raise Error::InstructionArgumentError, 'Cannot reference anymore!' if @deref_count <= 0 @deref_count -= 1 self end |