ruby-macho 0.0.5 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/macho.rb +20 -11
- data/lib/macho/exceptions.rb +11 -0
- data/lib/macho/fat_file.rb +2 -2
- data/lib/macho/macho_file.rb +12 -7
- data/lib/macho/utils.rb +18 -20
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6903e361104a718205c145e401ee484e38289217
|
4
|
+
data.tar.gz: 1bcea8a215a1e19b2cde870818206152582162be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc14af02958fa369eac1e5fe6a4cce3fff48d21797d601fe4d4778a80336253fae58864994504a2612989ab718bcdb0c475edb797792dbbdfb6d09eb1840657d
|
7
|
+
data.tar.gz: a0d438e785176bbc06556889440aaf013181898ceec4012a837c181c785d5a6be508fc830b0027e456107682cfd5845040a2c1bef6338e05cfdb4e6212c1f57a
|
data/lib/macho.rb
CHANGED
@@ -1,14 +1,23 @@
|
|
1
|
-
require "cstruct"
|
2
|
-
require "macho/headers"
|
3
|
-
require "macho/structure"
|
4
|
-
require "macho/load_commands"
|
5
|
-
require "macho/sections"
|
6
|
-
require "macho/macho_file"
|
7
|
-
require "macho/fat_file"
|
8
|
-
require "macho/exceptions"
|
9
|
-
require "macho/utils"
|
10
|
-
require "macho/tools"
|
1
|
+
require "#{File.dirname(__FILE__)}/cstruct"
|
2
|
+
require "#{File.dirname(__FILE__)}/macho/headers"
|
3
|
+
require "#{File.dirname(__FILE__)}/macho/structure"
|
4
|
+
require "#{File.dirname(__FILE__)}/macho/load_commands"
|
5
|
+
require "#{File.dirname(__FILE__)}/macho/sections"
|
6
|
+
require "#{File.dirname(__FILE__)}/macho/macho_file"
|
7
|
+
require "#{File.dirname(__FILE__)}/macho/fat_file"
|
8
|
+
require "#{File.dirname(__FILE__)}/macho/exceptions"
|
9
|
+
require "#{File.dirname(__FILE__)}/macho/utils"
|
10
|
+
require "#{File.dirname(__FILE__)}/macho/tools"
|
11
11
|
|
12
12
|
module MachO
|
13
|
-
|
13
|
+
def self.open(filename)
|
14
|
+
# open file and test magic instead of using exceptions for control?
|
15
|
+
begin
|
16
|
+
file = MachOFile.new(filename)
|
17
|
+
rescue FatBinaryError
|
18
|
+
file = FatFile.new(filename)
|
19
|
+
end
|
20
|
+
|
21
|
+
file
|
22
|
+
end
|
14
23
|
end
|
data/lib/macho/exceptions.rb
CHANGED
@@ -10,24 +10,28 @@ module MachO
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
# raised when a fat binary is loaded with MachOFile
|
13
14
|
class FatBinaryError < MachOError
|
14
15
|
def initialize
|
15
16
|
super "Fat binaries must be loaded with MachO::FatFile"
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
20
|
+
# raised when a mach-o is loaded with FatFile
|
19
21
|
class MachOBinaryError < MachOError
|
20
22
|
def initialize
|
21
23
|
super "Normal binaries must be loaded with MachO::MachOFile"
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
27
|
+
# raised when the CPU type is unknown
|
25
28
|
class CPUTypeError < MachOError
|
26
29
|
def initialize(num)
|
27
30
|
super "Unrecognized CPU type: 0x#{"%02x" % num}"
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
34
|
+
# raised when the CPU subtype is unknown
|
31
35
|
class CPUSubtypeError < MachOError
|
32
36
|
def initialize(num)
|
33
37
|
super "Unrecognized CPU sub-type: 0x#{"%02x" % num}"
|
@@ -56,4 +60,11 @@ module MachO
|
|
56
60
|
"-headerpad or -headerpad_max_install_names"
|
57
61
|
end
|
58
62
|
end
|
63
|
+
|
64
|
+
# raised when attempting to change a dylib name that doesn't exist
|
65
|
+
class DylibUnknownError < MachOError
|
66
|
+
def initialize(dylib)
|
67
|
+
super "No such dylib name: #{dylib}"
|
68
|
+
end
|
69
|
+
end
|
59
70
|
end
|
data/lib/macho/fat_file.rb
CHANGED
@@ -67,11 +67,11 @@ module MachO
|
|
67
67
|
def get_fat_header
|
68
68
|
magic, nfat_arch = @raw_data[0..7].unpack("N2")
|
69
69
|
|
70
|
-
if !
|
70
|
+
if !MachO.magic?(magic)
|
71
71
|
raise MagicError.new(magic)
|
72
72
|
end
|
73
73
|
|
74
|
-
if !
|
74
|
+
if !MachO.fat_magic?(magic)
|
75
75
|
raise MachOBinaryError.new
|
76
76
|
end
|
77
77
|
|
data/lib/macho/macho_file.rb
CHANGED
@@ -30,11 +30,11 @@ module MachO
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def magic32?
|
33
|
-
|
33
|
+
MachO.magic32?(header[:magic])
|
34
34
|
end
|
35
35
|
|
36
36
|
def magic64?
|
37
|
-
|
37
|
+
MachO.magic64?(header[:magic])
|
38
38
|
end
|
39
39
|
|
40
40
|
# is the file executable?
|
@@ -144,8 +144,8 @@ module MachO
|
|
144
144
|
old_id = dylib_id
|
145
145
|
new_id = new_id.dup
|
146
146
|
|
147
|
-
new_pad =
|
148
|
-
old_pad =
|
147
|
+
new_pad = MachO.round(new_id.size, cmd_round) - new_id.size
|
148
|
+
old_pad = MachO.round(old_id.size, cmd_round) - old_id.size
|
149
149
|
|
150
150
|
# pad the old and new IDs with null bytes to meet command bounds
|
151
151
|
old_id << "\x00" * old_pad
|
@@ -217,6 +217,11 @@ module MachO
|
|
217
217
|
dylibs
|
218
218
|
end
|
219
219
|
|
220
|
+
# stub
|
221
|
+
def change_dylib!(old_path, new_path)
|
222
|
+
raise DylibUnknownError.new(old_path) unless linked_dylibs.include?(old_path)
|
223
|
+
end
|
224
|
+
|
220
225
|
# get all sections in a segment by name
|
221
226
|
def sections(segment)
|
222
227
|
sections = []
|
@@ -267,7 +272,7 @@ module MachO
|
|
267
272
|
sizeofcmds = get_sizeofcmds
|
268
273
|
flags = get_flags
|
269
274
|
|
270
|
-
if
|
275
|
+
if MachO.magic32?(magic)
|
271
276
|
MachHeader.new(magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds, flags)
|
272
277
|
else
|
273
278
|
# the reserved field is...reserved, so just fill it with 0
|
@@ -278,11 +283,11 @@ module MachO
|
|
278
283
|
def get_magic
|
279
284
|
magic = @raw_data[0..3].unpack("N").first
|
280
285
|
|
281
|
-
if !
|
286
|
+
if !MachO.magic?(magic)
|
282
287
|
raise MagicError.new(magic)
|
283
288
|
end
|
284
289
|
|
285
|
-
if
|
290
|
+
if MachO.fat_magic?(magic)
|
286
291
|
raise FatBinaryError.new
|
287
292
|
end
|
288
293
|
|
data/lib/macho/utils.rb
CHANGED
@@ -1,27 +1,25 @@
|
|
1
1
|
module MachO
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
2
|
+
# http://www.opensource.apple.com/source/cctools/cctools-870/libstuff/rnd.c
|
3
|
+
def self.round(value, round)
|
4
|
+
round -= 1
|
5
|
+
value += round
|
6
|
+
value &= ~round
|
7
|
+
value
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def self.magic?(num)
|
11
|
+
MH_MAGICS.has_key?(num)
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def self.fat_magic?(num)
|
15
|
+
num == FAT_MAGIC || num == FAT_CIGAM
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
def self.magic32?(num)
|
19
|
+
num == MH_MAGIC || num == MH_CIGAM
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
end
|
22
|
+
def self.magic64?(num)
|
23
|
+
num == MH_MAGIC_64 || num == MH_CIGAM_64
|
26
24
|
end
|
27
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-macho
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Woodruff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A library for viewing and manipulating Mach-O files in Ruby.
|
14
14
|
email: william@tuffbizz.com
|
@@ -46,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
46
|
version: '0'
|
47
47
|
requirements: []
|
48
48
|
rubyforge_project:
|
49
|
-
rubygems_version: 2.4.5
|
49
|
+
rubygems_version: 2.4.5.1
|
50
50
|
signing_key:
|
51
51
|
specification_version: 4
|
52
52
|
summary: ruby-macho - Mach-O file analyzer.
|