Class: OneGadget::Gadget::Gadget
- Inherits:
-
Object
- Object
- OneGadget::Gadget::Gadget
- Defined in:
- lib/one_gadget/gadget.rb
Overview
Information of a gadget.
Instance Attribute Summary collapse
-
#base ⇒ Integer
Base address of libc.
-
#constraints ⇒ Array<String>
readonly
The constraints need for this gadget.
-
#effect ⇒ String
readonly
The final result of this gadget.
-
#offset ⇒ Integer
readonly
The gadget’s address offset.
Instance Method Summary collapse
-
#initialize(offset, **options) ⇒ Gadget
constructor
Initialize method of Gadget instance.
-
#inspect ⇒ Object
Show gadget in a pretty way.
-
#score ⇒ Float
The success probability of the constraints.
-
#value ⇒ Integer
Returns
baseplusoffset.
Constructor Details
#initialize(offset, **options) ⇒ Gadget
Initialize method of OneGadget::Gadget::Gadget instance.
27 28 29 30 31 32 |
# File 'lib/one_gadget/gadget.rb', line 27 def initialize(offset, **) @base = 0 @offset = offset @constraints = [:constraints] || [] @effect = [:effect] end |
Instance Attribute Details
#base ⇒ Integer
Returns Base address of libc. Default: 0.
13 14 15 |
# File 'lib/one_gadget/gadget.rb', line 13 def base @base end |
#constraints ⇒ Array<String> (readonly)
Returns The constraints need for this gadget.
17 18 19 |
# File 'lib/one_gadget/gadget.rb', line 17 def constraints @constraints end |
#effect ⇒ String (readonly)
Returns The final result of this gadget.
19 20 21 |
# File 'lib/one_gadget/gadget.rb', line 19 def effect @effect end |
#offset ⇒ Integer (readonly)
Returns The gadget’s address offset.
15 16 17 |
# File 'lib/one_gadget/gadget.rb', line 15 def offset @offset end |
Instance Method Details
#inspect ⇒ Object
Show gadget in a pretty way.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/one_gadget/gadget.rb', line 35 def inspect str = OneGadget::Helper.hex(value) str += effect ? " #{effect}\n" : "\n" unless constraints.empty? str += "#{OneGadget::Helper.colorize('constraints')}:\n " str += merge_constraints.join("\n ") end str.gsub!(/0x[\da-f]+/) { |s| OneGadget::Helper.colorize(s, sev: :integer) } OneGadget::ABI.all.each do |reg| str.gsub!(/([^\w])(#{reg})([^\w])/, "\\1#{OneGadget::Helper.colorize('\2', sev: :reg)}\\3") end "#{str}\n" end |
#score ⇒ Float
Returns The success probability of the constraints.
57 58 59 |
# File 'lib/one_gadget/gadget.rb', line 57 def score @score ||= constraints.reduce(1.0) { |s, c| s * calculate_score(c) } end |
#value ⇒ Integer
Returns base plus offset.
51 52 53 |
# File 'lib/one_gadget/gadget.rb', line 51 def value base + offset end |