ragweed 0.1.7.3 → 0.2.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,76 +1,72 @@
1
- require 'dl'
1
+ require 'ffi'
2
2
 
3
- module Ragweed; end
4
3
  module Ragweed::Wraptux
5
- LIBS = Hash.new do |h, str|
6
- if not str =~ /^[\.\/].*/
7
- str = "/lib/" + str
8
- end
9
- if not str =~ /.*\.so.6$/
10
- str = str + ".so.6"
11
- end
12
- h[str] = DL.dlopen(str)
4
+ module Libc
5
+ extend FFI::Library
6
+ ffi_lib FFI::Library::LIBC
7
+ attach_function 'ptrace', [ :ulong, :pid_t, :ulong, :ulong ], :long
8
+ attach_function 'wait', [ :pointer ], :int
9
+ attach_function 'waitpid', [ :int, :pointer, :int ], :int
10
+ attach_function 'kill', [ :int, :int ], :int
11
+ attach_function 'malloc', [ :size_t ], :pointer
12
+ attach_function 'free', [ :pointer ], :void
13
13
  end
14
-
15
- CALLS = Hash.new do |h, str|
16
- lib = proc = args = ret = nil
17
- lib, rest = str.split "!"
18
- proc, rest = rest.split ":"
19
- args, ret = rest.split("=") if rest
20
- ret ||= "0"
21
- raise "need proc" if not proc
22
- h[str] = LIBS[lib][proc, ret + args]
14
+
15
+ class PTRegs < FFI::Struct
16
+ include Ragweed::FFIStructInclude
17
+ layout :ebx, :ulong,
18
+ :ecx, :ulong,
19
+ :edx, :ulong,
20
+ :esi, :ulong,
21
+ :edi, :ulong,
22
+ :ebp, :ulong,
23
+ :eax, :ulong,
24
+ :xds, :ulong,
25
+ :xes, :ulong,
26
+ :xfs, :ulong,
27
+ :xgs, :ulong,
28
+ :orig_eax, :ulong,
29
+ :eip, :ulong,
30
+ :xcs, :ulong,
31
+ :eflags, :ulong,
32
+ :esp, :ulong,
33
+ :xss, :ulong
23
34
  end
24
35
 
25
- NULL = DL::PtrData.new(0)
26
-
27
- SIZEOFINT = DL.sizeof('I')
28
- SIZEOFLONG = DL.sizeof('L')
29
-
30
36
  class << self
31
- #long ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data);
32
- def ptrace(request, pid, addr, data)
33
- DL.last_error = 0
34
- r = CALLS["libc!ptrace:IIII=I"].call(request, pid, addr, data).first
35
- raise SystemCallError.new("ptrace", DL.last_error) if r == -1 and DL.last_error != 0
36
-
37
- case request
38
- when Ptrace::PEEK_TEXT, Ptrace::PEEK_DATA
39
- return r
40
- end
41
- end
42
-
43
- def malloc(sz)
44
- r = CALLS["libc!malloc:L=L"].call(sz)
45
- return r
46
- end
47
-
48
- #wait(int *status);
37
+ # pid_t wait(int *status);
49
38
  def wait
50
- status = ("\x00"*SIZEOFINT).to_ptr.to_i
51
- r = CALLS["libc!wait:I=I"].call(status).first
52
- raise SystemCallError.new("wait", DL.last_error) if r == -1
53
- self.continue # continue with the ptrace at this point
54
- return status.to_s(SIZEOFINT).unpack('i_').first
39
+ stat = FFI::MemoryPointer.new(:int, 1)
40
+ FFI.errno = 0
41
+ pid = Libc.wait stat
42
+ raise SystemCallError.new "wait", FFI.errno if pid == -1
43
+ [pid, stat.read_pointer.get_int32]
55
44
  end
56
-
57
- #waitpid(pid_t pid, int *stat_loc, int options);
58
- def waitpid(pid, opt=1)
59
- pstatus = ("\x00"*SIZEOFINT).to_ptr
60
- r = CALLS["libc!waitpid:IPI=I"].call(pid, pstatus, opt).first
61
- raise SystemCallError.new("waitpid", DL.last_error) if r == -1
62
- return [r, pstatus.to_s(SIZEOFINT).unpack('i_').first]
45
+
46
+ # pid_t waitpid(pid_t pid, int *status, int options);
47
+ def waitpid pid, opts = 0
48
+ p = FFI::MemoryPointer.new(:int, 1)
49
+ FFI.errno = 0
50
+ r = Libc.waitpid(pid,p,opts)
51
+ raise SystemCallErro.new "waitpid", FFI.errno if r == -1
52
+ status = p.get_int32(0)
53
+ [r, status]
63
54
  end
