ruby-macho 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2197be0a734893a06de0c2a50c78a125e1e0f7b
4
- data.tar.gz: 6333cb31cc35794f81b35c1e5f5a3e5d8f63d509
3
+ metadata.gz: 70e9e70c2eb3e759c76828051d5bca20c19f081b
4
+ data.tar.gz: 7a626fcc61d6437dec0085c46843cf7a9574f9a1
5
5
  SHA512:
6
- metadata.gz: 2965997a877ab4c4d675f7e51b8b8ddb7fa82dda776e6b2fe5bb10bcfbf27845809723dc072257076a87c351fe03321839d669dd517ec36e0f57453a7831bef5
7
- data.tar.gz: 326050eb144d5e9c415dcf58d10fb3da1c565044fae5bb3d1482fe9f15124c64490f95b2e595748b8f567e69db1cc8e5797cf0917c855150ae034bb9094b456c
6
+ metadata.gz: 6a110e3986ffbe60926702252a173082cd44bbb65824cbdd55648a969a2a54fb2afe9b60c5b761f978b8c2b11948887f052de67daab6d9b261085a199be58d38
7
+ data.tar.gz: 5a7c81e82a7857fe6a2732605f9dc4fb3e139d2989673ad3fbe1632be85072e13432cdbaf0964024cc53cc3c63d29a7864152dea5296b170185e12132e1fafc6
@@ -98,6 +98,15 @@ module MachO
98
98
 
99
99
  alias :change_dylib :change_install_name
100
100
 
101
+ # Extract a Mach-O with the given CPU type from the file.
102
+ # @example
103
+ # file.extract("CPU_TYPE_I386") # => MachO::MachOFile
104
+ # @param cputype [String] the CPU type of the Mach-O being extracted
105
+ # @return [MachO::MachOFile, nil] the extracted Mach-O or nil if no Mach-O has the given CPU type
106
+ def extract(cputype)
107
+ machos.select { |macho| macho.cputype == cputype }.first
108
+ end
109
+
101
110
  # Write all (fat) data to the given filename.
102
111
  # @param filename [String] the file to write to
103
112
  def write(filename)
@@ -338,13 +338,48 @@ module MachO
338
338
  super(offset, cmd, cmdsize)
339
339
  @uuid = uuid.unpack("C16") # re-unpack for the actual UUID array
340
340
  end
341
+
342
+ # @return [String] a string representation of the UUID
343
+ def uuid_string
344
+ hexes = uuid.map { |e| "%02x" % e }
345
+ segs = [
346
+ hexes[0..3].join, hexes[4..5].join, hexes[6..7].join,
347
+ hexes[8..9].join, hexes[10..15].join
348
+ ]
349
+
350
+ segs.join("-")
351
+ end
341
352
  end
342
353
 
343
354
  # A load command indicating that part of this file is to be mapped into
344
355
  # the task's address space. Corresponds to LC_SEGMENT.
345
356
  class SegmentCommand < LoadCommand
346
- attr_reader :segname, :vmaddr, :vmsize, :fileoff, :filesize, :maxprot
347
- attr_reader :initprot, :nsects, :flags
357
+ # @return [String] the name of the segment, including null padding bytes
358
+ attr_reader :segname
359
+
360
+ # @return [Fixnum] the memory address of the segment
361
+ attr_reader :vmaddr
362
+
363
+ # @return [Fixnum] the memory size of the segment
364
+ attr_reader :vmsize
365
+
366
+ # @return [Fixnum] the file offset of the segment
367
+ attr_reader :fileoff
368
+
369
+ # @return [Fixnum] the amount to map from the file
370
+ attr_reader :filesize
371
+
372
+ # @return [Fixnum] the maximum VM protection
373
+ attr_reader :maxprot
374
+
375
+ # @return [Fixnum] the initial VM protection
376
+ attr_reader :initprot
377
+
378
+ # @return [Fixnum] the number of sections in the segment
379
+ attr_reader :nsects
380
+
381
+ # @return [Fixnum] any flags associated with the segment
382
+ attr_reader :flags
348
383
 
349
384
  @format = "VVa16VVVVVVVV"
350
385
  @sizeof = 56
@@ -373,8 +408,32 @@ module MachO
373
408
  # A load command indicating that part of this file is to be mapped into
374
409
  # the task's address space. Corresponds to LC_SEGMENT_64.
375
410
  class SegmentCommand64 < LoadCommand
