Class: Ragweed::Wrap32::ThreadContext
- Defined in:
- lib/ragweed/wrap32/thread_context.rb
Class Method Summary collapse
Instance Method Summary collapse
- #dump(&block) ⇒ Object
- #get(h) ⇒ Object
-
#initialize(str = nil) ⇒ ThreadContext
constructor
A new instance of ThreadContext.
- #inspect ⇒ Object
- #refresh(str) ⇒ Object
- #set(h) ⇒ Object
- #single_step(v = true) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(str = nil) ⇒ ThreadContext
Returns a new instance of ThreadContext.
67 68 69 |
# File 'lib/ragweed/wrap32/thread_context.rb', line 67 def initialize(str=nil) refresh(str) if str end |
Class Method Details
.get(h) ⇒ Object
83 84 85 |
# File 'lib/ragweed/wrap32/thread_context.rb', line 83 def self.get(h) self.new(Wrap32::get_thread_context_raw(h)) end |
Instance Method Details
#dump(&block) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/ragweed/wrap32/thread_context.rb', line 105 def dump(&block) maybe_hex = lambda {|a| begin; "\n" + (" " * 9) + block.call(a, 16).hexdump(true)[10..-2]; rescue; ""; end } maybe_dis = lambda {|a| begin; "\n" + block.call(a, 16).distorm.map {|i| " " + i.mnem}.join("\n"); rescue; ""; end } string =<<EOM ----------------------------------------------------------------------- CONTEXT: EIP: #{self.eip.to_s(16).rjust(8, "0")} #{maybe_dis.call(self.eip)} EAX: #{self.eax.to_s(16).rjust(8, "0")} #{maybe_hex.call(self.eax)} EBX: #{self.ebx.to_s(16).rjust(8, "0")} #{maybe_hex.call(self.ebx)} ECX: #{self.ecx.to_s(16).rjust(8, "0")} #{maybe_hex.call(self.ecx)} EDX: #{self.edx.to_s(16).rjust(8, "0")} #{maybe_hex.call(self.edx)} EDI: #{self.edi.to_s(16).rjust(8, "0")} #{maybe_hex.call(self.edi)} ESI: #{self.esi.to_s(16).rjust(8, "0")} #{maybe_hex.call(self.esi)} EBP: #{self.ebp.to_s(16).rjust(8, "0")} #{maybe_hex.call(self.ebp)} ESP: #{self.esp.to_s(16).rjust(8, "0")} #{maybe_hex.call(self.esp)} EFL: #{self.eflags.to_s(2).rjust(32, "0")} #{Wrap32::EFlags.flag_dump(self.eflags)} EOM end |
#get(h) ⇒ Object
87 88 89 |
# File 'lib/ragweed/wrap32/thread_context.rb', line 87 def get(h) refresh(Wrap32::get_thread_context_raw(h)) end |
#inspect ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/ragweed/wrap32/thread_context.rb', line 95 def inspect body = lambda do FIELDS.map do |f| val = send(f[0]) "#{f[0]}=#{val.to_s(16) rescue val.to_s}" end.join(", ") end "#<ThreadContext #{body.call}>" end |
#refresh(str) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/ragweed/wrap32/thread_context.rb', line 71 def refresh(str) if str str.unpack(FIELDS.map {|x| x[1]}.join("")).each_with_index do |val, i| instance_variable_set "@#{ FIELDS[i][0] }".intern, val end end end |
#set(h) ⇒ Object
91 92 93 |
# File 'lib/ragweed/wrap32/thread_context.rb', line 91 def set(h) Wrap32::set_thread_context_raw(h, self.to_s) end |
#single_step(v = true) ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/ragweed/wrap32/thread_context.rb', line 126 def single_step(v=true) if v @eflags |= Wrap32::EFlags::TRAP else @eflags &= ~(Wrap32::EFlags::TRAP) end end |
#to_s ⇒ Object
79 80 81 |
# File 'lib/ragweed/wrap32/thread_context.rb', line 79 def to_s FIELDS.map {|f| send(f[0])}.pack(FIELDS.map {|x| x[1]}.join("")) end |