64
55
 
65
- #kill(pid_t pid, int sig);
66
- def kill(pid, sig)
67
- DL.last_error = 0
68
- r = CALLS["libc!kill:II=I"].call(pid,sig).first
69
- raise SystemCallError.new("kill",DL.last_error) if r != 0
56
+ # int kill(pid_t pid, int sig);
57
+ def kill pid, sig
58
+ FFI.errno = 0
59
+ r = Libc.kill pid, sig
60
+ raise SystemCallError.new "waitpid", FFI.errno if r == -1
61
+ r
70
62
  end
71
-
72
- def getpid
73
- CALLS["libc!getpid:=I"].call.first
63
+
64
+ #long ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data);
65
+ def ptrace req, pid, addr, data
66
+ FFI.errno = 0
67
+ r = Libc.ptrace req, pid, addr, data
68
+ #raise SystemCallError.new "ptrace", FFI.errno if r == -1 and !FFI.errno.zero?
69
+ r
74
70
  end
75
71
  end
76
72
  end
@@ -1,11 +1,11 @@
1
1
  # Dir[File.expand_path("#{File.dirname(__FILE__)}/wraptux/*.rb")].each do |file|
2
2
  # require file
3
3
  # end
4
+
4
5
  module Ragweed; end
5
6
  module Ragweed::Wraptux
6
-
7
7
  # :stopdoc:
8
- VERSION = '0.1.7.3'
8
+ VERSION = File.read(File.join(File.dirname(__FILE__),"..","..","VERSION")).strip
9
9
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
10
10
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
11
11
  # :startdoc:
@@ -47,8 +47,7 @@ module Ragweed::Wraptux
47
47
  dir ||= ::File.basename(fname, '.*')
