ruby-macho 0.2.1 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90daf462e0ebdf631ea6f5a9b045ae9d590ecd5c
4
- data.tar.gz: 44da8c060f29021a991842f6728140b433a868c5
3
+ metadata.gz: f149c2c7085b336a2447513e28f10d59afc88062
4
+ data.tar.gz: 1f938c11b54535cc8b92a625235bff9a34572ceb
5
5
  SHA512:
6
- metadata.gz: e25c029ab6f3819dc255a1ebe0c77d343896a4e971dc3c3f54cdb97999fcf88ca042aa7a730897d866ec9a6e04113180ce23e5d4e9133d22ce1dcca326658da1
7
- data.tar.gz: fa24c66f7de915d030829ef174764a045b0e45bae3f2cfe858fdf8a2b83e417d5e42e27f5486886355fb3260f21c0313730b4fe4b47007b743984b3dcd74e977
6
+ metadata.gz: 09cd628c568572c632897f1799e784a2668b41ef1c476a84db7c8a438b96832cd54f85050fd4aef593def43b82c90af4cdacdf5a607eb56b4c607390ffdcaddf
7
+ data.tar.gz: f58bc28a331f6d9ec3d7c98e98d3d1d630788a31ec0fa7d82eef0bc43d254126726f8198581eb11c14f626078c92475fcf6de4742f5170008aa0553db9ffffc6
data/lib/macho.rb CHANGED
@@ -12,5 +12,5 @@ require "#{File.dirname(__FILE__)}/macho/tools"
12
12
  # The primary namespace for ruby-macho.
13
13
  module MachO
14
14
  # release version
15
- VERSION = "0.2.1".freeze
15
+ VERSION = "0.2.2".freeze
16
16
  end
@@ -32,60 +32,62 @@ module MachO
32
32
  @raw_data
33
33
  end
34
34
 
35
- # @return [Boolean] true if the Mach-O is of type `MH_OBJECT`, false otherwise
35
+ # @return [Boolean] true if the file is of type `MH_OBJECT`, false otherwise
36
36
  def object?
37
37
  machos.first.object?
38
38
  end
39
39
 
40
- # @return [Boolean] true if the Mach-O is of type `MH_EXECUTE`, false otherwise
40
+ # @return [Boolean] true if the file is of type `MH_EXECUTE`, false otherwise
41
41
  def executable?
42
42
  machos.first.executable?
43
43
  end
44
44
 
45
- # @return [Boolean] true if the Mach-O is of type `MH_FVMLIB`, false otherwise
45
+ # @return [Boolean] true if the file is of type `MH_FVMLIB`, false otherwise
46
46
  def fvmlib?
47
47
  machos.first.fvmlib?
48
48
  end
49
49
 
50
- # @return [Boolean] true if the Mach-O is of type `MH_CORE`, false otherwise
50
+ # @return [Boolean] true if the file is of type `MH_CORE`, false otherwise
51
51
  def core?
52
52
  machos.first.core?
53
53
  end
54
54
 
55
- # @return [Boolean] true if the Mach-O is of type `MH_PRELOAD`, false otherwise
55
+ # @return [Boolean] true if the file is of type `MH_PRELOAD`, false otherwise
56
56
  def preload?
57
57
  machos.first.preload?
58
58
  end
59
59
 
60
- # @return [Boolean] true if the Mach-O is of type `MH_DYLIB`, false otherwise
60
+ # @return [Boolean] true if the file is of type `MH_DYLIB`, false otherwise
61
61
  def dylib?
62
62
  machos.first.dylib?
63
63
  end
64
64
 
65
- # @return [Boolean] true if the Mach-O is of type `MH_DYLINKER`, false otherwise
65
+ # @return [Boolean] true if the file is of type `MH_DYLINKER`, false otherwise
66
66
  def dylinker?
67
67
  machos.first.dylinker?
68
68
  end
69
69
 
70
- # @return [Boolean] true if the Mach-O is of type `MH_BUNDLE`, false otherwise
70
+ # @return [Boolean] true if the file is of type `MH_BUNDLE`, false otherwise
71
71
  def bundle?
72
72
  machos.first.bundle?
73
73
  end
74
74
 
75
- # @return [Boolean] true if the Mach-O is of type `MH_DSYM`, false otherwise
75
+ # @return [Boolean] true if the file is of type `MH_DSYM`, false otherwise
76
76
  def dsym?
