module Ragweed::Wrap32 module EFlags CARRY = (1<< 0) X0 = (1<< 1) PARITY = (1<< 2) X1 = (1<< 3) ADJUST = (1<< 4) X2 = (1<< 5) ZERO = (1<< 6) SIGN = (1<< 7) TRAP = (1<< 8) INTERRUPT = (1<< 9) DIRECTION = (1<< 10) OVERFLOW = (1<< 11) IOPL1 = (1<< 12) IOPL2 = (1<< 13) NESTEDTASK = (1<< 14) X3 = (1<< 15) RESUME = (1<< 16) V86MODE = (1<< 17) ALIGNCHECK = (1<< 18) VINT = (1<< 19) VINTPENDING = (1<< 20) CPUID = (1<< 21) end module ContextFlags I386 = 0x10000 CONTROL = 1 INTEGER = 2 SEGMENTS = 4 FLOATING_POINT = 8 DEBUG_REGISTERS = 0x10 FULL = (I386|CONTROL|INTEGER|SEGMENTS) DEBUG = (FULL|DEBUG_REGISTERS) end end class Ragweed::Wrap32::ThreadContext (FIELDS = [ [:context_flags, "L"], [:dr0, "L"], [:dr1, "L"], [:dr2, "L"], [:dr3, "L"], [:dr6, "L"], [:dr7, "L"], [:floating_save, "a112"], [:seg_gs, "L"], [:seg_gs, "L"], [:seg_es, "L"], [:seg_ds, "L"], [:edi, "L"], [:esi, "L"], [:ebx, "L"], [:edx, "L"], [:ecx, "L"], [:eax, "L"], [:ebp, "L"], [:eip, "L"], [:seg_cs, "L"], [:eflags, "L"], [:esp, "L"], [:seg_ss, "L"], [:spill, "a1024"]]).each {|x| attr_accessor x[0]} def initialize(str=nil) refresh(str) if str end 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 def to_s FIELDS.map {|f| send(f[0])}.pack(FIELDS.map {|x| x[1]}.join("")) end def self.get(h) self.new(Ragweed::Wrap32::get_thread_context_raw(h)) end def get(h) refresh(Ragweed::Wrap32::get_thread_context_raw(h)) end def set(h) Ragweed::Wrap32::set_thread_context_raw(h, self.to_s) end def inspect body = lambda do FIELDS.map do |f| val = send(f[0]) "#{f[0]}=#{val.to_s(16) rescue val.to_s.hexify}" end.join(", ") end "#" end 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 =<