48
48
  search_me = ::File.expand_path(
49
49
  ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
50
-
51
- Dir.glob(search_me).sort.each {|rb| require rb}
50
+ Dir.glob(search_me).sort.each {|rb| require rb }
52
51
  # require File.dirname(File.basename(__FILE__)) + "/#{x}"
53
52
 
54
53
  end
data/lib/ragweed.rb CHANGED
@@ -1,8 +1,9 @@
1
+ require 'ffi'
1
2
 
2
3
  module Ragweed
3
4
 
4
5
  # :stopdoc:
5
- VERSION = '0.1.7.3'
6
+ VERSION = File.read(File.join(File.dirname(__FILE__),"..","VERSION")).strip
6
7
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
7
8
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
8
9
  # :startdoc:
@@ -38,7 +39,6 @@ module Ragweed
38
39
  dir ||= ::File.basename(fname, '.*')
39
40
  search_me = ::File.expand_path(
40
41
  ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
41
-
42
42
  # Don't want to load wrapper or debugger here.
43
43
  Dir.glob(search_me).sort.reject{|rb| rb =~ /(wrap|debugger|rasm[^\.])/}.each {|rb| require rb}
44
44
  # require File.dirname(File.basename(__FILE__)) + "/#{x}"d
@@ -48,15 +48,18 @@ module Ragweed
48
48
  dir ||= ::File.basename(fname, '.*')
49
49
  pkgs = ""
50
50
  dbg = ""
51
+
51
52
  case
52
- when RUBY_PLATFORM =~ /win(dows|32)/i
53
+ when ::FFI::Platform.windows?
53
54
  pkgs = '32'
54
- when RUBY_PLATFORM =~ /darwin/i
55
+ when ::FFI::Platform.mac?
55
56
  pkgs = 'osx'
56
- when RUBY_PLATFORM =~ /linux/i
57
+ # coming soon
58
+ # when ::FFI::Platform.bsd?
59
+ # pkgs = "bsd"
60
+ when ::FFI::Platform.unix? && ! ::FFI::Platform.bsd?
61
+ # FFI doesn't specifically detect linux so... we punt
57
62
  pkgs = 'tux'
58
- # when RUBY_PLATFORM =~ /java/i
59
- # TODO - Java port using jni?
60
63
  else
61
64
  warn "Platform not supported no wrapper libraries loaded."
62
65
  end
@@ -68,6 +71,32 @@ module Ragweed
68
71
  end
69
72
  end # module Ragweed
70
73
 
74
+ ## FFI Struct Accessor Methods
75
+ module Ragweed::FFIStructInclude
76
+ if RUBY_VERSION < "1.9"
77
+ def methods regular=true
78
+ super + self.offsets.map{|x| x.first.to_s}
79
+ end
80
+ else
81
+ def methods regular=true
82
+ super + self.offsets.map{|x| x.first}
83
+ end
84
+ end
85
+
86
+ def method_missing meth, *args
87
+ super unless self.respond_to? meth
88
+ if meth.to_s =~ /=$/
89
+ self.__send__(:[]=, meth.to_s.gsub(/=$/,'').intern, *args)
90
+ else
91
+ self.__send__(:[], meth, *args)
92
+ end
93
+ end
94
+
95
+ def respond_to? meth, include_priv=false
96
+ mth = meth.to_s.gsub(/=$/,'')
97
+ self.offsets.map{|x| x.first.to_s}.include? mth || super
98
+ end
99
+ end
71
100
 
72
101
  # pkgs = %w[arena sbuf ptr process event rasm blocks detour trampoline device debugger hooks]
73
102
  # pkgs << 'wrap32' if RUBY_PLATFORM =~ /win(dows|32)/i
@@ -80,5 +109,4 @@ end # module Ragweed
80
109
 
81
110
  Ragweed.require_os_libs_relative_to(__FILE__)
82
111
  Ragweed.require_all_libs_relative_to(__FILE__)
83
-
84
112
  # EOF
data/ragweed.gemspec CHANGED
@@ -1,34 +1,104 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
1
4
  # -*- encoding: utf-8 -*-
2
5
 
3
6
  Gem::Specification.new do |s|
4
7
  s.name = %q{ragweed}
5
- s.version = "0.1.7.3"
8
+ s.version = "0.2.0.pre1"
6
9
 
7
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["tduehr, tqbf, struct"]
9
- s.date = %q{2009-09-21}
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["tduehr", "struct", "tqbf"]
12
+ s.date = %q{2010-11-19}
10
13
  s.description = %q{General debugging tool written in Ruby for OSX/Win32/Linux}
11
14
  s.email = %q{td@matasano.com}
12
- s.extra_rdoc_files = ["History.txt", "README.rdoc", "README.txt"]
13
- s.files = ["History.txt", "README.rdoc", "README.txt", "Rakefile", "examples/hittracertux.rb", "examples/hittracerx.rb", "examples/hook_notepad.rb", "examples/snicker.rb", "examples/tux-example.rb", "lib/ragweed.rb", "lib/ragweed/arena.rb", "lib/ragweed/blocks.rb", "lib/ragweed/debugger32.rb", "lib/ragweed/debuggerosx.rb", "lib/ragweed/debuggertux.rb", "lib/ragweed/detour.rb", "lib/ragweed/ptr.rb", "lib/ragweed/rasm.rb", "lib/ragweed/rasm/bblock.rb", "lib/ragweed/rasm/isa.rb", "lib/ragweed/sbuf.rb", "lib/ragweed/trampoline.rb", "lib/ragweed/utils.rb", "lib/ragweed/wrap32.rb", "lib/ragweed/wrap32/debugging.rb", "lib/ragweed/wrap32/device.rb", "lib/ragweed/wrap32/event.rb", "lib/ragweed/wrap32/hooks.rb", "lib/ragweed/wrap32/overlapped.rb", "lib/ragweed/wrap32/process.rb", "lib/ragweed/wrap32/process_token.rb", "lib/ragweed/wrap32/thread_context.rb", "lib/ragweed/wrap32/winx.rb", "lib/ragweed/wrap32/wrap32.rb", "lib/ragweed/wraposx.rb", "lib/ragweed/wraposx/constants.rb", "lib/ragweed/wraposx/kernelerrorx.rb", "lib/ragweed/wraposx/region_info.rb", "lib/ragweed/wraposx/thread_context.rb", "lib/ragweed/wraposx/thread_info.rb", "lib/ragweed/wraposx/wraposx.rb", "lib/ragweed/wraptux.rb", "lib/ragweed/wraptux/constants.rb", "lib/ragweed/wraptux/threads.rb", "lib/ragweed/wraptux/wraptux.rb", "ragweed.gemspec", "spec/ragweed_spec.rb", "spec/spec_helper.rb", "test/test_ragweed.rb"]
14
- s.homepage = %q{http://github.com/tduehr/ragweed/tree/master}
15
- s.rdoc_options = ["--inline-source", "--line-numbers", "--main", "README.txt"]
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc",
17
+ "README.txt"
18
+ ]
19
+ s.files = [
20
+ "History.txt",
21
+ "README.rdoc",
22
+ "README.txt",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "examples/hittracertux.rb",
26
+ "examples/hittracerx.rb",
27
+ "examples/hook_notepad.rb",
28
+ "examples/snicker.rb",
29
+ "examples/tux-example.rb",
30
+ "lib/.DS_Store",
31
+ "lib/ragweed.rb",
32
+ "lib/ragweed/arena.rb",
33
+ "lib/ragweed/blocks.rb",
34
+ "lib/ragweed/debugger32.rb",
35
+ "lib/ragweed/debuggerosx.rb",
36
+ "lib/ragweed/debuggertux.rb",
37
+ "lib/ragweed/detour.rb",
38
+ "lib/ragweed/ptr.rb",
39
+ "lib/ragweed/rasm.rb",
40
+ "lib/ragweed/rasm/bblock.rb",
41
+ "lib/ragweed/rasm/isa.rb",
42
+ "lib/ragweed/sbuf.rb",
43
+ "lib/ragweed/trampoline.rb",
44
+ "lib/ragweed/utils.rb",
45
+ "lib/ragweed/wrap32.rb",
46
+ "lib/ragweed/wrap32/debugging.rb",
47
+ "lib/ragweed/wrap32/device.rb",
48
+ "lib/ragweed/wrap32/event.rb",
49
+ "lib/ragweed/wrap32/hooks.rb",
50
+ "lib/ragweed/wrap32/overlapped.rb",
51
+ "lib/ragweed/wrap32/process.rb",
52
+ "lib/ragweed/wrap32/process_token.rb",
53
+ "lib/ragweed/wrap32/thread_context.rb",
54
+ "lib/ragweed/wrap32/winx.rb",
55
+ "lib/ragweed/wrap32/wrap32.rb",
56
+ "lib/ragweed/wraposx.rb",
57
+ "lib/ragweed/wraposx/constants.rb",
58
+ "lib/ragweed/wraposx/kernelerrorx.rb",
59
+ "lib/ragweed/wraposx/region_info.rb",
60
+ "lib/ragweed/wraposx/structs.rb",
61
+ "lib/ragweed/wraposx/thread_context.rb",
62
+ "lib/ragweed/wraposx/thread_info.rb",
63
+ "lib/ragweed/wraposx/thread_info.rb.old",
64
+ "lib/ragweed/wraposx/wraposx.rb",
65
+ "lib/ragweed/wraptux.rb",
66
+ "lib/ragweed/wraptux/constants.rb",
67
+ "lib/ragweed/wraptux/struct_helpers.rb",
68
+ "lib/ragweed/wraptux/threads.rb",
69
+ "lib/ragweed/wraptux/wraptux.rb",
70
+ "ragweed.gemspec",
71
+ "spec/ragweed_spec.rb",
72
+ "spec/spec_helper.rb",
73
+ "test/test_ragweed.rb"
74
+ ]
75
+ s.homepage = %q{http://github.com/tduehr/ragweed}
76
+ s.rdoc_options = ["--inline-source", "--line-numbers", "--main", "README.rdoc"]
16
77
  s.require_paths = ["lib"]
17
- s.rubyforge_project = %q{}
18
- s.rubygems_version = %q{1.3.5}
78
+ s.rubygems_version = %q{1.3.7}
19
79
  s.summary = %q{Scriptable debugger}
20
- s.test_files = ["test/test_ragweed.rb"]
80
+ s.test_files = [
81
+ "examples/hittracertux.rb",
82
+ "examples/hittracerx.rb",
83
+ "examples/hook_notepad.rb",
84
+ "examples/snicker.rb",
85
+ "examples/tux-example.rb",
86
+ "spec/ragweed_spec.rb",
87
+ "spec/spec_helper.rb",
88
+ "test/test_ragweed.rb"
89
+ ]
21
90
 
22
91
  if s.respond_to? :specification_version then
23
92
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
93
  s.specification_version = 3
25
94
 
26
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
- s.add_development_dependency(%q<bones>, [">= 2.5.1"])
95
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
96
+ s.add_runtime_dependency(%q<ffi>, [">= 0"])
28
97
  else
29
- s.add_dependency(%q<bones>, [">= 2.5.1"])
98
+ s.add_dependency(%q<ffi>, [">= 0"])
30
99
  end
31
100
  else
32
- s.add_dependency(%q<bones>, [">= 2.5.1"])
101
+ s.add_dependency(%q<ffi>, [">= 0"])
33
102
  end
34
103
  end
104
+
metadata CHANGED
@@ -1,27 +1,40 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ragweed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7.3
4
+ hash: -1876988176
5
+ prerelease: true
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 0
10
+ - pre1
11
+ version: 0.2.0.pre1
5
12
  platform: ruby
6
13
  authors:
7
- - tduehr, tqbf, struct
14
+ - tduehr
15
+ - struct
16
+ - tqbf
8
17
  autorequire:
9
18
  bindir: bin
10
19
  cert_chain: []
11
20
 
12
- date: 2009-09-21 00:00:00 -05:00
21
+ date: 2010-11-19 00:00:00 -06:00
13
22
  default_executable:
14
23
  dependencies:
15
24
  - !ruby/object:Gem::Dependency
16
- name: bones
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
25
+ name: ffi
26
+ prerelease: false
27
+ requirement: &id001 !ruby/object:Gem::Requirement
28
+ none: false
20
29
  requirements:
21
30
  - - ">="
22
31
  - !ruby/object:Gem::Version
23
- version: 2.5.1
24
- version:
32
+ hash: 3
33
+ segments:
34
+ - 0
35
+ version: "0"
36
+ type: :runtime
37
+ version_requirements: *id001
25
38
  description: General debugging tool written in Ruby for OSX/Win32/Linux
26
39
  email: td@matasano.com
27
40
  executables: []
@@ -29,7 +42,6 @@ executables: []
29
42
  extensions: []
30
43
 
31
44
  extra_rdoc_files:
32
- - History.txt
33
45
  - README.rdoc
34
46
  - README.txt
35
47
  files:
@@ -37,11 +49,13 @@ files:
37
49
  - README.rdoc
38
50
  - README.txt
39
51
  - Rakefile
52
+ - VERSION
40
53
  - examples/hittracertux.rb
41
54
  - examples/hittracerx.rb
42
55
  - examples/hook_notepad.rb
43
56
  - examples/snicker.rb
44
57
  - examples/tux-example.rb
58
+ - lib/.DS_Store
45
59
  - lib/ragweed.rb
46
60
  - lib/ragweed/arena.rb
47
61
  - lib/ragweed/blocks.rb
@@ -71,11 +85,14 @@ files:
71
85
  - lib/ragweed/wraposx/constants.rb
72
86
  - lib/ragweed/wraposx/kernelerrorx.rb
73
87
  - lib/ragweed/wraposx/region_info.rb
88
+ - lib/ragweed/wraposx/structs.rb
74
89
  - lib/ragweed/wraposx/thread_context.rb
75
90
  - lib/ragweed/wraposx/thread_info.rb
91
+ - lib/ragweed/wraposx/thread_info.rb.old
76
92
  - lib/ragweed/wraposx/wraposx.rb
77
93
  - lib/ragweed/wraptux.rb
78
94
  - lib/ragweed/wraptux/constants.rb
95
+ - lib/ragweed/wraptux/struct_helpers.rb
79
96
  - lib/ragweed/wraptux/threads.rb
80
97
  - lib/ragweed/wraptux/wraptux.rb
81
98
  - ragweed.gemspec
@@ -83,7 +100,7 @@ files:
83
100
  - spec/spec_helper.rb
84
101
  - test/test_ragweed.rb
85
102
  has_rdoc: true
86
- homepage: http://github.com/tduehr/ragweed/tree/master
103
+ homepage: http://github.com/tduehr/ragweed
87
104
  licenses: []
88
105
 
89
106
  post_install_message:
@@ -91,27 +108,42 @@ rdoc_options:
91
108
  - --inline-source
92
109
  - --line-numbers
93
110
  - --main
94
- - README.txt
111
+ - README.rdoc
95
112
  require_paths:
96
113
  - lib
97
114
  required_ruby_version: !ruby/object:Gem::Requirement
115
+ none: false
98
116
  requirements:
99
117
  - - ">="
100
118
  - !ruby/object:Gem::Version
119
+ hash: 3
120
+ segments:
121
+ - 0
101
122
  version: "0"
102
- version:
103
123
  required_rubygems_version: !ruby/object:Gem::Requirement
124
+ none: false
104
125
  requirements:
105
- - - ">="
126
+ - - ">"
106
127
  - !ruby/object:Gem::Version
107
- version: "0"
108
- version:
128
+ hash: 25
129
+ segments:
130
+ - 1
131
+ - 3
132
+ - 1
133
+ version: 1.3.1
109
134
  requirements: []
110
135
 
111
- rubyforge_project: ""
112
- rubygems_version: 1.3.5
136
+ rubyforge_project:
137
+ rubygems_version: 1.3.7
113
138
  signing_key:
114
139
  specification_version: 3
115
140
  summary: Scriptable debugger
116
141
  test_files:
142
+ - examples/hittracertux.rb
143
+ - examples/hittracerx.rb
144
+ - examples/hook_notepad.rb
145
+ - examples/snicker.rb
146
+ - examples/tux-example.rb
147
+ - spec/ragweed_spec.rb
148
+ - spec/spec_helper.rb
117
149
  - test/test_ragweed.rb