elf-mithril 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+ gemspec
3
+ gem 'bindata', github: "jbangert/bindata"
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Julian Bangert
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Mithril
2
+
3
+ In Soviet Russia, Mithril forges ELF.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'elf-mithril'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install elf-mithril
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require 'mithril'
4
+ module Elf
5
+ def self.newfile
6
+ ElfFile.new.tap {|x|
7
+ x.filetype = ElfFlags::Type::ET_EXEC
8
+ x.machine = ElfFlags::Machine::EM_X86_64
9
+ x.version = ElfFlags::Version::EV_CURRENT
10
+ x.flags = 0
11
+ x.bits = 64
12
+ x.endian = :little
13
+ x.interp = "/lib64/ld-linux-x86-64.so.2"
14
+ }
15
+ end
16
+ def self.linkfiles(outfile, infiles)
17
+ progbits = {}
18
+ symbols = {}
19
+ sect_map = {}
20
+ sect_offsets = {}
21
+ symbols = {}
22
+ infiles.each {|infile|
23
+ #link actual data
24
+ (infile.progbits + infile.nobits).each {|inbit|
25
+ outbit = (progbits[inbit.name] ||= Elf::ProgBits.new(inbit.name))
26
+ outbit.flags |= inbit.flags
27
+ outbit.align = [inbit.align, outbit.align].max
28
+ outbit.sect_type = inbit.sect_type
29
+ sect_offsets[inbit] = outbit.data.tell
30
+ sect_map[inbit] = outbit
31
+ outbit.data.write inbit.data.read #TODO: Handle align
32
+ }
33
+ # Link together symbol table. Note we do not support versioning in the poc
34
+ infile.symbols.each {|symbol|
35
+ next if symbol.name.empty?
36
+ next unless [Elf::STT::STT_OBJECT, Elf::STT::STT_FUNC, Elf::STT::STT_COMMON, Elf::STT::STT_NOTYPE].include? symbol.type
37
+
38
+ if (symbols.include? symbol.name)
39
+ next if symbol.weak? or symbol.undefined?
40
+ raise ArgumentError.new "Duplicate definition of symbol #{symbol.name}" unless symbols[symbol.name].weak? or symbols[symbol.name].undefined?
41
+ end
42
+ symbols[symbol.name] = symbol.clone.tap{|outsym|
43
+ unless outsym.undefined?
44
+ outsym.sectoffset += sect_offsets[outsym.section]
45
+ outsym.section = sect_map[outsym.section]
46
+ end
47
+ }
48
+ }
49
+ }
50
+ #TODO: mark per-object section symbols
51
+ progbits.values.each {|progbit| outfile.progbits << progbit }
52
+ symbols.values.each {|sym| outfile.symbols << sym}
53
+
54
+ infiles.map(&:relocations).flatten.each {|rela|
55
+ outfile.relocations << rela.clone.tap{|x|
56
+ x.offset += sect_offsets[x.section]
57
+ x.section = sect_map[x.section]
58
+ name = x.symbol.name
59
+ x.symbol = symbols[name]
60
+ x.is_dynamic = true
61
+ raise ArgumentError.new "Undefined symbol #{name}" if(x.symbol.nil?)
62
+ }
63
+ } #TODO: Produce dynsym
64
+ raise "Undefined entry point _start " unless symbols.include? "_start"
65
+ entry = symbols["_start"]
66
+ entry.section.addr = 0x40000
67
+ outfile.entry = entry.sectoffset + entry.section.addr
68
+
69
+ outfile
70
+
71
+ end
72
+ end
73
+ file = Elf::linkfiles(Elf::newfile, ARGV[1..-1].map{|x| Elf::Parser::from_file(x)})
74
+
75
+ Elf::Writer.to_file(ARGV[0], file)
76
+ `chmod +x '#{ARGV[0]}'`
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require 'mithril'
4
+
5
+ nginx_path = "/home/julian/important/12W/elf-policy/webserver-samples/nginx-install/sbin/"
6
+ $parse = Elf::Parser.from_file (ARGV[0] || nginx_path + "nginx-ori")
7
+ #binding.pry
8
+ outfile= ARGV[1] || nginx_path+"nginx"
9
+ Elf::Writer::Writer.to_file(outfile ,$parse)
10
+ `chmod +x #{outfile}`
11
+
12
+ #pp parse # .instance_variables
13
+ ##TODO: Do enums as custom records.
14
+
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ require 'mithril'
3
+ require 'mithril/inject_symbols'
4
+
5
+ Elf::rewrite(ARGV[0]){|file|
6
+ Elf::Policy::inject_symbols(file)
7
+ # if(file.symbols.include? "_dl_runtime_resolve")
8
+ # print "detected ld.so, making _dl_runtime_resolve public"
9
+ # file.symbols["_dl_runtime_resolve"].is_dynamic = true
10
+ # end
11
+ }
12
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
@@ -0,0 +1,6 @@
1
+ require "mithril/version"
2
+ require "mithril/elf"
3
+ require "mithril/parser"
4
+ require "mithril/writer"
5
+ require "mithril/policy"
6
+ require "mithril/inject_symbols"
@@ -0,0 +1,220 @@
1
+ # require 'bundler'
2
+ require 'andand'
3
+ require_relative 'elf_enums'
4
+ require_relative 'elf_structs'
5
+ require 'fileutils'
6
+
7
+ require 'pp'
8
+ require 'set'
9
+ require 'segment_tree'
10
+ require 'rbtree'
11
+ #TODO: freeze some things after parse?
12
+ module Elf
13
+ DT = ElfFlags::DynamicType
14
+ SHT = ElfFlags::SectionType
15
+ SHF = ElfFlags::SectionFlags
16
+ STB = ElfFlags::SymbolBinding
17
+ SHN = ElfFlags::SpecialSection
18
+ STT= ElfFlags::SymbolType
19
+ STV= ElfFlags::SymbolVisibility
20
+ ET = ElfFlags::Type
21
+ PT = ElfFlags::PhdrType
22
+ PF = ElfFlags::PhdrFlags
23
+ R = ElfFlags::Relocation
24
+ NOTE_ALIGN = 4
25
+ NOTE_FLAGS = SHF::SHF_ALLOC
26
+ NOTE_ENTSIZE =0
27
+ def self.rewrite(filename,&block)
28
+ FileUtils::cp(filename,filename+".bak")
29
+ file = Elf::Parser::from_file(filename)
30
+ block.call(file)
31
+ Elf::Writer::Writer.to_file(filename,file)
32
+ end
33
+ class Dynamic
34
+ attr_accessor :bind_now, :symbolic, :needed, :init, :fini, :pltgot, :debug_val, :soname
35
+ attr_accessor :extra_dynamic, :soname, :init_array, :fini_array,:rpath
36
+ attr_accessor :gnu_version_basename #Name of the base GNU version (:global)
37
+
38
+ #TODO: I feel this should always be the SONAME, warn otherwise
39
+ attr_accessor :flags, :flags1
40
+ def initialize
41
+ @needed = []
42
+ end
43
+ end
44
+ class ProgBits
45
+ attr_accessor :data,:name, :addr, :flags, :align, :entsize
46
+ attr_accessor :phdr, :phdr_flags # Makes a PHDR for this section
47
+ attr_accessor :sect_type
48
+ def initialize(name,shdr = nil,data = "")
49
+ @data = StringIO.new(data)
50
+ @name = name
51
+ if shdr.nil?
52
+ @addr = nil
53
+ @flags = 0
54
+ @align = 0
55
+ @entsize = 0
56
+ @sect_type = 0
57
+ else
58
+ @addr = shdr.vaddr
59
+ @flags = shdr.flags
60
+ expect_value "PROGBITS link", shdr.link, 0
61
+ expect_value "PROGBITS info", shdr.info, 0
62
+ @align = shdr.addralign
63
+ @entsize = shdr.entsize # Expect 0 for now?
64
+ @sect_type = shdr.type.to_i
65
+ # expect_value "PROGBITS entsize", @entsize,0
66
+ expect_value "Progbits must be full present", @data.size, shdr.siz
67
+ end
68
+
69
+ end
70
+ def size
71
+ @data.size
72
+ end
73
+ end
74
+ class NoBits
75
+ attr_accessor :name, :addr, :flags, :align, :phdr, :phdr_flags, :size
76
+ def initialize(name,shdr)
77
+ @name = name
78
+ @addr = shdr.vaddr
79
+ @flags = shdr.flags
80
+ expect_value "NOBITS link", shdr.link, 0
81
+ expect_value "NOBITS info", shdr.info, 0
82
+ @align = shdr.addralign
83
+ @entsize = shdr.entsize # Expect 0 for now?
84
+ @size = shdr.siz
85
+ # expect_value "PROGBITS entsize", @entsize,0
86
+ end
87
+ def data
88
+ StringIO.new().tap{|x|
89
+ BinData::Array.new(type: :uint8le,initial_length: @size).write x
90
+ }
91
+ end
92
+ def sect_type
93
+ SHT::SHT_NOBITS
94
+ end
95
+ def entsize
96
+ 1
97
+ end
98
+ # def size
99
+ # @size
100
+ # end
101
+ end
102
+ class GnuVersion
103
+ attr_accessor :file,:version,:flags, :needed
104
+ attr_accessor :parents
105
+ def initialize(file,version,flags,needed)
106
+ @file, @version,@flags,@needed = file,version,flags,needed
107
+ @parents = []
108
+ end
109
+ end
110
+
111
+ class Symbol #All values here are section offsets
112
+ attr_accessor :name, :section ,:type, :sectoffset, :bind, :size,:is_dynamic
113
+ attr_accessor :gnu_version, :hidden
114
+ attr_accessor :visibility # One of STV
115
+ attr_accessor :semantics # Either one of the SHNs or a nil for normal symbols
116
+ def dynamic?
117
+ is_dynamic
118
+ end
119
+ def undefined?
120
+ semantics == SHN::SHN_UNDEF
121
+ end
122
+ def weak?
123
+ bind == STB::STB_WEAK
124
+ end
125
+ def initialize(name,section,type,sectoffset, bind,size)
126
+ @name,@section, @type, @sectoffset, @bind, @size = name.to_s,section,type,sectoffset, bind,size
127
+ @is_dynamic = false
128
+ @gnu_version = :global
129
+ @visibility = ElfFlags::SymbolVisibility::STV_DEFAULT
130
+ @hidden = false
131
+ end
132
+ end
133
+ class SymbolTable
134
+ #TODO: hook symbol.version=
135
+ include Enumerable
136
+ def initialize
137
+ @all_symbols = []
138
+ @named_symbols = {}
139
+ @versioned_symbols = {}
140
+ end
141
+ def each(&block)
142
+ @all_symbols.each(&block)
143
+ end
144
+ def <<(symbol)
145
+ @all_symbols << symbol
146
+ unless symbol.hidden
147
+ name = symbol.name
148
+ version = symbol.gnu_version
149
+ @versioned_symbols[version] ||= {}
150
+ if(@versioned_symbols[version].include? name)
151
+ #TODO: emit some form of warning!
152
+ #raise RuntimeError.new "Symbol #{name} version #{version} not unique"
153
+ else
154
+ @versioned_symbols[version][name] = symbol
155
+ end
156
+ @named_symbols[name] ||= []
157
+ @named_symbols[name] << symbol
158
+ end
159
+ end
160
+
161
+ def lookup(name,version=nil)
162
+ if(version.nil?)
163
+ @named_symbols[name].andand {|x|
164
+ if(x.length > 1)
165
+ x = x.select{|i| i.gnu_version != :local and i.bind != STB::STB_LOCAL}
166
+ if(x.length > 1)
167
+ raise RuntimeError.new("Multiple definitions of symbol #{name}")
168
+ end
169
+ end
170
+ x.first
171
+ }
172
+ else
173
+ @versioned_symbols[version].andand{|x| x[name]}
174
+ end
175
+ end
176
+ def lookup_all(name)
177
+ @named_symbols[name]
178
+ end
179
+ def include?(name,version=nil)
180
+ if version.nil?
181
+ @named_symbols.include? name
182
+ else
183
+ @versioned_symbols[version].include? name
184
+ end
185
+ end
186
+ def [](name)
187
+ lookup(name)
188
+ end
189
+ end
190
+ class Relocation
191
+ attr_accessor :section, :offset, :type, :symbol, :addend
192
+ attr_accessor :is_dynamic #false for static, true otherwise.
193
+ attr_accessor :is_lazy # Is in PLT
194
+ def initialize
195
+ @is_dynamic = false
196
+ @is_lazy = false
197
+ end
198
+ end
199
+ class TLS
200
+ attr_accessor :tbss,:tdata
201
+ end
202
+ class ElfFile
203
+ attr_accessor :filetype, :machine, :entry, :flags, :version
204
+ attr_accessor :progbits, :nobits, :dynamic, :relocations
205
+ attr_accessor :gnu_tls
206
+ attr_accessor :symbols#, :relocated_symbols
207
+ attr_accessor :notes, :bits, :endian, :interp, :extra_phdrs
208
+ attr_accessor :pinned_sections #Some binaries rely on specific address layouts (esp. ld.so)
209
+ def initialize
210
+ @dynamic = Dynamic.new
211
+ @relocations = []
212
+ @progbits = []
213
+ @nobits = []
214
+ @pinned_sections = {}
215
+ @notes = []
216
+ @symbols = SymbolTable.new
217
+ end
218
+ end
219
+ end
220
+
@@ -0,0 +1,581 @@
1
+ #Inspired + partially derived from http://golang.org/src/cmd/ld/elf.h?m=text
2
+ =begin
3
+ /*
4
+ * Derived from:
5
+ * $FreeBSD: src/sys/sys/elf32.h,v 1.8.14.1 2005/12/30 22:13:58 marcel Exp $
6
+ * $FreeBSD: src/sys/sys/elf64.h,v 1.10.14.1 2005/12/30 22:13:58 marcel Exp $
7
+ * $FreeBSD: src/sys/sys/elf_common.h,v 1.15.8.1 2005/12/30 22:13:58 marcel Exp $
8
+ * $FreeBSD: src/sys/alpha/include/elf.h,v 1.14 2003/09/25 01:10:22 peter Exp $
9
+ * $FreeBSD: src/sys/amd64/include/elf.h,v 1.18 2004/08/03 08:21:48 dfr Exp $
10
+ * $FreeBSD: src/sys/arm/include/elf.h,v 1.5.2.1 2006/06/30 21:42:52 cognet Exp $
11
+ * $FreeBSD: src/sys/i386/include/elf.h,v 1.16 2004/08/02 19:12:17 dfr Exp $
12
+ * $FreeBSD: src/sys/powerpc/include/elf.h,v 1.7 2004/11/02 09:47:01 ssouhlal Exp $
13
+ * $FreeBSD: src/sys/sparc64/include/elf.h,v 1.12 2003/09/25 01:10:26 peter Exp $
14
+ *
15
+ * Copyright (c) 1996-1998 John D. Polstra. All rights reserved.
16
+ * Copyright (c) 2001 David E. O'Brien
17
+ * Portions Copyright 2009 The Go Authors. All rights reserved.
18
+ *
19
+ * Redistribution and use in source and binary forms, with or without
20
+ * modification, are permitted provided that the following conditions
21
+ * are met:
22
+ * 1. Redistributions of source code must retain the above copyright
23
+ * notice, this list of conditions and the following disclaimer.
24
+ * 2. Redistributions in binary form must reproduce the above copyright
25
+ * notice, this list of conditions and the following disclaimer in the
26
+ * documentation and/or other materials provided with the distribution.
27
+ *
28
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
29
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
32
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38
+ * SUCH DAMAGE.
39
+ *
40
+ */
41
+ =end
42
+ module ElfFlags
43
+ class Enum
44
+
45
+ end
46
+ class Version < Enum # EV_
47
+ EV_NONE = 0
48
+ EV_CURRENT = 1
49
+ end
50
+ class IdentClass < Enum # ELFCLASS
51
+ ELFCLASSNONE = 0
52
+ ELFCLASS32 = 1
53
+ ELFCLASS64 = 2
54
+ end
55
+ class IdentData < Enum # ELFDATA
56
+ ELFDATANONE = 0
57
+ ELFDATA2LSB = 1
58
+ ELFDATA2MSB = 2
59
+ end
60
+ class OsAbi < Enum # ELFOSABI
61
+ ELFOSABI_NONE = 0
62
+ ELFOSABI_HPUX = 1
63
+ ELFOSABI_NETBSD = 2
64
+ ELFOSABI_LINUX = 3
65
+ ELFOSABI_HURD = 4
66
+ ELFOSABI_86OPEN = 5
67
+ ELFOSABI_SOLARIS = 6
68
+ ELFOSABI_AIX = 7
69
+ ELFOSABI_IRIX = 8
70
+ ELFOSABI_FREEBSD = 9
71
+ ELFOSABI_TRU64 = 10
72
+ ELFOSABI_MODESTO = 11
73
+ ELFOSABI_OPENBSD = 12
74
+ ELFOSABI_OPENVMS = 13
75
+ ELFOSABI_NSK = 14
76
+ ELFOSABI_ARM = 97
77
+ ELFOSABI_STANDALONE = 255
78
+ ELFOSABI_SYSV = ELFOSABI_NONE
79
+ ELFOSABI_MONTEREY = ELFOSABI_AIX
80
+ end
81
+ class Type < Enum # ET_
82
+ ET_NONE = 0
83
+ ET_REL = 1
84
+ ET_EXEC = 2
85
+ ET_DYN = 3
86
+ ET_CORE = 4
87
+ ET_LOOS = 0xfe00
88
+ ET_HIOS = 0xfeff
89
+ ET_LOPROC = 0xff00
90
+ ET_HIPROC = 0xffff
91
+ end
92
+ class Machine < Enum # EM_
93
+ EM_NONE = 0
94
+ EM_M32 = 1
95
+ EM_SPARC = 2
96
+ EM_386 = 3
97
+ EM_68K = 4
98
+ EM_88K = 5
99
+ EM_860 = 7
100
+ EM_MIPS = 8
101
+ EM_S370 = 9
102
+ EM_MIPS_RS3_LE = 10
103
+ EM_PARISC = 15
104
+ EM_VPP500 = 17
105
+ EM_SPARC32PLUS = 18
106
+ EM_960 = 19
107
+ EM_PPC = 20
108
+ EM_PPC64 = 21
109
+ EM_S390 = 22
110
+ EM_V800 = 36
111
+ EM_FR20 = 37
112
+ EM_RH32 = 38
113
+ EM_RCE = 39
114
+ EM_ARM = 40
115
+ EM_SH = 42
116
+ EM_SPARCV9 = 43
117
+ EM_TRICORE = 44
118
+ EM_ARC = 45
119
+ EM_H8_300 = 46
120
+ EM_H8_300H = 47
121
+ EM_H8S = 48
122
+ EM_H8_500 = 49
123
+ EM_IA_64 = 50
124
+ EM_MIPS_X = 51
125
+ EM_COLDFIRE = 52
126
+ EM_68HC12 = 53
127
+ EM_MMA = 54
128
+ EM_PCP = 55
129
+ EM_NCPU = 56
130
+ EM_NDR1 = 57
131
+ EM_STARCORE = 58
132
+ EM_ME16 = 59
133
+ EM_ST100 = 60
134
+ EM_TINYJ = 61
135
+ EM_X86_64 = 62
136
+ EM_486 = 6
137
+ EM_MIPS_RS4_BE = 10
138
+ EM_ALPHA_STD = 41
139
+ EM_ALPHA = 0x9026
140
+ end
141
+ class SpecialSection < Enum # SHN_
142
+ SHN_UNDEF = 0
143
+ SHN_LORESERVE = 0xff00
144
+ SHN_LOPROC = 0xff00
145
+ SHN_HIPROC = 0xff1f
146
+ SHN_LOOS = 0xff20
147
+ SHN_HIOS = 0xff3f
148
+ SHN_ABS = 0xfff1
149
+ SHN_COMMON = 0xfff2
150
+ SHN_XINDEX = 0xffff
151
+ SHN_HIRESERVE = 0xffff
152
+ SHT_SYMTAB_SHNDX = 18
153
+ end
154
+ class SectionType < Enum # SHT_
155
+ SHT_NULL = 0
156
+ SHT_PROGBITS = 1
157
+ SHT_SYMTAB = 2
158
+ SHT_STRTAB = 3
159
+ SHT_RELA = 4
160
+ SHT_HASH = 5
161
+ SHT_DYNAMIC = 6
162
+ SHT_NOTE = 7
163
+ SHT_NOBITS = 8
164
+ SHT_REL = 9
165
+ SHT_SHLIB = 10
166
+ SHT_DYNSYM = 11
167
+ SHT_INIT_ARRAY = 14
168
+ SHT_FINI_ARRAY = 15
169
+ SHT_PREINIT_ARRAY = 16
170
+ SHT_GROUP = 17
171
+ SHT_SYMTAB_SHNDX = 18
172
+ SHT_LOOS = 0x60000000
173
+ SHT_HIOS = 0x6fffffff
174
+ SHT_GNU_VERDEF = 0x6ffffffd
175
+ SHT_GNU_VERNEED = 0x6ffffffe
176
+ SHT_GNU_VERSYM = 0x6fffffff
177
+ SHT_LOPROC = 0x70000000
178
+ SHT_HIPROC = 0x7fffffff
179
+ SHT_LOUSER = 0x80000000
180
+ SHT_HIUSER = 0xffffffff
181
+ end
182
+ class SectionFlags < Enum # SHF_
183
+ SHF_WRITE = 0x1
184
+ SHF_ALLOC = 0x2
185
+ SHF_EXECINSTR = 0x4
186
+ SHF_MERGE = 0x10
187
+ SHF_STRINGS = 0x20
188
+ SHF_INFO_LINK = 0x40
189
+ SHF_LINK_ORDER = 0x80
190
+ SHF_OS_NONCONFORMING = 0x100
191
+ SHF_GROUP = 0x200
192
+ SHF_TLS = 0x400
193
+ SHF_MASKOS = 0x0ff00000
194
+ SHF_MASKPROC = 0xf0000000
195
+ end
196
+ class PhdrType < Enum # PT_
197
+ PT_NULL = 0
198
+ PT_LOAD = 1
199
+ PT_DYNAMIC = 2
200
+ PT_INTERP = 3
201
+ PT_NOTE = 4
202
+ PT_SHLIB = 5
203
+ PT_PHDR = 6
204
+ PT_TLS = 7
205
+ PT_LOOS = 0x60000000
206
+ PT_HIOS = 0x6fffffff
207
+ PT_LOPROC = 0x70000000
208
+ PT_HIPROC = 0x7fffffff
209
+ PT_GNU_STACK = 0x6474e551
210
+ PT_ELFBAC = 42 # Nothing to see here ;) - ELFBAC, see Dartmouth
211
+ # college TR
212
+
213
+ end
214
+ class PhdrFlags < Enum # PF_
215
+ PF_X = 0x1
216
+ PF_W = 0x2
217
+ PF_R = 0x4
218
+ PF_MASKOS = 0x0ff00000
219
+ PF_MASKPROC = 0xf0000000
220
+ end
221
+ class DynamicType < Enum # DT_
222
+ DT_NULL = 0
223
+ DT_NEEDED = 1
224
+ DT_PLTRELSZ = 2
225
+ DT_PLTGOT = 3
226
+ DT_HASH = 4
227
+ DT_STRTAB = 5
228
+ DT_SYMTAB = 6
229
+ DT_RELA = 7
230
+ DT_RELASZ = 8
231
+ DT_RELAENT = 9
232
+ DT_STRSZ = 10
233
+ DT_SYMENT = 11
234
+ DT_INIT = 12
235
+ DT_FINI = 13
236
+ DT_SONAME = 14
237
+ DT_RPATH = 15
238
+ DT_SYMBOLIC = 16
239
+ DT_REL = 17
240
+ DT_RELSZ = 18
241
+ DT_RELENT = 19
242
+ DT_PLTREL = 20
243
+ DT_DEBUG = 21
244
+ DT_TEXTREL = 22
245
+ DT_JMPREL = 23
246
+ DT_BIND_NOW = 24
247
+ DT_INIT_ARRAY = 25
248
+ DT_FINI_ARRAY = 26
249
+ DT_INIT_ARRAYSZ = 27
250
+ DT_FINI_ARRAYSZ = 28
251
+ DT_RUNPATH = 29
252
+ DT_FLAGS = 30
253
+ DT_ENCODING = 32
254
+ DT_PREINIT_ARRAY = 32
255
+ DT_PREINIT_ARRAYSZ = 33
256
+ DT_LOOS = 0x6000000d
257
+ DT_HIOS = 0x6ffff000
258
+ DT_LOPROC = 0x70000000
259
+ DT_HIPROC = 0x7fffffff
260
+
261
+ DT_VERNEED = 0x6ffffffe
262
+ DT_VERNEEDNUM = 0x6fffffff
263
+ DT_VERSYM = 0x6ffffff0
264
+ DT_VERDEF = 0x6ffffffc
265
+ DT_VERDEFNUM = 0x6ffffffd
266
+ DT_GNU_HASH = 0x6ffffef5
267
+ DT_RELACOUNT = 0x6ffffff9
268
+ DT_RELCOUNT = 0x6ffffffa
269
+ DT_FLAGS_1 = 0x6ffffffb
270
+ end
271
+ class GnuVerFlags < Enum
272
+ VERFLAG_BASE = 0x1
273
+ VERFLAG_WEAK = 0x2
274
+ end
275
+ class DynamicFlags < Enum # DF_
276
+ DF_ORIGIN = 0x0001
277
+ DF_SYMBOLIC = 0x0002
278
+ DF_TEXTREL = 0x0004
279
+ DF_BIND_NOW = 0x0008
280
+ DF_STATIC_TLS = 0x0010
281
+ end
282
+ class CoreNType < Enum # NT_
283
+ NT_PRSTATUS = 1
284
+ NT_FPREGSET = 2
285
+ NT_PRPSINFO = 3
286
+ end
287
+ class SymbolBinding < Enum # STB_
288
+ STB_LOCAL = 0
289
+ STB_GLOBAL = 1
290
+ STB_WEAK = 2
291
+ STB_LOOS = 10
292
+ STB_HIOS = 12
293
+ STB_LOPROC = 13
294
+ STB_HIPROC = 15
295
+ end
296
+ class SymbolType < Enum # STT_
297
+ STT_NOTYPE = 0
298
+ STT_OBJECT = 1
299
+ STT_FUNC = 2
300
+ STT_SECTION = 3
301
+ STT_FILE = 4
302
+ STT_COMMON = 5
303
+ STT_TLS = 6
304
+ STT_LOOS = 10
305
+ STT_HIOS = 12
306
+ STT_LOPROC = 13
307
+ STT_HIPROC = 15
308
+ end
309
+ class SymbolVisibility < Enum # STV_
310
+ STV_DEFAULT = 0x0
311
+ STV_INTERNAL = 0x1
312
+ STV_HIDDEN = 0x2
313
+ STV_PROTECTED = 0x3
314
+ end
315
+ class SymbolName < Enum # STN_
316
+ STN_UNDEF = 0
317
+ end
318
+ class ElfPData < Enum
319
+ ELFP_RW_READ = 1
320
+ ELFP_RW_WRITE = 2
321
+ ELFP_RW_EXEC = 4
322
+ ELFP_RW_SIZE = 8
323
+ end
324
+ class Relocation < Enum # R_
325
+ R_X86_64_NONE = 0
326
+ R_X86_64_64 = 1
327
+ R_X86_64_PC32 = 2
328
+ R_X86_64_GOT32 = 3
329
+ R_X86_64_PLT32 = 4
330
+ R_X86_64_COPY = 5
331
+ R_X86_64_GLOB_DAT = 6
332
+ R_X86_64_JMP_SLOT = 7
333
+ R_X86_64_RELATIVE = 8
334
+ R_X86_64_GOTPCREL = 9
335
+ R_X86_64_32 = 10
336
+ R_X86_64_32S = 11
337
+ R_X86_64_16 = 12
338
+ R_X86_64_PC16 = 13
339
+ R_X86_64_8 = 14
340
+ R_X86_64_PC8 = 15
341
+ R_X86_64_DTPMOD64 = 16
342
+ R_X86_64_DTPOFF64 = 17
343
+ R_X86_64_TPOFF64 = 18
344
+ R_X86_64_TLSGD = 19
345
+ R_X86_64_TLSLD = 20
346
+ R_X86_64_DTPOFF32 = 21
347
+ R_X86_64_GOTTPOFF = 22
348
+ R_X86_64_TPOFF32 = 23
349
+ R_X86_64_SIZE64 = 33
350
+ R_X86_64_COUNT = 39
351
+ R_ALPHA_NONE = 0
352
+ R_ALPHA_REFLONG = 1
353
+ R_ALPHA_REFQUAD = 2
354
+ R_ALPHA_GPREL32 = 3
355
+ R_ALPHA_LITERAL = 4
356
+ R_ALPHA_LITUSE = 5
357
+ R_ALPHA_GPDISP = 6
358
+ R_ALPHA_BRADDR = 7
359
+ R_ALPHA_HINT = 8
360
+ R_ALPHA_SREL16 = 9
361
+ R_ALPHA_SREL32 = 10
362
+ R_ALPHA_SREL64 = 11
363
+ R_ALPHA_OP_PUSH = 12
364
+ R_ALPHA_OP_STORE = 13
365
+ R_ALPHA_OP_PSUB = 14
366
+ R_ALPHA_OP_PRSHIFT = 15
367
+ R_ALPHA_GPVALUE = 16
368
+ R_ALPHA_GPRELHIGH = 17
369
+ R_ALPHA_GPRELLOW = 18
370
+ R_ALPHA_IMMED_GP_16 = 19
371
+ R_ALPHA_IMMED_GP_HI32 = 20
372
+ R_ALPHA_IMMED_SCN_HI32 = 21
373
+ R_ALPHA_IMMED_BR_HI32 = 22
374
+ R_ALPHA_IMMED_LO32 = 23
375
+ R_ALPHA_COPY = 24
376
+ R_ALPHA_GLOB_DAT = 25
377
+ R_ALPHA_JMP_SLOT = 26
378
+ R_ALPHA_RELATIVE = 27
379
+ R_ALPHA_COUNT = 28
380
+ R_ARM_NONE = 0
381
+ R_ARM_PC24 = 1
382
+ R_ARM_ABS32 = 2
383
+ R_ARM_REL32 = 3
384
+ R_ARM_PC13 = 4
385
+ R_ARM_ABS16 = 5
386
+ R_ARM_ABS12 = 6
387
+ R_ARM_THM_ABS5 = 7
388
+ R_ARM_ABS8 = 8
389
+ R_ARM_SBREL32 = 9
390
+ R_ARM_THM_PC22 = 10
391
+ R_ARM_THM_PC8 = 11
392
+ R_ARM_AMP_VCALL9 = 12
393
+ R_ARM_SWI24 = 13
394
+ R_ARM_THM_SWI8 = 14
395
+ R_ARM_XPC25 = 15
396
+ R_ARM_THM_XPC22 = 16
397
+ R_ARM_COPY = 20
398
+ R_ARM_GLOB_DAT = 21
399
+ R_ARM_JUMP_SLOT = 22
400
+ R_ARM_RELATIVE = 23
401
+ R_ARM_GOTOFF = 24
402
+ R_ARM_GOTPC = 25
403
+ R_ARM_GOT32 = 26
404
+ R_ARM_PLT32 = 27
405
+ R_ARM_GNU_VTENTRY = 100
406
+ R_ARM_GNU_VTINHERIT = 101
407
+ R_ARM_RSBREL32 = 250
408
+ R_ARM_THM_RPC22 = 251
409
+ R_ARM_RREL32 = 252
410
+ R_ARM_RABS32 = 253
411
+ R_ARM_RPC24 = 254
412
+ R_ARM_RBASE = 255
413
+ R_ARM_COUNT = 33
414
+ R_386_NONE = 0
415
+ R_386_32 = 1
416
+ R_386_PC32 = 2
417
+ R_386_GOT32 = 3
418
+ R_386_PLT32 = 4
419
+ R_386_COPY = 5
420
+ R_386_GLOB_DAT = 6
421
+ R_386_JMP_SLOT = 7
422
+ R_386_RELATIVE = 8
423
+ R_386_GOTOFF = 9
424
+ R_386_GOTPC = 10
425
+ R_386_TLS_TPOFF = 14
426
+ R_386_TLS_IE = 15
427
+ R_386_TLS_GOTIE = 16
428
+ R_386_TLS_LE = 17
429
+ R_386_TLS_GD = 18
430
+ R_386_TLS_LDM = 19
431
+ R_386_TLS_GD_32 = 24
432
+ R_386_TLS_GD_PUSH = 25
433
+ R_386_TLS_GD_CALL = 26
434
+ R_386_TLS_GD_POP = 27
435
+ R_386_TLS_LDM_32 = 28
436
+ R_386_TLS_LDM_PUSH = 29
437
+ R_386_TLS_LDM_CALL = 30
438
+ R_386_TLS_LDM_POP = 31
439
+ R_386_TLS_LDO_32 = 32
440
+ R_386_TLS_IE_32 = 33
441
+ R_386_TLS_LE_32 = 34
442
+ R_386_TLS_DTPMOD32 = 35
443
+ R_386_TLS_DTPOFF32 = 36
444
+ R_386_TLS_TPOFF32 = 37
445
+ R_386_COUNT = 38
446
+ R_PPC_NONE = 0
447
+ R_PPC_ADDR32 = 1
448
+ R_PPC_ADDR24 = 2
449
+ R_PPC_ADDR16 = 3
450
+ R_PPC_ADDR16_LO = 4
451
+ R_PPC_ADDR16_HI = 5
452
+ R_PPC_ADDR16_HA = 6
453
+ R_PPC_ADDR14 = 7
454
+ R_PPC_ADDR14_BRTAKEN = 8
455
+ R_PPC_ADDR14_BRNTAKEN = 9
456
+ R_PPC_REL24 = 10
457
+ R_PPC_REL14 = 11
458
+ R_PPC_REL14_BRTAKEN = 12
459
+ R_PPC_REL14_BRNTAKEN = 13
460
+ R_PPC_GOT16 = 14
461
+ R_PPC_GOT16_LO = 15
462
+ R_PPC_GOT16_HI = 16
463
+ R_PPC_GOT16_HA = 17
464
+ R_PPC_PLTREL24 = 18
465
+ R_PPC_COPY = 19
466
+ R_PPC_GLOB_DAT = 20
467
+ R_PPC_JMP_SLOT = 21
468
+ R_PPC_RELATIVE = 22
469
+ R_PPC_LOCAL24PC = 23
470
+ R_PPC_UADDR32 = 24
471
+ R_PPC_UADDR16 = 25
472
+ R_PPC_REL32 = 26
473
+ R_PPC_PLT32 = 27
474
+ R_PPC_PLTREL32 = 28
475
+ R_PPC_PLT16_LO = 29
476
+ R_PPC_PLT16_HI = 30
477
+ R_PPC_PLT16_HA = 31
478
+ R_PPC_SDAREL16 = 32
479
+ R_PPC_SECTOFF = 33
480
+ R_PPC_SECTOFF_LO = 34
481
+ R_PPC_SECTOFF_HI = 35
482
+ R_PPC_SECTOFF_HA = 36
483
+ R_PPC_COUNT = 37
484
+ R_PPC_TLS = 67
485
+ R_PPC_DTPMOD32 = 68
486
+ R_PPC_TPREL16 = 69
487
+ R_PPC_TPREL16_LO = 70
488
+ R_PPC_TPREL16_HI = 71
489
+ R_PPC_TPREL16_HA = 72
490
+ R_PPC_TPREL32 = 73
491
+ R_PPC_DTPREL16 = 74
492
+ R_PPC_DTPREL16_LO = 75
493
+ R_PPC_DTPREL16_HI = 76
494
+ R_PPC_DTPREL16_HA = 77
495
+ R_PPC_DTPREL32 = 78
496
+ R_PPC_GOT_TLSGD16 = 79
497
+ R_PPC_GOT_TLSGD16_LO = 80
498
+ R_PPC_GOT_TLSGD16_HI = 81
499
+ R_PPC_GOT_TLSGD16_HA = 82
500
+ R_PPC_GOT_TLSLD16 = 83
501
+ R_PPC_GOT_TLSLD16_LO = 84
502
+ R_PPC_GOT_TLSLD16_HI = 85
503
+ R_PPC_GOT_TLSLD16_HA = 86
504
+ R_PPC_GOT_TPREL16 = 87
505
+ R_PPC_GOT_TPREL16_LO = 88
506
+ R_PPC_GOT_TPREL16_HI = 89
507
+ R_PPC_GOT_TPREL16_HA = 90
508
+ R_PPC_EMB_NADDR32 = 101
509
+ R_PPC_EMB_NADDR16 = 102
510
+ R_PPC_EMB_NADDR16_LO = 103
511
+ R_PPC_EMB_NADDR16_HI = 104
512
+ R_PPC_EMB_NADDR16_HA = 105
513
+ R_PPC_EMB_SDAI16 = 106
514
+ R_PPC_EMB_SDA2I16 = 107
515
+ R_PPC_EMB_SDA2REL = 108
516
+ R_PPC_EMB_SDA21 = 109
517
+ R_PPC_EMB_MRKREF = 110
518
+ R_PPC_EMB_RELSEC16 = 111
519
+ R_PPC_EMB_RELST_LO = 112
520
+ R_PPC_EMB_RELST_HI = 113
521
+ R_PPC_EMB_RELST_HA = 114
522
+ R_PPC_EMB_BIT_FLD = 115
523
+ R_PPC_EMB_RELSDA = 116
524
+ R_SPARC_NONE = 0
525
+ R_SPARC_8 = 1
526
+ R_SPARC_16 = 2
527
+ R_SPARC_32 = 3
528
+ R_SPARC_DISP8 = 4
529
+ R_SPARC_DISP16 = 5
530
+ R_SPARC_DISP32 = 6
531
+ R_SPARC_WDISP30 = 7
532
+ R_SPARC_WDISP22 = 8
533
+ R_SPARC_HI22 = 9
534
+ R_SPARC_22 = 10
535
+ R_SPARC_13 = 11
536
+ R_SPARC_LO10 = 12
537
+ R_SPARC_GOT10 = 13
538
+ R_SPARC_GOT13 = 14
539
+ R_SPARC_GOT22 = 15
540
+ R_SPARC_PC10 = 16
541
+ R_SPARC_PC22 = 17
542
+ R_SPARC_WPLT30 = 18
543
+ R_SPARC_COPY = 19
544
+ R_SPARC_GLOB_DAT = 20
545
+ R_SPARC_JMP_SLOT = 21
546
+ R_SPARC_RELATIVE = 22
547
+ R_SPARC_UA32 = 23
548
+ R_SPARC_PLT32 = 24
549
+ R_SPARC_HIPLT22 = 25
550
+ R_SPARC_LOPLT10 = 26
551
+ R_SPARC_PCPLT32 = 27
552
+ R_SPARC_PCPLT22 = 28
553
+ R_SPARC_PCPLT10 = 29
554
+ R_SPARC_10 = 30
555
+ R_SPARC_11 = 31
556
+ R_SPARC_64 = 32
557
+ R_SPARC_OLO10 = 33
558
+ R_SPARC_HH22 = 34
559
+ R_SPARC_HM10 = 35
560
+ R_SPARC_LM22 = 36
561
+ R_SPARC_PC_HH22 = 37
562
+ R_SPARC_PC_HM10 = 38
563
+ R_SPARC_PC_LM22 = 39
564
+ R_SPARC_WDISP16 = 40
565
+ R_SPARC_WDISP19 = 41
566
+ R_SPARC_GLOB_JMP = 42
567
+ R_SPARC_7 = 43
568
+ R_SPARC_5 = 44
569
+ R_SPARC_6 = 45
570
+ R_SPARC_DISP64 = 46
571
+ R_SPARC_PLT64 = 47
572
+ R_SPARC_HIX22 = 48
573
+ R_SPARC_LOX10 = 49
574
+ R_SPARC_H44 = 50
575
+ R_SPARC_M44 = 51
576
+ R_SPARC_L44 = 52
577
+ R_SPARC_REGISTER = 53
578
+ R_SPARC_UA64 = 54
579
+ R_SPARC_UA16 = 55
580
+ end
581
+ end