77
77
  machos.first.dsym?
78
78
  end
79
79
 
80
- # @return [Boolean] true if the Mach-O is of type `MH_KEXT_BUNDLE`, false otherwise
80
+ # @return [Boolean] true if the file is of type `MH_KEXT_BUNDLE`, false otherwise
81
81
  def kext?
82
82
  machos.first.kext?
83
83
  end
84
84
 
85
+ # @return [Fixnum] the file's magic number
85
86
  def magic
86
87
  header.magic
87
88
  end
88
89
 
90
+ # @return [String] a string representation of the file's magic number
89
91
  def magic_string
90
92
  MH_MAGICS[magic]
91
93
  end
@@ -129,10 +131,8 @@ module MachO
129
131
  # All shared libraries linked to the file's Mach-Os.
130
132
  # @return [Array<String>] an array of all shared libraries
131
133
  def linked_dylibs
132
- dylibs = machos.map(&:linked_dylibs).flatten
133
-
134
134
  # can machos inside fat binaries have different dylibs?
135
- dylibs.uniq!
135
+ machos.flat_map(&:linked_dylibs).uniq
136
136
  end
137
137
 
138
138
  # Changes all dependent shared library install names from `old_name` to `new_name`.
@@ -55,6 +55,16 @@ module MachO
55
55
  0x2e => :LC_LINKER_OPTIMIZATION_HINT
56
56
  }
57
57
 
58
+ # load commands responsible for loading dylibs
59
+ # @api private
60
+ DYLIB_LOAD_COMMANDS = [
61
+ :LC_LOAD_DYLIB,
62
+ :LC_LOAD_WEAK_DYLIB,
63
+ :LC_REEXPORT_DYLIB,
64
+ :LC_LAZY_LOAD_DYLIB,
65
+ :LC_LOAD_UPWARD_DYLIB,
66
+ ].freeze
67
+
58
68
  # association of load command symbols to string representations of classes
59
69
  # @api private