376
- attr_reader :segname, :vmaddr, :vmsize, :fileoff, :filesize, :maxprot
377
- attr_reader :initprot, :nsects, :flags
411
+ # @return [String] the name of the segment, including null padding bytes
412
+ attr_reader :segname
413
+
414
+ # @return [Fixnum] the memory address of the segment
415
+ attr_reader :vmaddr
416
+
417
+ # @return [Fixnum] the memory size of the segment
418
+ attr_reader :vmsize
419
+
420
+ # @return [Fixnum] the file offset of the segment
421
+ attr_reader :fileoff
422
+
423
+ # @return [Fixnum] the amount to map from the file
424
+ attr_reader :filesize
425
+
426
+ # @return [Fixnum] the maximum VM protection
427
+ attr_reader :maxprot
428
+
429
+ # @return [Fixnum] the initial VM protection
430
+ attr_reader :initprot
431
+
432
+ # @return [Fixnum] the number of sections in the segment
433
+ attr_reader :nsects
434
+
435
+ # @return [Fixnum] any flags associated with the segment
436
+ attr_reader :flags
378
437
 
379
438
  @format = "VVa16QQQQVVVV"
380
439
  @sizeof = 72
@@ -404,7 +463,17 @@ module MachO
404
463
  # on filetype. Corresponds to LC_ID_DYLIB, LC_LOAD_DYLIB, LC_LOAD_WEAK_DYLIB,
405
464
  # and LC_REEXPORT_DYLIB.
406
465
  class DylibCommand < LoadCommand
407
- attr_reader :name, :timestamp, :current_version, :compatibility_version
466
+ # @return [Fixnum] the library's path name (lc_str)
467
+ attr_reader :name
468
+
469
+ # @return [Fixnum] the library's build time stamp
470
+ attr_reader :timestamp
471
+
472
+ # @return [Fixnum] the library's current version number
473
+ attr_reader :current_version
474
+
475
+ # @return [Fixnum] the library's compatibility version number
476
+ attr_reader :compatibility_version
408
477
 
409
478
  @format = "VVVVVV"
410
479
  @sizeof = 24
@@ -424,6 +493,7 @@ module MachO
424
493
  # on filetype. Corresponds to LC_ID_DYLINKER, LC_LOAD_DYLINKER, and
425
494
  # LC_DYLD_ENVIRONMENT.
426
495
  class DylinkerCommand < LoadCommand
496
+ # @return [Fixnum] the dynamic linker's path name (lc_str)
427
497
  attr_reader :name
428
498
 
429
499
  @format = "VVV"
@@ -439,7 +509,14 @@ module MachO
439
509
  # A load command used to indicate dynamic libraries used in prebinding.
440
510
  # Corresponds to LC_PREBOUND_DYLIB.
441
511
  class PreboundDylibCommand < LoadCommand
442
- attr_reader :name, :nmodules, :linked_modules
512
+ # @return [Fixnum] the library's path name (lc_str)
513
+ attr_reader :name
514
+
515
+ # @return [Fixnum] the number of modules in the library
516
+ attr_reader :nmodules
517
+
518
+ # @return [Fixnum] a bit vector of linked modules
519
+ attr_reader :linked_modules
443
520
 
444
521
  @format = "VVVVV"
445
522
  @sizeof = 20
@@ -463,8 +540,29 @@ module MachO
463
540
  # initialization routine and an index into the module table for the module
464
541
  # that defines the routine. Corresponds to LC_ROUTINES.
465
542
  class RoutinesCommand < LoadCommand
466
- attr_reader :init_address, :init_module, :reserved1, :reserved2
467
- attr_reader :reserved3, :reserved4, :reserved5, :reserved6
543
+ # @return [Fixnum] the address of the initialization routine
544
+ attr_reader :init_address
545
+
546
+ # @return [Fixnum] the index into the module table that the init routine is defined in
547
+ attr_reader :init_module
548
+
549
+ # @return [void]
550
+ attr_reader :reserved1
551
+
552
+ # @return [void]
553
+ attr_reader :reserved2
554
+
555
+ # @return [void]
556
+ attr_reader :reserved3
557
+
558
+ # @return [void]
559
+ attr_reader :reserved4
560
+
561
+ # @return [void]
562
+ attr_reader :reserved5
563
+
564
+ # @return [void]
565
+ attr_reader :reserved6
468
566
 
469
567
  @format = "VVVVVVVVVV"
470
568
  @sizeof = 40
@@ -489,8 +587,29 @@ module MachO
489
587
  # initialization routine and an index into the module table for the module
490
588
  # that defines the routine. Corresponds to LC_ROUTINES_64.
491
589
  class RoutinesCommand64 < LoadCommand
