ruby-macho 0.0.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 +7 -0
- data/lib/cstruct.rb +346 -0
- data/lib/int_helpers.rb +17 -0
- data/lib/macho.rb +14 -0
- data/lib/macho/exceptions.rb +54 -0
- data/lib/macho/file.rb +351 -0
- data/lib/macho/headers.rb +122 -0
- data/lib/macho/load_commands.rb +588 -0
- data/lib/macho/sections.rb +114 -0
- data/lib/macho/structure.rb +15 -0
- data/lib/macho/utils.rb +28 -0
- data/lib/otool_helpers.rb +3 -0
- metadata +55 -0
@@ -0,0 +1,114 @@
|
|
1
|
+
module MachO
|
2
|
+
# the flags field of a section has two parts: a type and attributes
|
3
|
+
SECTION_TYPE = 0x000000ff # type mask
|
4
|
+
SECTION_ATTRIBUTES = 0xffffff00 # attributes mask
|
5
|
+
SECTION_ATTRIBUTES_USR = 0xff000000 # user settable attributes mask
|
6
|
+
SECTION_ATTRIBUTES_SYS = 0x00ffff00 # system settable attributes mask
|
7
|
+
|
8
|
+
# section types for the flags field
|
9
|
+
S_REGULAR = 0x0
|
10
|
+
S_ZEROFILL = 0x1
|
11
|
+
S_CSTRING_LITERALS = 0x2
|
12
|
+
S_4BYTE_LITERALS = 0x3
|
13
|
+
S_8BYTE_LITERALS = 0x4
|
14
|
+
S_LITERAL_POINTERS = 0x5
|
15
|
+
S_NON_LAZY_SYMBOL_POINTERS = 0x6
|
16
|
+
S_LAZY_SYMBOL_POINTERS = 0x7
|
17
|
+
S_SYMBOL_STUBS = 0x8
|
18
|
+
S_MOD_INIT_FUNC_POINTERS = 0x9
|
19
|
+
S_MOD_TERM_FUNC_POINTERS = 0xa
|
20
|
+
S_COALESCED = 0xb
|
21
|
+
S_GB_ZEROFILE = 0xc
|
22
|
+
S_INTERPOSING = 0xd
|
23
|
+
S_16BYTE_LITERALS = 0xe
|
24
|
+
S_DTRACE_DOF = 0xf
|
25
|
+
S_LAZY_DYLIB_SYMBOL_POINTERS = 0x10
|
26
|
+
S_THREAD_LOCAL_REGULAR = 0x11
|
27
|
+
S_THREAD_LOCAL_ZEROFILL = 0x12
|
28
|
+
S_THREAD_LOCAL_VARIABLES = 0x13
|
29
|
+
S_THREAD_LOCAL_VARIABLE_POINTERS = 0x14
|
30
|
+
S_THREAD_LOCAL_INIT_FUNCTION_POINTERS = 0x15
|
31
|
+
|
32
|
+
# section attributes for the flags field
|
33
|
+
S_ATTR_PURE_INSTRUCTIONS = 0x80000000
|
34
|
+
S_ATTR_NO_TOC = 0x40000000
|
35
|
+
S_ATTR_STRIP_STATIC_SYMS = 0x20000000
|
36
|
+
S_ATTR_NO_DEAD_STRIP = 0x10000000
|
37
|
+
S_ATTR_LIVE_SUPPORT = 0x08000000
|
38
|
+
S_ATTR_SELF_MODIFYING_CODE = 0x04000000
|
39
|
+
S_ATTR_DEBUG = 0x02000000
|
40
|
+
S_ATTR_SOME_INSTRUCTIONS = 0x00000400
|
41
|
+
S_ATTR_EXT_RELOC = 0x00000200
|
42
|
+
S_ATTR_LOC_RELOC = 0x00000100
|
43
|
+
|
44
|
+
class Section < MachOStructure
|
45
|
+
attr_reader :sectname, :segname, :addr, :size, :offset, :align, :reloff
|
46
|
+
attr_reader :nreloc, :flags, :reserved1, :reserved2
|
47
|
+
|
48
|
+
@format = "a16a16VVVVVVVVV"
|
49
|
+
@sizeof = 68
|
50
|
+
|
51
|
+
def initialize(sectname, segname, addr, size, offset, align, reloff,
|
52
|
+
nreloc, flags, reserved1, reserved2)
|
53
|
+
@sectname = sectname
|
54
|
+
@segname = segname
|
55
|
+
@addr = addr
|
56
|
+
@size = size
|
57
|
+
@offset = offset
|
58
|
+
@align = align
|
59
|
+
@reloff = reloff
|
60
|
+
@nreloc = nreloc
|
61
|
+
@flags = flags
|
62
|
+
@reserved1 = reserved1
|
63
|
+
@reserved2 = reserved2
|
64
|
+
end
|
65
|
+
|
66
|
+
def section_name
|
67
|
+
@sectname.delete("\x00")
|
68
|
+
end
|
69
|
+
|
70
|
+
def segment_name
|
71
|
+
@segname.delete("\x00")
|
72
|
+
end
|
73
|
+
|
74
|
+
def flag?(flag)
|
75
|
+
flags & flag == flag
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class Section64 < MachOStructure
|
80
|
+
attr_reader :sectname, :segname, :addr, :size, :offset, :align, :reloff
|
81
|
+
attr_reader :nreloc, :flags, :reserved1, :reserved2, :reserved3
|
82
|
+
|
83
|
+
@format = "a16a16QQVVVVVVVV"
|
84
|
+
@sizeof = 80
|
85
|
+
|
86
|
+
def initialize(sectname, segname, addr, size, offset, align, reloff,
|
87
|
+
nreloc, flags, reserved1, reserved2, reserved3)
|
88
|
+
@sectname = sectname
|
89
|
+
@segname = segname
|
90
|
+
@addr = addr
|
91
|
+
@size = size
|
92
|
+
@offset = offset
|
93
|
+
@align = align
|
94
|
+
@reloff = reloff
|
95
|
+
@nreloc = nreloc
|
96
|
+
@flags = flags
|
97
|
+
@reserved1 = reserved1
|
98
|
+
@reserved2 = reserved2
|
99
|
+
@reserved3 = reserved3
|
100
|
+
end
|
101
|
+
|
102
|
+
def section_name
|
103
|
+
@sectname.delete("\x00")
|
104
|
+
end
|
105
|
+
|
106
|
+
def segment_name
|
107
|
+
@segname.delete("\x00")
|
108
|
+
end
|
109
|
+
|
110
|
+
def flag?(flag)
|
111
|
+
flags & flag == flag
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
data/lib/macho/utils.rb
ADDED
@@ -0,0 +1,28 @@
|
|
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
|
10
|
+
|
11
|
+
def self.magic?(num)
|
12
|
+
num == FAT_MAGIC || num == FAT_CIGAM || num == MH_MAGIC ||
|
13
|
+
num == MH_CIGAM || num == MH_MAGIC_64 || num == MH_CIGAM_64
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.fat_magic?(num)
|
17
|
+
num == FAT_MAGIC || num == FAT_CIGAM
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.magic32?(num)
|
21
|
+
num == MH_MAGIC || num == MH_CIGAM
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.magic64?(num)
|
25
|
+
num == MH_MAGIC_64 || num == MH_CIGAM_64
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-macho
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- William Woodruff
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-29 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A library for viewing and manipulating Mach-O files in Ruby.
|
14
|
+
email: william@tuffbizz.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/cstruct.rb
|
20
|
+
- lib/int_helpers.rb
|
21
|
+
- lib/macho.rb
|
22
|
+
- lib/macho/exceptions.rb
|
23
|
+
- lib/macho/file.rb
|
24
|
+
- lib/macho/headers.rb
|
25
|
+
- lib/macho/load_commands.rb
|
26
|
+
- lib/macho/sections.rb
|
27
|
+
- lib/macho/structure.rb
|
28
|
+
- lib/macho/utils.rb
|
29
|
+
- lib/otool_helpers.rb
|
30
|
+
homepage: https://github.com/woodruffw/ruby-macho
|
31
|
+
licenses:
|
32
|
+
- MIT
|
33
|
+
metadata: {}
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 2.4.5
|
51
|
+
signing_key:
|
52
|
+
specification_version: 4
|
53
|
+
summary: ruby-macho - Mach-O file analyzer.
|
54
|
+
test_files: []
|
55
|
+
has_rdoc:
|