60
70
  LC_STRUCTURES = {
@@ -89,11 +99,11 @@ module MachO
89
99
  :LC_CODE_SIGNATURE => "LinkeditDataCommand",
90
100
  :LC_SEGMENT_SPLIT_INFO => "LinkeditDataCommand",
91
101
  :LC_REEXPORT_DYLIB => "DylibCommand",
92
- :LC_LAZY_LOAD_DYLIB => "LoadCommand", # undoc, maybe DylibCommand?
102
+ :LC_LAZY_LOAD_DYLIB => "DylibCommand",
93
103
  :LC_ENCRYPTION_INFO => "EncryptionInfoCommand",
94
104
  :LC_DYLD_INFO => "DyldInfoCommand",
95
105
  :LC_DYLD_INFO_ONLY => "DyldInfoCommand",
96
- :LC_LOAD_UPWARD_DYLIB => "LoadCommand", # undoc, maybe DylibCommand?
106
+ :LC_LOAD_UPWARD_DYLIB => "DylibCommand",
97
107
  :LC_VERSION_MIN_MACOSX => "VersionMinCommand",
98
108
  :LC_VERSION_MIN_IPHONEOS => "VersionMinCommand",
99
109
  :LC_FUNCTION_STARTS => "LinkeditDataCommand",
@@ -58,62 +58,62 @@ module MachO
58
58
  MachO.magic64?(header.magic)
59
59
  end
60
60
 
61
- # @return [Boolean] true if the Mach-O is of type `MH_OBJECT`, false otherwise
61
+ # @return [Boolean] true if the file is of type `MH_OBJECT`, false otherwise
62
62
  def object?
63
63
  header.filetype == MH_OBJECT
64
64
  end
65
65
 
66
- # @return [Boolean] true if the Mach-O is of type `MH_EXECUTE`, false otherwise
66
+ # @return [Boolean] true if the file is of type `MH_EXECUTE`, false otherwise
67
67
  def executable?
68
68
  header.filetype == MH_EXECUTE
69
69
  end
70
70
 
71
- # @return [Boolean] true if the Mach-O is of type `MH_FVMLIB`, false otherwise
71
+ # @return [Boolean] true if the file is of type `MH_FVMLIB`, false otherwise
72
72
  def fvmlib?
73
73
  header.filetype == MH_FVMLIB
74
74
  end
75
75
 
76
- # @return [Boolean] true if the Mach-O is of type `MH_CORE`, false otherwise
76
+ # @return [Boolean] true if the file is of type `MH_CORE`, false otherwise
77
77
  def core?
78
78
  header.filetype == MH_CORE
79
79
  end
80
80
 
81
- # @return [Boolean] true if the Mach-O is of type `MH_PRELOAD`, false otherwise
81
+ # @return [Boolean] true if the file is of type `MH_PRELOAD`, false otherwise
82
82
  def preload?
83
83
  header.filetype == MH_PRELOAD
84
84
  end
85
85
 
86
- # @return [Boolean] true if the Mach-O is of type `MH_DYLIB`, false otherwise
86
+ # @return [Boolean] true if the file is of type `MH_DYLIB`, false otherwise
87
87
  def dylib?
88
88
  header.filetype == MH_DYLIB
89
89
  end
90
90
 
91
- # @return [Boolean] true if the Mach-O is of type `MH_DYLINKER`, false otherwise
91
+ # @return [Boolean] true if the file is of type `MH_DYLINKER`, false otherwise
92
92
  def dylinker?
93
93
  header.filetype == MH_DYLINKER
94
94
  end
95
95
 
96
- # @return [Boolean] true if the Mach-O is of type `MH_BUNDLE`, false otherwise
96
+ # @return [Boolean] true if the file is of type `MH_BUNDLE`, false otherwise
97
97
  def bundle?
98
98
  header.filetype == MH_BUNDLE
99
99
  end
100
100
 
101
- # @return [Boolean] true if the Mach-O is of type `MH_DSYM`, false otherwise
101
+ # @return [Boolean] true if the file is of type `MH_DSYM`, false otherwise
102
102
  def dsym?
103
103
  header.filetype == MH_DSYM
104
104
  end
105
105
 
106
- # @return [Boolean] true if the Mach-O is of type `MH_KEXT_BUNDLE`, false otherwise
106
+ # @return [Boolean] true if the file is of type `MH_KEXT_BUNDLE`, false otherwise
107
107
  def kext?
108
108
  header.filetype == MH_KEXT_BUNDLE
109
109
  end
110
110
 
111
- # @return [Fixnum] the Mach-O's magic number
111
+ # @return [Fixnum] the file's magic number
112
112
  def magic
113
113
  header.magic
114
114
  end
115
115
 
116
- # @return [String] a string representation of the Mach-O's magic number
116
+ # @return [String] a string representation of the file's magic number
117
117
  def magic_string
118
118
  MH_MAGICS[magic]
119
119
  end
@@ -160,6 +160,12 @@ module MachO
160
160
 
161
161
  alias :[] :command
162
162
 
163
+ # All load commands responsible for loading dylibs.
164
+ # @return [Array<MachO::DylibCommand>] an array of DylibCommands
165
+ def dylib_load_commands
166
+ load_commands.select { |lc| DYLIB_LOAD_COMMANDS.include?(lc.type) }
167
+ end
168
+
163
169
  # All segment load commands in the Mach-O.
164
170
  # @return [Array<MachO::SegmentCommand>] if the Mach-O is 32-bit
165
171
  # @return [Array<MachO::SegmentCommand64>] if the Mach-O is 64-bit
@@ -209,7 +215,7 @@ module MachO
209
215
  # All shared libraries linked to the Mach-O.
210
216
  # @return [Array<String>] an array of all shared libraries
211
217
  def linked_dylibs
212
- command(:LC_LOAD_DYLIB).map(&:name).map(&:to_s)
218
+ dylib_load_commands.map(&:name).map(&:to_s)
213
219
  end
214
220
 
215
221
  # Changes the shared library `old_name` to `new_name`
@@ -220,7 +226,7 @@ module MachO
220
226
  # @return [void]
221
227
  # @raise [MachO::DylibUnknownError] if no shared library has the old name
222
228
  def change_install_name(old_name, new_name)
223
- dylib_cmd = command(:LC_LOAD_DYLIB).find { |d| d.name.to_s == old_name }
229
+ dylib_cmd = dylib_load_commands.find { |d| d.name.to_s == old_name }
224
230
  raise DylibUnknownError.new(old_name) if dylib_cmd.nil?
225
231
 
226
232
  set_name_in_dylib(dylib_cmd, old_name, new_name)
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.2.1
4
+ version: 0.2.2
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-13 00:00:00.000000000 Z
11
+ date: 2016-02-02 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