492
- attr_reader :init_address, :init_module, :reserved1, :reserved2
493
- attr_reader :reserved3, :reserved4, :reserved5, :reserved6
590
+ # @return [Fixnum] the address of the initialization routine
591
+ attr_reader :init_address
592
+
593
+ # @return [Fixnum] the index into the module table that the init routine is defined in
594
+ attr_reader :init_module
595
+
596
+ # @return [void]
597
+ attr_reader :reserved1
598
+
599
+ # @return [void]
600
+ attr_reader :reserved2
601
+
602
+ # @return [void]
603
+ attr_reader :reserved3
604
+
605
+ # @return [void]
606
+ attr_reader :reserved4
607
+
608
+ # @return [void]
609
+ attr_reader :reserved5
610
+
611
+ # @return [void]
612
+ attr_reader :reserved6
494
613
 
495
614
  @format = "VVQQQQQQQQ"
496
615
  @sizeof = 72
@@ -514,6 +633,7 @@ module MachO
514
633
  # A load command signifying membership of a subframework containing the name
515
634
  # of an umbrella framework. Corresponds to LC_SUB_FRAMEWORK.
516
635
  class SubFrameworkCommand < LoadCommand
636
+ # @return [Fixnum] the umbrella framework name (lc_str)
517
637
  attr_reader :umbrella
518
638
 
519
639
  @format = "VVV"
@@ -529,6 +649,7 @@ module MachO
529
649
  # A load command signifying membership of a subumbrella containing the name
530
650
  # of an umbrella framework. Corresponds to LC_SUB_UMBRELLA.
531
651
  class SubUmbrellaCommand < LoadCommand
652
+ # @return [Fixnum] the subumbrella framework name (lc_str)
532
653
  attr_reader :sub_umbrella
533
654
 
534
655
  @format = "VVV"
@@ -544,6 +665,7 @@ module MachO
544
665
  # A load command signifying a sublibrary of a shared library. Corresponds
545
666
  # to LC_SUB_LIBRARY.
546
667
  class SubLibraryCommand < LoadCommand
668
+ # @return [Fixnum] the sublibrary name (lc_str)
547
669
  attr_reader :sub_library
548
670
 
549
671
  @format = "VVV"
@@ -559,6 +681,7 @@ module MachO
559
681
  # A load command signifying a shared library that is a subframework of
560
682
  # an umbrella framework. Corresponds to LC_SUB_CLIENT.
561
683
  class SubClientCommand < LoadCommand
684
+ # @return [Fixnum] the subclient name (lc_str)
562
685
  attr_reader :sub_client
563
686
 
564
687
  @format = "VVV"
@@ -602,40 +725,58 @@ module MachO
602
725
  # A load command containing symbolic information needed to support data
603
726
  # structures used by the dynamic link editor. Corresponds to LC_DYSYMTAB.
604
727
  class DysymtabCommand < LoadCommand
728
+ # @return [Fixnum] the index to local symbols
605
729
  attr_reader :ilocalsym
606
730
 
731
+ # @return [Fixnum] the number of local symbols
607
732
  attr_reader :nlocalsym
608
733
 
734
+ # @return [Fixnum] the index to externally defined symbols
609
735
  attr_reader :iextdefsym
610
736
 
737
+ # @return [Fixnum] the number of externally defined symbols
611
738
  attr_reader :nextdefsym
612
739
 
740
+ # @return [Fixnum] the index to undefined symbols
613
741
  attr_reader :iundefsym
614
742
 
743
+ # @return [Fixnum] the number of undefined symbols
615
744
  attr_reader :nundefsym
616
745
 
746
+ # @return [Fixnum] the file offset to the table of contents
617
747
  attr_reader :tocoff
618
748
 
749
+ # @return [Fixnum] the number of entries in the table of contents
619
750
  attr_reader :ntoc
620
751
 
752
+ # @return [Fixnum] the file offset to the module table
621
753
  attr_reader :modtaboff
622
754
 
755
+ # @return [Fixnum] the number of entries in the module table
623
756
  attr_reader :nmodtab
624
757
 
758
+ # @return [Fixnum] the file offset to the referenced symbol table
625
759
  attr_reader :extrefsymoff
626
760
 
761
+ # @return [Fixnum] the number of entries in the referenced symbol table
627
762
  attr_reader :nextrefsyms
628
763
 
764
+ # @return [Fixnum] the file offset to the indirect symbol table
629
765
  attr_reader :indirectsymoff
630
766
 
767
+ # @return [Fixnum] the number of entries in the indirect symbol table
631
768
  attr_reader :nindirectsyms
632
769
 
770
+ # @return [Fixnum] the file offset to the external relocation entries
633
771
  attr_reader :extreloff
