machery 0.0.1

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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YWFjNWMzNWNkYWIzMTRlOWVlOWRiYzE4MmUyMGY5Zjk4NmIwMzljNA==
5
+ data.tar.gz: !binary |-
6
+ YzMwMzBkM2U4MjhlYzlkYzcyZDA1NGQyNmQ5OTY0NTdhN2ExYjliMw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZmFhNDM5MTYwZjQ1OGE2ZTZjM2RkYzZkM2I1NDcxMjlhY2U2YmRkNzcwNTNh
10
+ Y2Y5MzMwNzg3MzI0MDIwOTg2Y2M1ZGVkNWVmOTQ4YTAzZDY0Y2VmODJhNjdj
11
+ NzI0MDI2YmM3MzdhYzhjNjRhOTNhNGUxNzI3Mzc1MGRiMTU2MTM=
12
+ data.tar.gz: !binary |-
13
+ Y2Q0NDczNDkzZTc4OTg1MWNhZGRiNmNiYTFiZjM3NGZjZWVkOThjYWQ4ZDhi
14
+ ZjkxYjc5Yzc3Mjk3ZGU5Nzc5YTM1MGJlNzUzNTM3N2FiMmUyZTg2NzZkNjVj
15
+ NjQ5NWU0YTA0ODhmNTk1M2M0ZjkwYzdhYTRmZjYwMTYxZmM4ZWI=
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ ./test.rb
@@ -0,0 +1,2 @@
1
+ ruby-1.9.3-p392@machery
2
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in machery.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Adam Hallett
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Machery
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'machery'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install machery
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/machery/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,8 @@
1
+ require 'ffi'
2
+ require 'ffi-inliner'
3
+ require 'machery/version'
4
+ require 'machery/vm_methods'
5
+
6
+ module Machery
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,3 @@
1
+ module Machery
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,64 @@
1
+ module Machery
2
+ extend FFI::Library
3
+ extend Inliner
4
+
5
+ inline '
6
+ #include <stdio.h>
7
+ #include <stdlib.h>
8
+ #include <mach/mach.h>
9
+ #include <mach/mach_vm.h>
10
+ void * c_mach_vm_read( int pid , uint64_t address, int len) {
11
+
12
+ kern_return_t kr;
13
+ mach_port_t target_task;
14
+ vm_offset_t local_address;
15
+ mach_msg_type_number_t local_size = vm_page_size;
16
+ mach_vm_size_t size = (mach_vm_size_t)vm_page_size;
17
+
18
+ kr = task_for_pid(mach_task_self(), pid, &target_task);
19
+
20
+ if ( kr != 0 ){
21
+ return NULL;
22
+ }
23
+
24
+ kr = mach_vm_read(target_task, address, size, &local_address, &local_size);
25
+
26
+ if ( kr != 0 ){
27
+ return NULL;
28
+ }
29
+
30
+ void * bytes = (void *)malloc(local_size * 2 * sizeof(char));
31
+ memcpy(bytes, ( const void *)local_address, local_size);
32
+ mach_vm_deallocate(mach_task_self(), address, local_size);
33
+
34
+ return bytes;
35
+ }
36
+ '
37
+
38
+ PAGE_SIZE = 4096
39
+
40
+ attach_function :free, [:pointer], :void
41
+
42
+ def self.read( pid, address, len )
43
+ bottom = page_down( address )
44
+ top = page_align_up(address + len)
45
+ new_length = top - bottom
46
+
47
+ byte_ptr = c_mach_vm_read(pid, bottom, new_length)
48
+
49
+ return nil if byte_ptr.null?
50
+
51
+ ret = byte_ptr.read_string(new_length)[address - bottom..-1]
52
+ free(byte_ptr)
53
+ ret
54
+ end
55
+
56
+ def self.page_down( address )
57
+ ((address)&(~((PAGE_SIZE)-1)))
58
+ end
59
+
60
+ def self.page_align_up( address )
61
+ (((address)+((PAGE_SIZE)-1))&(~((PAGE_SIZE)-1)));
62
+ end
63
+
64
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'machery/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'machery'
8
+ spec.version = Machery::VERSION
9
+ spec.authors = ['Adam Hallett']
10
+ spec.email = ['adam.t.hallett@gmail.com']
11
+ spec.summary = %q{A wrapper for accessing Mach OSX functions in Ruby.}
12
+ spec.description = %q{A wrapper for accessing Mach OSX functions in Ruby.}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'debugger'
24
+
25
+ spec.add_dependency 'ffi'
26
+ spec.add_dependency 'ffi-inliner', '>= 0.2.4'
27
+ end
data/test.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'machery'
2
+
3
+ address = 0x10931D36E
4
+
5
+ while 1
6
+ p Machery.read(2291, address, 2000)
7
+
8
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: machery
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Adam Hallett
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: debugger
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ffi
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: ffi-inliner
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.2.4
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.2.4
83
+ description: A wrapper for accessing Mach OSX functions in Ruby.
84
+ email:
85
+ - adam.t.hallett@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .ruby-version
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/machery.rb
97
+ - lib/machery/version.rb
98
+ - lib/machery/vm_methods.rb
99
+ - machery.gemspec
100
+ - test.rb
101
+ homepage: ''
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.2.2
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: A wrapper for accessing Mach OSX functions in Ruby.
125
+ test_files: []