Class: Ragweed::Detour::Dbreak

Inherits:
Detour show all
Defined in:
lib/ragweed/detour.rb

Overview

A breakpoint implemented as a Detour. TODO not tested.

Instance Attribute Summary collapse

Attributes inherited from Detour

#dpoint, #snarfed, #stack

Instance Method Summary collapse

Methods inherited from Detour

#call, #release

Constructor Details

#initialize(*args) ⇒ Dbreak

accepts: :ev1: reuse events from somewhere else :ev2:



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/ragweed/detour.rb', line 168

def initialize(*args)
  super 
  @ev1 = @opts[:ev1] || WinEvent.new
  @ev2 = @opts[:ev2] || WinEvent.new

  # create the state block that the eventpair shim wants:
  mem = @a.alloc(100)
  @data = mem

  # ghetto vtbl
  swch = ["OpenProcess",                   
          "DuplicateHandle", 
          "ResetEvent", 
          "SetEvent", 
          "WaitForSingleObject",
          "GetCurrentThreadId"].
    map {|x| @p.get_proc("kernel32!#{x}").to_i}.
    pack("LLLLLL")

  # ghetto instance vars
  state = [@p.w.get_current_process_id, @ev1.handle, @ev2.handle].
    pack("LLL")
  @data.write(swch + state)
end

Instance Attribute Details

#ev1Object (readonly)

Returns the value of attribute ev1.



163
164
165
# File 'lib/ragweed/detour.rb', line 163

def ev1
  @ev1
end

#ev2Object (readonly)

Returns the value of attribute ev2.



163
164
165
# File 'lib/ragweed/detour.rb', line 163

def ev2
  @ev2
end

Instance Method Details

#inner_blockObject



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/ragweed/detour.rb', line 193

def inner_block      
  i = Ragweed::Rasm::Subprogram.new      
  i.<< Push(eax)
  i.<< Xor(eax, eax)
  i.<< Or(eax, @data)
  i.<< Push(eax) 
  i.<< Call(1)            # cheesy in the extreme: fake a call
                          # so I don't have to change my event shim
  i.<< Nop.new
  i.<< Nop.new
  i.<< Nop.new
  i.<< Nop.new
  i.<< Nop.new
  s = event_pair_stub
  s[-1] = Add(esp, 4)
  i.concat(s)
  i.<< Pop(eax)
  return i
end

#on(&block) ⇒ Object

in theory, loop on this breakpoint



214
215
216
217
218
219
220
221
# File 'lib/ragweed/detour.rb', line 214

def on(&block)
  puts "#{ @p.pid }: #{ @ev1.handle }" # in case we need to release
  loop do
    @ev1.wait
    yield 
    @ev2.signal
  end
end