ruby-macho 0.0.5 → 0.0.7

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: e6bf6b45bcf73b710246fe124075f4ca77c73070
4
- data.tar.gz: 5713089fd72d423c6a25b90839e29a317072169b
3
+ metadata.gz: 6903e361104a718205c145e401ee484e38289217
4
+ data.tar.gz: 1bcea8a215a1e19b2cde870818206152582162be
5
5
  SHA512:
6
- metadata.gz: a2aaa85277768159ee35ff7e44817afd1bad136884a2ced66dd471a39657e3827d4adbb7987fbca38c36aae25ef2ec3f8bfa5b9296d06013443f8f2e77db85fc
7
- data.tar.gz: 20d89669d43b4fa964f878ade17d5130c58743a9bd742978e36cb485a32f4575d1d81957eb68719647340a9fc83120da611570e70da54a27ede7a4fe5adb02a2
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
- # nothing to see here.
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
@@ -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
@@ -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 !Utils.magic?(magic)
70
+ if !MachO.magic?(magic)
71
71
  raise MagicError.new(magic)
72
72
  end
73
73
 
74
- if !Utils.fat_magic?(magic)
74
+ if !MachO.fat_magic?(magic)
75
75
  raise MachOBinaryError.new
76
76
  end
77
77
 
@@ -30,11 +30,11 @@ module MachO
30
30
  end
31
31
 
32
32
  def magic32?
33
- Utils.magic32?(header[:magic])
33
+ MachO.magic32?(header[:magic])
34
34
  end
35
35
 
36
36
  def magic64?
37
- Utils.magic64?(header[:magic])
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 = Utils.round(new_id.size, cmd_round) - new_id.size
148
- old_pad = Utils.round(old_id.size, cmd_round) - old_id.size
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 Utils.magic32?(magic)
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 !Utils.magic?(magic)
286
+ if !MachO.magic?(magic)
282
287
  raise MagicError.new(magic)
283
288
  end
284
289
 
285
- if Utils.fat_magic?(magic)
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
- module Utils
3
- # http://www.opensource.apple.com/source/cctools/cctools-870/libstuff/rnd.c
4
- def self.round(value, round)
5
- round -= 1
6
- value += round
7
- value &= ~round
8
- value
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
- def self.magic?(num)
12
- MH_MAGICS.has_key?(num)
13
- end
10
+ def self.magic?(num)
11
+ MH_MAGICS.has_key?(num)
12
+ end
14
13
 
15
- def self.fat_magic?(num)
16
- num == FAT_MAGIC || num == FAT_CIGAM
17
- end
14
+ def self.fat_magic?(num)
15
+ num == FAT_MAGIC || num == FAT_CIGAM
16
+ end
18
17
 
19
- def self.magic32?(num)
20
- num == MH_MAGIC || num == MH_CIGAM
21
- end
18
+ def self.magic32?(num)
19
+ num == MH_MAGIC || num == MH_CIGAM
20
+ end
22
21
 
23
- def self.magic64?(num)
24
- num == MH_MAGIC_64 || num == MH_CIGAM_64
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.5
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-07-29 00:00:00.000000000 Z
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.