ruby-macho 1.0.0 → 1.1.0
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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/macho.rb +5 -5
- data/lib/macho/exceptions.rb +8 -4
- data/lib/macho/fat_file.rb +96 -96
- data/lib/macho/headers.rb +75 -0
- data/lib/macho/load_commands.rb +86 -53
- data/lib/macho/macho_file.rb +83 -131
- data/lib/macho/sections.rb +8 -5
- data/lib/macho/structure.rb +1 -1
- data/lib/macho/tools.rb +29 -5
- data/lib/macho/utils.rb +12 -9
- metadata +3 -3
data/lib/macho/sections.rb
CHANGED
@@ -72,7 +72,8 @@ module MachO
|
|
72
72
|
# @return [String] the name of the section, including null pad bytes
|
73
73
|
attr_reader :sectname
|
74
74
|
|
75
|
-
# @return [String] the name of the segment's section, including null
|
75
|
+
# @return [String] the name of the segment's section, including null
|
76
|
+
# pad bytes
|
76
77
|
attr_reader :segname
|
77
78
|
|
78
79
|
# @return [Fixnum] the memory address of the section
|
@@ -124,17 +125,19 @@ module MachO
|
|
124
125
|
@reserved2 = reserved2
|
125
126
|
end
|
126
127
|
|
127
|
-
# @return [String] the section's name, with any trailing NULL characters
|
128
|
+
# @return [String] the section's name, with any trailing NULL characters
|
129
|
+
# removed
|
128
130
|
def section_name
|
129
131
|
sectname.delete("\x00")
|
130
132
|
end
|
131
133
|
|
132
|
-
# @return [String] the parent segment's name, with any trailing NULL
|
134
|
+
# @return [String] the parent segment's name, with any trailing NULL
|
135
|
+
# characters removed
|
133
136
|
def segment_name
|
134
137
|
segname.delete("\x00")
|
135
138
|
end
|
136
139
|
|
137
|
-
# @return [Boolean]
|
140
|
+
# @return [Boolean] whether the section is empty (i.e, {size} is 0)
|
138
141
|
def empty?
|
139
142
|
size.zero?
|
140
143
|
end
|
@@ -142,7 +145,7 @@ module MachO
|
|
142
145
|
# @example
|
143
146
|
# puts "this section is regular" if sect.flag?(:S_REGULAR)
|
144
147
|
# @param flag [Symbol] a section flag symbol
|
145
|
-
# @return [Boolean]
|
148
|
+
# @return [Boolean] whether the flag is present in the section's {flags}
|
146
149
|
def flag?(flag)
|
147
150
|
flag = SECTION_FLAGS[flag]
|
148
151
|
return false if flag.nil?
|
data/lib/macho/structure.rb
CHANGED
@@ -19,7 +19,7 @@ module MachO
|
|
19
19
|
|
20
20
|
# @param endianness [Symbol] either `:big` or `:little`
|
21
21
|
# @param bin [String] the string to be unpacked into the new structure
|
22
|
-
# @return [MachO::MachOStructure]
|
22
|
+
# @return [MachO::MachOStructure] the resulting structure
|
23
23
|
# @api private
|
24
24
|
def self.new_from_bin(endianness, bin)
|
25
25
|
format = Utils.specialize_format(self::FORMAT, endianness)
|
data/lib/macho/tools.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module MachO
|
2
|
-
# A collection of convenient methods for common operations on Mach-O and Fat
|
2
|
+
# A collection of convenient methods for common operations on Mach-O and Fat
|
3
|
+
# binaries.
|
3
4
|
module Tools
|
4
5
|
# @param filename [String] the Mach-O or Fat binary being read
|
5
6
|
# @return [Array<String>] an array of all dylibs linked to the binary
|
@@ -9,7 +10,8 @@ module MachO
|
|
9
10
|
file.linked_dylibs
|
10
11
|
end
|
11
12
|
|
12
|
-
# Changes the dylib ID of a Mach-O or Fat binary, overwriting the source
|
13
|
+
# Changes the dylib ID of a Mach-O or Fat binary, overwriting the source
|
14
|
+
# file.
|
13
15
|
# @param filename [String] the Mach-O or Fat binary being modified
|
14
16
|
# @param new_id [String] the new dylib ID for the binary
|
15
17
|
# @param options [Hash]
|
@@ -23,7 +25,8 @@ module MachO
|
|
23
25
|
file.write!
|
24
26
|
end
|
25
27
|
|
26
|
-
# Changes a shared library install name in a Mach-O or Fat binary,
|
28
|
+
# Changes a shared library install name in a Mach-O or Fat binary,
|
29
|
+
# overwriting the source file.
|
27
30
|
# @param filename [String] the Mach-O or Fat binary being modified
|
28
31
|
# @param old_name [String] the old shared library name
|
29
32
|
# @param new_name [String] the new shared library name
|
@@ -38,7 +41,8 @@ module MachO
|
|
38
41
|
file.write!
|
39
42
|
end
|
40
43
|
|
41
|
-
# Changes a runtime path in a Mach-O or Fat binary, overwriting the source
|
44
|
+
# Changes a runtime path in a Mach-O or Fat binary, overwriting the source
|
45
|
+
# file.
|
42
46
|
# @param filename [String] the Mach-O or Fat binary being modified
|
43
47
|
# @param old_path [String] the old runtime path
|
44
48
|
# @param new_path [String] the new runtime path
|
@@ -67,7 +71,8 @@ module MachO
|
|
67
71
|
file.write!
|
68
72
|
end
|
69
73
|
|
70
|
-
# Delete a runtime path from a Mach-O or Fat binary, overwriting the source
|
74
|
+
# Delete a runtime path from a Mach-O or Fat binary, overwriting the source
|
75
|
+
# file.
|
71
76
|
# @param filename [String] the Mach-O or Fat binary being modified
|
72
77
|
# @param old_path [String] the old runtime path
|
73
78
|
# @param options [Hash]
|
@@ -80,5 +85,24 @@ module MachO
|
|
80
85
|
file.delete_rpath(old_path, options)
|
81
86
|
file.write!
|
82
87
|
end
|
88
|
+
|
89
|
+
# Merge multiple Mach-Os into one universal (Fat) binary.
|
90
|
+
# @param filename [String] the fat binary to create
|
91
|
+
# @param files [Array<MachO::MachOFile, MachO::FatFile>] the files to merge
|
92
|
+
# @return [void]
|
93
|
+
def self.merge_machos(filename, *files)
|
94
|
+
machos = files.map do |file|
|
95
|
+
macho = MachO.open(file)
|
96
|
+
case macho
|
97
|
+
when MachO::MachOFile
|
98
|
+
macho
|
99
|
+
else
|
100
|
+
macho.machos
|
101
|
+
end
|
102
|
+
end.flatten
|
103
|
+
|
104
|
+
fat_macho = MachO::FatFile.new_from_machos(*machos)
|
105
|
+
fat_macho.write(filename)
|
106
|
+
end
|
83
107
|
end
|
84
108
|
end
|
data/lib/macho/utils.rb
CHANGED
@@ -13,7 +13,8 @@ module MachO
|
|
13
13
|
value
|
14
14
|
end
|
15
15
|
|
16
|
-
# Returns the number of bytes needed to pad the given size to the given
|
16
|
+
# Returns the number of bytes needed to pad the given size to the given
|
17
|
+
# alignment.
|
17
18
|
# @param size [Fixnum] the unpadded size
|
18
19
|
# @param alignment [Fixnum] the number to alignment the size with
|
19
20
|
# @return [Fixnum] the number of pad bytes required
|
@@ -21,7 +22,8 @@ module MachO
|
|
21
22
|
round(size, alignment) - size
|
22
23
|
end
|
23
24
|
|
24
|
-
# Converts an abstract (native-endian) String#unpack format to big or
|
25
|
+
# Converts an abstract (native-endian) String#unpack format to big or
|
26
|
+
# little.
|
25
27
|
# @param format [String] the format string being converted
|
26
28
|
# @param endianness [Symbol] either `:big` or `:little`
|
27
29
|
# @return [String] the converted string
|
@@ -31,7 +33,8 @@ module MachO
|
|
31
33
|
end
|
32
34
|
|
33
35
|
# Packs tagged strings into an aligned payload.
|
34
|
-
# @param fixed_offset [Fixnum] the baseline offset for the first packed
|
36
|
+
# @param fixed_offset [Fixnum] the baseline offset for the first packed
|
37
|
+
# string
|
35
38
|
# @param alignment [Fixnum] the alignment value to use for packing
|
36
39
|
# @param strings [Hash] the labeled strings to pack
|
37
40
|
# @return [Array<String, Hash>] the packed string and labeled offsets
|
@@ -53,42 +56,42 @@ module MachO
|
|
53
56
|
|
54
57
|
# Compares the given number to valid Mach-O magic numbers.
|
55
58
|
# @param num [Fixnum] the number being checked
|
56
|
-
# @return [Boolean]
|
59
|
+
# @return [Boolean] whether `num` is a valid Mach-O magic number
|
57
60
|
def self.magic?(num)
|
58
61
|
Headers::MH_MAGICS.key?(num)
|
59
62
|
end
|
60
63
|
|
61
64
|
# Compares the given number to valid Fat magic numbers.
|
62
65
|
# @param num [Fixnum] the number being checked
|
63
|
-
# @return [Boolean]
|
66
|
+
# @return [Boolean] whether `num` is a valid Fat magic number
|
64
67
|
def self.fat_magic?(num)
|
65
68
|
num == Headers::FAT_MAGIC
|
66
69
|
end
|
67
70
|
|
68
71
|
# Compares the given number to valid 32-bit Mach-O magic numbers.
|
69
72
|
# @param num [Fixnum] the number being checked
|
70
|
-
# @return [Boolean]
|
73
|
+
# @return [Boolean] whether `num` is a valid 32-bit magic number
|
71
74
|
def self.magic32?(num)
|
72
75
|
num == Headers::MH_MAGIC || num == Headers::MH_CIGAM
|
73
76
|
end
|
74
77
|
|
75
78
|
# Compares the given number to valid 64-bit Mach-O magic numbers.
|
76
79
|
# @param num [Fixnum] the number being checked
|
77
|
-
# @return [Boolean]
|
80
|
+
# @return [Boolean] whether `num` is a valid 64-bit magic number
|
78
81
|
def self.magic64?(num)
|
79
82
|
num == Headers::MH_MAGIC_64 || num == Headers::MH_CIGAM_64
|
80
83
|
end
|
81
84
|
|
82
85
|
# Compares the given number to valid little-endian magic numbers.
|
83
86
|
# @param num [Fixnum] the number being checked
|
84
|
-
# @return [Boolean]
|
87
|
+
# @return [Boolean] whether `num` is a valid little-endian magic number
|
85
88
|
def self.little_magic?(num)
|
86
89
|
num == Headers::MH_CIGAM || num == Headers::MH_CIGAM_64
|
87
90
|
end
|
88
91
|
|
89
92
|
# Compares the given number to valid big-endian magic numbers.
|
90
93
|
# @param num [Fixnum] the number being checked
|
91
|
-
# @return [Boolean]
|
94
|
+
# @return [Boolean] whether `num` is a valid big-endian magic number
|
92
95
|
def self.big_magic?(num)
|
93
96
|
num == Headers::MH_CIGAM || num == Headers::MH_CIGAM_64
|
94
97
|
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: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Woodruff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-26 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
|
@@ -50,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
50
|
version: '0'
|
51
51
|
requirements: []
|
52
52
|
rubyforge_project:
|
53
|
-
rubygems_version: 2.
|
53
|
+
rubygems_version: 2.6.8
|
54
54
|
signing_key:
|
55
55
|
specification_version: 4
|
56
56
|
summary: ruby-macho - Mach-O file analyzer.
|