634
772
 
773
+ # @return [Fixnum] the number of external relocation entries
635
774
  attr_reader :nextrel
636
775
 
776
+ # @return [Fixnum] the file offset to the local relocation entries
637
777
  attr_reader :locreloff
638
778
 
779
+ # @return [Fixnum] the number of local relocation entries
639
780
  attr_reader :nlocrel
640
781
 
641
782
 
@@ -710,6 +851,7 @@ module MachO
710
851
  # be added to the current run path used to find @rpath prefixed dylibs.
711
852
  # Corresponds to LC_RPATH.
712
853
  class RpathCommand < LoadCommand
854
+ # @return [Fixnum] the oath to add to the run path (lc_str)
713
855
  attr_reader :path
714
856
 
715
857
  @format = "VVV"
@@ -813,15 +955,63 @@ module MachO
813
955
  @version = version
814
956
  @sdk = sdk
815
957
  end
958
+
959
+ # A string representation of the binary's minimum OS version.
960
+ # @return [String] a string representing the minimum OS version.
961
+ def version_string
962
+ binary = "%032b" % version
963
+ segs = [
964
+ binary[0..15], binary[16..23], binary[24..31]
965
+ ].map { |s| s.to_i(2) }
966
+
967
+ segs.join(".")
968
+ end
969
+
970
+ # A string representation of the binary's SDK version.
971
+ # @return [String] a string representing the SDK version.
972
+ def sdk_string
973
+ binary = "%032b" % sdk
974
+ segs = [
975
+ binary[0..15], binary[16..23], binary[24..31]
976
+ ].map { |s| s.to_i(2) }
977
+
978
+ segs.join(".")
979
+ end
816
980
  end
817
981
 
818
982
  # A load command containing the file offsets and sizes of the new
819
983
  # compressed form of the information dyld needs to load the image.
820
984
  # Corresponds to LC_DYLD_INFO and LC_DYLD_INFO_ONLY.
821
985
  class DyldInfoCommand < LoadCommand
822
- attr_reader :rebase_off, :rebase_size, :bind_off, :bind_size
823
- attr_reader :weak_bind_off, :weak_bind_size, :lazy_bind_off
824
- attr_reader :lazy_bind_size, :export_off, :export_size
986
+ # @return [Fixnum] the file offset to the rebase information
987
+ attr_reader :rebase_off
988
+
989
+ # @return [Fixnum] the size of the rebase information
990
+ attr_reader :rebase_size
991
+
992
+ # @return [Fixnum] the file offset to the binding information
993
+ attr_reader :bind_off
994
+
995
+ # @return [Fixnum] the size of the binding information
996
+ attr_reader :bind_size
997
+
998
+ # @return [Fixnum] the file offset to the weak binding information
999
+ attr_reader :weak_bind_off
1000
+
1001
+ # @return [Fixnum] the size of the weak binding information
1002
+ attr_reader :weak_bind_size
1003
+
1004
+ # @return [Fixnum] the file offset to the lazy binding information
1005
+ attr_reader :lazy_bind_off
1006
+
1007
+ # @return [Fixnum] the size of the lazy binding information
1008
+ attr_reader :lazy_bind_size
1009
+
1010
+ # @return [Fixnum] the file offset to the export information
1011
+ attr_reader :export_off
1012
+
1013
+ # @return [Fixnum] the size of the export information
1014
+ attr_reader :export_size
825
1015
 
826
1016
  @format = "VVVVVVVVVVVV"
827
1017
  @sizeof = 48
@@ -893,5 +1083,17 @@ module MachO
893
1083
  super(offset, cmd, cmdsize)
894
1084
  @version = version
895
1085
  end
1086
+
1087
+ # A string representation of the sources used to build the binary.
1088
+ # @return [String] a string representation of the version
1089
+ def version_string
1090
+ binary = "%064b" % version
1091
+ segs = [
1092
+ binary[0..23], binary[24..33], binary[34..43], binary[44..53],
1093
+ binary[54..63]
1094
+ ].map { |s| s.to_i(2) }
1095
+
1096
+ segs.join(".")
1097
+ end
896
1098
  end
897
1099
  end
@@ -1,5 +1,6 @@
1
1
  module MachO
2
- # A general purpose pseudo-structure.
2
+ # A general purpose pseudo-structure.
3
+ # @abstract
3
4
  class MachOStructure
4
5
  # Subclasses should fill these in manually.
5
6
  @format = ""
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.1.0
4
+ version: 0.1.1
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-10-23 00:00:00.000000000 Z
11
+ date: 2015-10-24 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