ragweed 0.2.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/History.txt +32 -0
  2. data/README.rdoc +60 -0
  3. data/README.txt +9 -0
  4. data/Rakefile +86 -0
  5. data/VERSION +1 -0
  6. data/examples/hittracertux.rb +45 -0
  7. data/examples/hittracerx.rb +63 -0
  8. data/examples/hook_notepad.rb +9 -0
  9. data/examples/snicker.rb +183 -0
  10. data/examples/tux-example.rb +24 -0
  11. data/lib/ragweed/arena.rb +55 -0
  12. data/lib/ragweed/blocks.rb +128 -0
  13. data/lib/ragweed/debugger32.rb +400 -0
  14. data/lib/ragweed/debuggerosx.rb +456 -0
  15. data/lib/ragweed/debuggertux.rb +502 -0
  16. data/lib/ragweed/detour.rb +223 -0
  17. data/lib/ragweed/ptr.rb +48 -0
  18. data/lib/ragweed/rasm/bblock.rb +73 -0
  19. data/lib/ragweed/rasm/isa.rb +1115 -0
  20. data/lib/ragweed/rasm.rb +59 -0
  21. data/lib/ragweed/sbuf.rb +197 -0
  22. data/lib/ragweed/trampoline.rb +103 -0
  23. data/lib/ragweed/utils.rb +182 -0
  24. data/lib/ragweed/wrap32/debugging.rb +401 -0
  25. data/lib/ragweed/wrap32/device.rb +49 -0
  26. data/lib/ragweed/wrap32/event.rb +50 -0
  27. data/lib/ragweed/wrap32/hooks.rb +39 -0
  28. data/lib/ragweed/wrap32/overlapped.rb +46 -0
  29. data/lib/ragweed/wrap32/process.rb +613 -0
  30. data/lib/ragweed/wrap32/process_token.rb +75 -0
  31. data/lib/ragweed/wrap32/thread_context.rb +142 -0
  32. data/lib/ragweed/wrap32/winx.rb +16 -0
  33. data/lib/ragweed/wrap32/wrap32.rb +583 -0
  34. data/lib/ragweed/wrap32.rb +59 -0
  35. data/lib/ragweed/wraposx/constants.rb +114 -0
  36. data/lib/ragweed/wraposx/kernelerrorx.rb +147 -0
  37. data/lib/ragweed/wraposx/region_info.rb +275 -0
  38. data/lib/ragweed/wraposx/structs.rb +102 -0
  39. data/lib/ragweed/wraposx/thread_context.rb +902 -0
  40. data/lib/ragweed/wraposx/thread_info.rb +160 -0
  41. data/lib/ragweed/wraposx/thread_info.rb.old +121 -0
  42. data/lib/ragweed/wraposx/wraposx.rb +356 -0
  43. data/lib/ragweed/wraposx.rb +60 -0
  44. data/lib/ragweed/wraptux/constants.rb +101 -0
  45. data/lib/ragweed/wraptux/process.rb +35 -0
  46. data/lib/ragweed/wraptux/threads.rb +7 -0
  47. data/lib/ragweed/wraptux/wraptux.rb +72 -0
  48. data/lib/ragweed/wraptux.rb +57 -0
  49. data/lib/ragweed.rb +112 -0
  50. data/ragweed.gemspec +102 -0
  51. data/spec/ragweed_spec.rb +7 -0
  52. data/spec/spec_helper.rb +16 -0
  53. data/test/test_ragweed.rb +0 -0
  54. metadata +121 -0
@@ -0,0 +1,48 @@
1
+ # TODO: make read/write work for other oses
2
+
3
+ class Ragweed::Ptr
4
+ # A dubious achievement. Wrap Integers in a pointer class, which,
5
+ # when you call to_s, returns the marshalled type, and which exports
6
+ # read/write methods.
7
+ attr_accessor :p
8
+ attr_reader :val
9
+
10
+ # ptr-to-zero?
11
+ def null?
12
+ @val == 0
13
+ end
14
+
15
+ # initialize with a number or another pointer (implements copy-ctor)
16
+ def initialize(i)
17
+ if i.kind_of? self.class
18
+ @val = i.val
19
+ @p = i.p
20
+ elsif not i
21
+ @val = 0
22
+ else
23
+ @val = i
24
+ end
25
+ end
26
+
27
+ # return the raw pointer bits
28
+ def to_s; @val.to_l32; end
29
+
30
+ # return the underlying number
31
+ def to_i; @val; end
32
+
33
+ # only works if you attach a process
34
+ def write(arg); p.write(self, arg); end
35
+ def read(sz); p.read(self, sz); end
36
+
37
+ # everything else: work like an integer --- also, where these
38
+ # calls return numbers, turn them back into pointers, so pointer
39
+ # math doesn't shed the class wrapper
40
+ def method_missing(meth, *args)
41
+ ret = @val.send meth, *args
42
+ if ret.kind_of? Numeric
43
+ ret = Ragweed::Ptr.new(ret)
44
+ ret.p = self.p
45
+ end
46
+ ret
47
+ end
48
+ end
@@ -0,0 +1,73 @@
1
+ module Ragweed; end
2
+ module Ragweed::Rasm
3
+ # Ruby inline assembler.
4
+ class Bblock
5
+ # Don't call this directly; use Bblock#make
6
+ def initialize
7
+ @insns = Ragweed::Rasm::Subprogram.new
8
+ end
9
+
10
+ # Wrap the methods of Rasm::Subprogram we care about:
11
+
12
+ # Assemble the instructions, which also calculates appropriate
13
+ # jump labels.
14
+ def assemble; @insns.assemble; end
15
+
16
+ # Disassemble the block (after it's been assembled) into
17
+ # Frasm objects.
18
+ def disassemble; @insns.disassemble; end
19
+
20
+ # Generate a human-readable assembly listing.
21
+ def listing; @insns.dump_disassembly; end
22
+
23
+ # Append more instructions to a previously created block;
24
+ # see Bblock#make
25
+ def append(&block)
26
+ instance_eval(&block)
27
+ end
28
+
29
+ # Takes a block argument, containing (mostly) assembly
30
+ # instructions, as interpreted by Rasm. For example:
31
+ #
32
+ # Bblock.make {
33
+ # push ebp
34
+ # mov ebp, esp
35
+ # push ebx
36
+ # xor ebx, ebx
37
+ # addl esp, 4
38
+ # pop ebp
39
+ # ret
40
+ # }
41
+ #
42
+ # Each of those instructions is in fact the name of a class
43
+ # in Rasm, lowercased; Bblock has a method_missing that catches
44
+ # and instantiates them.
45
+ #
46
+ # Your block can contain arbitrary Ruby, but remember that it
47
+ # runs in the scope of an anonymous class and so cannot directly
48
+ # reference instance variables.
49
+ def self.make(&block)
50
+ c = Bblock.new
51
+ c.instance_eval(&block)
52
+ c
53
+ end
54
+
55
+ # method to fix collision with Kernel#sub properly
56
+ def sub(*args)
57
+ Ragweed::Rasm::Sub.new(*args)
58
+ end
59
+
60
+ def method_missing(meth, *args)
61
+ k = Ragweed::Rasm.const_get(meth.to_s.capitalize)
62
+
63
+ # If it's a class, it's an assembly opcode; otherwise,
64
+ # it's a register or operand.
65
+ if k.class == Class
66
+ @insns << (k = k.new(*args))
67
+ else
68
+ k
69
+ end
70
+ k
71
+ end
72
+ end
73
+ end