elftools 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef6779875e27077da47848a95cef46ee26be52e56e763c0850dbd2e22e7e100b
4
- data.tar.gz: a9b422a4fb0a11a08036e222475110f9a9f6f788ce8c775d6e67d0e6f1b5a9c6
3
+ metadata.gz: ab5e28fa0f434f6bbfe67e7799ba85fdd5e66aef685c9b299e948dcac916b21a
4
+ data.tar.gz: 70fbe96e62e6ebe036082959b3f0be0803bd7fe5cee42194686369d19529d35f
5
5
  SHA512:
6
- metadata.gz: 13f82b3b243a09531408986b1acef31556089bca5927077c9e4d490632229f77cef97f9fdd1eb4343be8dc9bbb9f55e57b3ee51f5da5651009bd4b4ac3724eb5
7
- data.tar.gz: 276ad11bcc135f067046694da526da5078cfdc0b24137cadeb7d8c52b0ddb462b23ee7d47c97bc08611160d436240c559ff1b4d18b51ed78a0b607c0973dc913
6
+ metadata.gz: 52bacdbdb8de7d6f3d0c28d52b7b4e8b75c69741381ae45877f9a5424af69a4ba299e28479851defc48884147aa87ae4ab5f7c9d86a7ef5515ae895dbc284d45
7
+ data.tar.gz: a06de74a09b59b5067e4d31cd12f5c377ef9dc936fe7fda3d906bd2e9107ad5d3e049914b2542a56c4cb0895b672a56d13106ad0c78c9511ae6af92e29943d15
data/README.md CHANGED
@@ -1,21 +1,23 @@
1
- [![Build Status](https://travis-ci.org/david942j/rbelftools.svg?branch=master)](https://travis-ci.org/david942j/rbelftools)
2
- [![Build Status](https://ci.appveyor.com/api/projects/status/sq5c4gli8ir95h6k?svg=true&retina=true)](https://ci.appveyor.com/project/david942j/rbelftools)
1
+ [![Build Status](https://github.com/david942j/rbelftools/workflows/build/badge.svg)](https://github.com/david942j/rbelftools/actions)
3
2
  [![Code Climate](https://codeclimate.com/github/david942j/rbelftools/badges/gpa.svg)](https://codeclimate.com/github/david942j/rbelftools)
4
3
  [![Issue Count](https://codeclimate.com/github/david942j/rbelftools/badges/issue_count.svg)](https://codeclimate.com/github/david942j/rbelftools)
5
4
  [![Test Coverage](https://codeclimate.com/github/david942j/rbelftools/badges/coverage.svg)](https://codeclimate.com/github/david942j/rbelftools/coverage)
6
5
  [![Inline docs](https://inch-ci.org/github/david942j/rbelftools.svg?branch=master)](https://inch-ci.org/github/david942j/rbelftools)
6
+ [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](https://www.rubydoc.info/github/david942j/rbelftools/)
7
7
  [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](http://choosealicense.com/licenses/mit/)
8
8
 
9
9
  # rbelftools
10
- Pure ruby library for parsing and patching ELF files.
10
+ Pure Ruby library for parsing and patching ELF files.
11
11
 
12
12
  # Introduction
13
13
 
14
- ELF parser in pure ruby implementation. This work is inspired by [pyelftools](https://github.com/eliben/pyelftools) by [Eli Bendersky](https://github.com/eliben).
14
+ An ELF parser implemented in pure Ruby. This work is inspired by [pyelftools](https://github.com/eliben/pyelftools) by [Eli Bendersky](https://github.com/eliben).
15
15
 
16
- The motivation to create this repository is want to be a dependency of [pwntools-ruby](https://github.com/peter50216/pwntools-ruby). Since ELF parser is a big work, it should not be implemented directly in pwntools.
16
+ The original motivation to create this gem is to be a dependency of [pwntools-ruby](https://github.com/peter50216/pwntools-ruby). Since ELF parser is not an easy work, it should not be implemented directly in pwntools.
17
17
 
18
- **rbelftools**'s target is to create a nice ELF parsing library in ruby. More features remain a work in progress.
18
+ Now rbelftools is also used by the [Homebrew](https://github.com/Homebrew/brew) project: https://github.com/Homebrew/brew/tree/master/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/elftools-1.1.3/lib
19
+
20
+ **rbelftools**'s target is to create a nice ELF parsing library in Ruby. More features remain a work in progress.
19
21
 
20
22
  # Install
21
23
 
@@ -34,9 +36,10 @@ See example usage for more details.
34
36
 
35
37
  # Example Usage
36
38
 
37
- ## Start from file object
39
+ ## Start from a file object
38
40
  ```ruby
39
41
  require 'elftools'
42
+
40
43
  elf = ELFTools::ELFFile.new(File.open('spec/files/amd64.elf'))
41
44
  #=> #<ELFTools::ELFFile:0x00560b147f8328 @elf_class=64, @endian=:little, @stream=#<File:spec/files/amd64>>
42
45
 
@@ -48,6 +51,7 @@ elf.build_id
48
51
  ```
49
52
 
50
53
  ## Sections
54
+
51
55
  ```ruby
52
56
  elf.section_by_name('.dynstr')
53
57
  #=>
@@ -75,6 +79,7 @@ elf.section_by_name('.note.gnu.build-id').data
75
79
  ```
76
80
 
77
81
  ## Symbols
82
+
78
83
  ```ruby
79
84
  symtab_section = elf.section_by_name('.symtab')
80
85
  symtab_section.num_symbols
@@ -92,6 +97,7 @@ symbols.map(&:name).reject(&:empty?).first(5).join(' ')
92
97
  ```
93
98
 
94
99
  ## Segments
100
+
95
101
  ```ruby
96
102
  elf.segment_by_type(:note)
97
103
  #=>
@@ -165,14 +171,14 @@ elf.save('elf.patched')
165
171
  2. Fully tested
166
172
  Of course.
167
173
  3. Lazy loading on everything
168
- To use **rbelftools**, only need to pass the stream object of ELF file.
174
+ To use **rbelftools**, passing the stream object of an ELF file.
169
175
  **rbelftools** will read the stream object **as least times as possible** when parsing
170
176
  the file. Most information will not be fetched until you need it, which makes
171
177
  **rbelftools** efficient.
172
178
  4. To be a library
173
179
  **rbelftools** is designed to be a library for further usage.
174
180
  It will _not_ add any too trivial features.
175
- For example, to check if NX disabled, you can use
181
+ For example, to check whether NX is disabled, **rbelftools** provides
176
182
  `!elf.segment_by_type(:gnu_stack).executable?` but not `elf.nx?`
177
183
  5. Section and segment parser
178
184
  Providing common sections and segments parser. For example, `.symtab`, `.shstrtab`
@@ -42,120 +42,371 @@ module ELFTools
42
42
  DF_1_SYMINTPOSE = 0x00800000 # Object has individual interposers.
43
43
  DF_1_GLOBAUDIT = 0x01000000 # Global auditing required.
44
44
  DF_1_SINGLETON = 0x02000000 # Singleton symbols are used.
45
+ DF_1_STUB = 0x04000000 # :nodoc:
46
+ DF_1_PIE = 0x08000000 # Object is a position-independent executable.
47
+ DF_1_KMOD = 0x10000000 # :nodoc:
48
+ DF_1_WEAKFILTER = 0x20000000 # :nodoc:
49
+ DF_1_NOCOMMON = 0x40000000 # :nodoc:
45
50
  end
46
51
  include DF
47
52
 
48
53
  # Dynamic table types, records in +d_tag+.
49
54
  module DT
50
- DT_NULL = 0 # marks the end of the _DYNAMIC array
51
- DT_NEEDED = 1 # libraries need to be linked by loader
52
- DT_PLTRELSZ = 2 # total size of relocation entries
53
- DT_PLTGOT = 3 # address of procedure linkage table or global offset table
54
- DT_HASH = 4 # address of symbol hash table
55
- DT_STRTAB = 5 # address of string table
56
- DT_SYMTAB = 6 # address of symbol table
57
- DT_RELA = 7 # address of a relocation table
58
- DT_RELASZ = 8 # total size of the {DT_RELA} table
59
- DT_RELAENT = 9 # size of each entry in the {DT_RELA} table
60
- DT_STRSZ = 10 # total size of {DT_STRTAB}
61
- DT_SYMENT = 11 # size of each entry in {DT_SYMTAB}
62
- DT_INIT = 12 # where the initialization function is
63
- DT_FINI = 13 # where the termination function is
64
- DT_SONAME = 14 # the shared object name
65
- DT_RPATH = 15 # has been superseded by {DT_RUNPATH}
66
- DT_SYMBOLIC = 16 # has been superseded by the DF_SYMBOLIC flag
67
- DT_REL = 17 # similar to {DT_RELA}
68
- DT_RELSZ = 18 # total size of the {DT_REL} table
69
- DT_RELENT = 19 # size of each entry in the {DT_REL} table
70
- DT_PLTREL = 20 # type of relocation entry, either {DT_REL} or {DT_RELA}
71
- DT_DEBUG = 21 # for debugging
72
- DT_TEXTREL = 22 # has been superseded by the DF_TEXTREL flag
73
- DT_JMPREL = 23 # address of relocation entries that are associated solely with the procedure linkage table
74
- DT_BIND_NOW = 24 # if the loader needs to do relocate now, superseded by the DF_BIND_NOW flag
75
- DT_INIT_ARRAY = 25 # address init array
76
- DT_FINI_ARRAY = 26 # address of fini array
77
- DT_INIT_ARRAYSZ = 27 # total size of init array
78
- DT_FINI_ARRAYSZ = 28 # total size of fini array
79
- DT_RUNPATH = 29 # path of libraries for searching
80
- DT_FLAGS = 30 # flags
81
- DT_ENCODING = 32 # just a lower bound
55
+ DT_NULL = 0 # marks the end of the _DYNAMIC array
56
+ DT_NEEDED = 1 # libraries need to be linked by loader
57
+ DT_PLTRELSZ = 2 # total size of relocation entries
58
+ DT_PLTGOT = 3 # address of procedure linkage table or global offset table
59
+ DT_HASH = 4 # address of symbol hash table
60
+ DT_STRTAB = 5 # address of string table
61
+ DT_SYMTAB = 6 # address of symbol table
62
+ DT_RELA = 7 # address of a relocation table
63
+ DT_RELASZ = 8 # total size of the {DT_RELA} table
64
+ DT_RELAENT = 9 # size of each entry in the {DT_RELA} table
65
+ DT_STRSZ = 10 # total size of {DT_STRTAB}
66
+ DT_SYMENT = 11 # size of each entry in {DT_SYMTAB}
67
+ DT_INIT = 12 # where the initialization function is
68
+ DT_FINI = 13 # where the termination function is
69
+ DT_SONAME = 14 # the shared object name
70
+ DT_RPATH = 15 # has been superseded by {DT_RUNPATH}
71
+ DT_SYMBOLIC = 16 # has been superseded by the DF_SYMBOLIC flag
72
+ DT_REL = 17 # similar to {DT_RELA}
73
+ DT_RELSZ = 18 # total size of the {DT_REL} table
74
+ DT_RELENT = 19 # size of each entry in the {DT_REL} table
75
+ DT_PLTREL = 20 # type of relocation entry, either {DT_REL} or {DT_RELA}
76
+ DT_DEBUG = 21 # for debugging
77
+ DT_TEXTREL = 22 # has been superseded by the DF_TEXTREL flag
78
+ DT_JMPREL = 23 # address of relocation entries associated solely with procedure linkage table
79
+ DT_BIND_NOW = 24 # if the loader needs to do relocate now, superseded by the DF_BIND_NOW flag
80
+ DT_INIT_ARRAY = 25 # address init array
81
+ DT_FINI_ARRAY = 26 # address of fini array
82
+ DT_INIT_ARRAYSZ = 27 # total size of init array
83
+ DT_FINI_ARRAYSZ = 28 # total size of fini array
84
+ DT_RUNPATH = 29 # path of libraries for searching
85
+ DT_FLAGS = 30 # flags
86
+ DT_ENCODING = 32 # just a lower bound
87
+ DT_PREINIT_ARRAY = 32 # pre-initialization functions array
88
+ DT_PREINIT_ARRAYSZ = 33 # pre-initialization functions array size (bytes)
89
+ DT_SYMTAB_SHNDX = 34 # address of the +SHT_SYMTAB_SHNDX+ section associated with {DT_SYMTAB} table
90
+ DT_RELRSZ = 35 # :nodoc:
91
+ DT_RELR = 36 # :nodoc:
92
+ DT_RELRENT = 37 # :nodoc:
93
+
82
94
  # Values between {DT_LOOS} and {DT_HIOS} are reserved for operating system-specific semantics.
83
- DT_LOOS = 0x6000000d
84
- DT_HIOS = 0x6ffff000 # see {DT_LOOS}
95
+ DT_LOOS = 0x6000000d
96
+ DT_HIOS = 0x6ffff000 # see {DT_LOOS}
97
+
85
98
  # Values between {DT_VALRNGLO} and {DT_VALRNGHI} use the +d_un.d_val+ field of the dynamic structure.
86
- DT_VALRNGLO = 0x6ffffd00
87
- DT_VALRNGHI = 0x6ffffdff # see {DT_VALRNGLO}
99
+ DT_VALRNGLO = 0x6ffffd00
100
+ DT_VALRNGHI = 0x6ffffdff # see {DT_VALRNGLO}
101
+
88
102
  # Values between {DT_ADDRRNGLO} and {DT_ADDRRNGHI} use the +d_un.d_ptr+ field of the dynamic structure.
89
- DT_ADDRRNGLO = 0x6ffffe00
90
- DT_GNU_HASH = 0x6ffffef5 # the gnu hash
91
- DT_ADDRRNGHI = 0x6ffffeff # see {DT_ADDRRNGLO}
92
- DT_RELACOUNT = 0x6ffffff9 # relative relocation count
93
- DT_RELCOUNT = 0x6ffffffa # relative relocation count
94
- DT_FLAGS_1 = 0x6ffffffb # flags
95
- DT_VERDEF = 0x6ffffffc # address of version definition table
96
- DT_VERDEFNUM = 0x6ffffffd # number of entries in {DT_VERDEF}
97
- DT_VERNEED = 0x6ffffffe # address of version dependency table
98
- DT_VERSYM = 0x6ffffff0 # section address of .gnu.version
99
- DT_VERNEEDNUM = 0x6fffffff # number of entries in {DT_VERNEED}
103
+ DT_ADDRRNGLO = 0x6ffffe00
104
+ DT_GNU_HASH = 0x6ffffef5 # the gnu hash
105
+ DT_TLSDESC_PLT = 0x6ffffef6 # :nodoc:
106
+ DT_TLSDESC_GOT = 0x6ffffef7 # :nodoc:
107
+ DT_GNU_CONFLICT = 0x6ffffef8 # :nodoc:
108
+ DT_GNU_LIBLIST = 0x6ffffef9 # :nodoc:
109
+ DT_CONFIG = 0x6ffffefa # :nodoc:
110
+ DT_DEPAUDIT = 0x6ffffefb # :nodoc:
111
+ DT_AUDIT = 0x6ffffefc # :nodoc:
112
+ DT_PLTPAD = 0x6ffffefd # :nodoc:
113
+ DT_MOVETAB = 0x6ffffefe # :nodoc:
114
+ DT_SYMINFO = 0x6ffffeff # :nodoc:
115
+ DT_ADDRRNGHI = 0x6ffffeff # see {DT_ADDRRNGLO}
116
+
117
+ DT_VERSYM = 0x6ffffff0 # section address of .gnu.version
118
+ DT_RELACOUNT = 0x6ffffff9 # relative relocation count
119
+ DT_RELCOUNT = 0x6ffffffa # relative relocation count
120
+ DT_FLAGS_1 = 0x6ffffffb # flags
121
+ DT_VERDEF = 0x6ffffffc # address of version definition table
122
+ DT_VERDEFNUM = 0x6ffffffd # number of entries in {DT_VERDEF}
123
+ DT_VERNEED = 0x6ffffffe # address of version dependency table
124
+ DT_VERNEEDNUM = 0x6fffffff # number of entries in {DT_VERNEED}
125
+
100
126
  # Values between {DT_LOPROC} and {DT_HIPROC} are reserved for processor-specific semantics.
101
- DT_LOPROC = 0x70000000
102
- DT_HIPROC = 0x7fffffff # see {DT_LOPROC}
127
+ DT_LOPROC = 0x70000000
128
+
129
+ DT_PPC_GOT = 0x70000000 # global offset table
130
+ DT_PPC_OPT = 0x70000001 # whether various optimisations are possible
131
+
132
+ DT_PPC64_GLINK = 0x70000000 # start of the .glink section
133
+ DT_PPC64_OPD = 0x70000001 # start of the .opd section
134
+ DT_PPC64_OPDSZ = 0x70000002 # size of the .opd section
135
+ DT_PPC64_OPT = 0x70000003 # whether various optimisations are possible
136
+
137
+ DT_SPARC_REGISTER = 0x70000000 # index of an +STT_SPARC_REGISTER+ symbol within the {DT_SYMTAB} table
138
+
139
+ DT_MIPS_RLD_VERSION = 0x70000001 # 32 bit version number for runtime linker interface
140
+ DT_MIPS_TIME_STAMP = 0x70000002 # time stamp
141
+ DT_MIPS_ICHECKSUM = 0x70000003 # checksum of external strings and common sizes
142
+ DT_MIPS_IVERSION = 0x70000004 # index of version string in string table
143
+ DT_MIPS_FLAGS = 0x70000005 # 32 bits of flags
144
+ DT_MIPS_BASE_ADDRESS = 0x70000006 # base address of the segment
145
+ DT_MIPS_MSYM = 0x70000007 # :nodoc:
146
+ DT_MIPS_CONFLICT = 0x70000008 # address of +.conflict+ section
147
+ DT_MIPS_LIBLIST = 0x70000009 # address of +.liblist+ section
148
+ DT_MIPS_LOCAL_GOTNO = 0x7000000a # number of local global offset table entries
149
+ DT_MIPS_CONFLICTNO = 0x7000000b # number of entries in the +.conflict+ section
150
+ DT_MIPS_LIBLISTNO = 0x70000010 # number of entries in the +.liblist+ section
151
+ DT_MIPS_SYMTABNO = 0x70000011 # number of entries in the +.dynsym+ section
152
+ DT_MIPS_UNREFEXTNO = 0x70000012 # index of first external dynamic symbol not referenced locally
153
+ DT_MIPS_GOTSYM = 0x70000013 # index of first dynamic symbol in global offset table
154
+ DT_MIPS_HIPAGENO = 0x70000014 # number of page table entries in global offset table
155
+ DT_MIPS_RLD_MAP = 0x70000016 # address of run time loader map, used for debugging
156
+ DT_MIPS_DELTA_CLASS = 0x70000017 # delta C++ class definition
157
+ DT_MIPS_DELTA_CLASS_NO = 0x70000018 # number of entries in {DT_MIPS_DELTA_CLASS}
158
+ DT_MIPS_DELTA_INSTANCE = 0x70000019 # delta C++ class instances
159
+ DT_MIPS_DELTA_INSTANCE_NO = 0x7000001a # number of entries in {DT_MIPS_DELTA_INSTANCE}
160
+ DT_MIPS_DELTA_RELOC = 0x7000001b # delta relocations
161
+ DT_MIPS_DELTA_RELOC_NO = 0x7000001c # number of entries in {DT_MIPS_DELTA_RELOC}
162
+ DT_MIPS_DELTA_SYM = 0x7000001d # delta symbols that Delta relocations refer to
163
+ DT_MIPS_DELTA_SYM_NO = 0x7000001e # number of entries in {DT_MIPS_DELTA_SYM}
164
+ DT_MIPS_DELTA_CLASSSYM = 0x70000020 # delta symbols that hold class declarations
165
+ DT_MIPS_DELTA_CLASSSYM_NO = 0x70000021 # number of entries in {DT_MIPS_DELTA_CLASSSYM}
166
+ DT_MIPS_CXX_FLAGS = 0x70000022 # flags indicating information about C++ flavor
167
+ DT_MIPS_PIXIE_INIT = 0x70000023 # :nodoc:
168
+ DT_MIPS_SYMBOL_LIB = 0x70000024 # address of +.MIPS.symlib+
169
+ DT_MIPS_LOCALPAGE_GOTIDX = 0x70000025 # GOT index of the first PTE for a segment
170
+ DT_MIPS_LOCAL_GOTIDX = 0x70000026 # GOT index of the first PTE for a local symbol
171
+ DT_MIPS_HIDDEN_GOTIDX = 0x70000027 # GOT index of the first PTE for a hidden symbol
172
+ DT_MIPS_PROTECTED_GOTIDX = 0x70000028 # GOT index of the first PTE for a protected symbol
173
+ DT_MIPS_OPTIONS = 0x70000029 # address of +.MIPS.options+
174
+ DT_MIPS_INTERFACE = 0x7000002a # address of +.interface+
175
+ DT_MIPS_DYNSTR_ALIGN = 0x7000002b # :nodoc:
176
+ DT_MIPS_INTERFACE_SIZE = 0x7000002c # size of the +.interface+ section
177
+ DT_MIPS_RLD_TEXT_RESOLVE_ADDR = 0x7000002d # size of +rld_text_resolve+ function stored in the GOT
178
+ DT_MIPS_PERF_SUFFIX = 0x7000002e # default suffix of DSO to be added by rld on +dlopen()+ calls
179
+ DT_MIPS_COMPACT_SIZE = 0x7000002f # size of compact relocation section (O32)
180
+ DT_MIPS_GP_VALUE = 0x70000030 # GP value for auxiliary GOTs
181
+ DT_MIPS_AUX_DYNAMIC = 0x70000031 # address of auxiliary +.dynamic+
182
+ DT_MIPS_PLTGOT = 0x70000032 # address of the base of the PLTGOT
183
+ DT_MIPS_RWPLT = 0x70000034 # base of a writable PLT
184
+ DT_MIPS_RLD_MAP_REL = 0x70000035 # relative offset of run time loader map
185
+ DT_MIPS_XHASH = 0x70000036 # GNU-style hash table with xlat
186
+
187
+ DT_AUXILIARY = 0x7ffffffd # :nodoc:
188
+ DT_USED = 0x7ffffffe # :nodoc:
189
+ DT_FILTER = 0x7ffffffe # :nodoc:
190
+
191
+ DT_HIPROC = 0x7fffffff # see {DT_LOPROC}
103
192
  end
104
193
  include DT
105
194
 
106
195
  # These constants define the various ELF target machines.
107
196
  module EM
108
- EM_NONE = 0 # none
109
- EM_M32 = 1 # AT&T WE 32100
110
- EM_SPARC = 2 # SPARC
111
- EM_386 = 3 # Intel 80386
112
- EM_68K = 4 # Motorola 68000
113
- EM_88K = 5 # Motorola 88000
114
- EM_486 = 6 # Intel 80486
115
- EM_860 = 7 # Intel 80860
116
- EM_MIPS = 8 # MIPS R3000 (officially, big-endian only)
197
+ EM_NONE = 0 # none
198
+ EM_M32 = 1 # AT&T WE 32100
199
+ EM_SPARC = 2 # SPARC
200
+ EM_386 = 3 # Intel 80386
201
+ EM_68K = 4 # Motorola 68000
202
+ EM_88K = 5 # Motorola 88000
203
+ EM_486 = 6 # Intel 80486
204
+ EM_860 = 7 # Intel 80860
205
+ EM_MIPS = 8 # MIPS R3000 (officially, big-endian only)
206
+ EM_S370 = 9 # IBM System/370
117
207
 
118
208
  # Next two are historical and binaries and
119
209
  # modules of these types will be rejected by Linux.
120
- EM_MIPS_RS3_LE = 10 # MIPS R3000 little-endian
121
- EM_MIPS_RS4_BE = 10 # MIPS R4000 big-endian
122
-
123
- EM_PARISC = 15 # HPPA
124
- EM_SPARC32PLUS = 18 # Sun's "v8plus"
125
- EM_PPC = 20 # PowerPC
126
- EM_PPC64 = 21 # PowerPC64
127
- EM_SPU = 23 # Cell BE SPU
128
- EM_ARM = 40 # ARM 32 bit
129
- EM_SH = 42 # SuperH
130
- EM_SPARCV9 = 43 # SPARC v9 64-bit
131
- EM_H8_300 = 46 # Renesas H8/300
132
- EM_IA_64 = 50 # HP/Intel IA-64
133
- EM_X86_64 = 62 # AMD x86-64
134
- EM_S390 = 22 # IBM S/390
135
- EM_CRIS = 76 # Axis Communications 32-bit embedded processor
136
- EM_M32R = 88 # Renesas M32R
137
- EM_MN10300 = 89 # Panasonic/MEI MN10300, AM33
138
- EM_OPENRISC = 92 # OpenRISC 32-bit embedded processor
139
- EM_BLACKFIN = 106 # ADI Blackfin Processor
140
- EM_ALTERA_NIOS2 = 113 # Altera Nios II soft-core processor
141
- EM_TI_C6000 = 140 # TI C6X DSPs
142
- EM_AARCH64 = 183 # ARM 64 bit
143
- EM_TILEPRO = 188 # Tilera TILEPro
144
- EM_MICROBLAZE = 189 # Xilinx MicroBlaze
145
- EM_TILEGX = 191 # Tilera TILE-Gx
146
- EM_BPF = 247 # Linux BPF - in-kernel virtual machine
147
- EM_FRV = 0x5441 # Fujitsu FR-V
148
- EM_AVR32 = 0x18ad # Atmel AVR32
210
+ EM_MIPS_RS3_LE = 10 # MIPS R3000 little-endian
211
+ EM_MIPS_RS4_BE = 10 # MIPS R4000 big-endian
212
+
213
+ EM_PARISC = 15 # HPPA
214
+ EM_VPP500 = 17 # Fujitsu VPP500 (also some older versions of PowerPC)
215
+ EM_SPARC32PLUS = 18 # Sun's "v8plus"
216
+ EM_960 = 19 # Intel 80960
217
+ EM_PPC = 20 # PowerPC
218
+ EM_PPC64 = 21 # PowerPC64
219
+ EM_S390 = 22 # IBM S/390
220
+ EM_SPU = 23 # Cell BE SPU
221
+ EM_V800 = 36 # NEC V800 series
222
+ EM_FR20 = 37 # Fujitsu FR20
223
+ EM_RH32 = 38 # TRW RH32
224
+ EM_RCE = 39 # Motorola M*Core
225
+ EM_ARM = 40 # ARM 32 bit
226
+ EM_SH = 42 # SuperH
227
+ EM_SPARCV9 = 43 # SPARC v9 64-bit
228
+ EM_TRICORE = 44 # Siemens Tricore embedded processor
229
+ EM_ARC = 45 # ARC Cores
230
+ EM_H8_300 = 46 # Renesas H8/300
231
+ EM_H8_300H = 47 # Renesas H8/300H
232
+ EM_H8S = 48 # Renesas H8S
233
+ EM_H8_500 = 49 # Renesas H8/500H
234
+ EM_IA_64 = 50 # HP/Intel IA-64
235
+ EM_MIPS_X = 51 # Stanford MIPS-X
236
+ EM_COLDFIRE = 52 # Motorola Coldfire
237
+ EM_68HC12 = 53 # Motorola M68HC12
238
+ EM_MMA = 54 # Fujitsu Multimedia Accelerator
239
+ EM_PCP = 55 # Siemens PCP
240
+ EM_NCPU = 56 # Sony nCPU embedded RISC processor
241
+ EM_NDR1 = 57 # Denso NDR1 microprocessor
242
+ EM_STARCORE = 58 # Motorola Star*Core processor
243
+ EM_ME16 = 59 # Toyota ME16 processor
244
+ EM_ST100 = 60 # STMicroelectronics ST100 processor
245
+ EM_TINYJ = 61 # Advanced Logic Corp. TinyJ embedded processor
246
+ EM_X86_64 = 62 # AMD x86-64
247
+ EM_PDSP = 63 # Sony DSP Processor
248
+ EM_PDP10 = 64 # Digital Equipment Corp. PDP-10
249
+ EM_PDP11 = 65 # Digital Equipment Corp. PDP-11
250
+ EM_FX66 = 66 # Siemens FX66 microcontroller
251
+ EM_ST9PLUS = 67 # STMicroelectronics ST9+ 8/16 bit microcontroller
252
+ EM_ST7 = 68 # STMicroelectronics ST7 8-bit microcontroller
253
+ EM_68HC16 = 69 # Motorola MC68HC16 Microcontroller
254
+ EM_68HC11 = 70 # Motorola MC68HC11 Microcontroller
255
+ EM_68HC08 = 71 # Motorola MC68HC08 Microcontroller
256
+ EM_68HC05 = 72 # Motorola MC68HC05 Microcontroller
257
+ EM_SVX = 73 # Silicon Graphics SVx
258
+ EM_ST19 = 74 # STMicroelectronics ST19 8-bit cpu
259
+ EM_VAX = 75 # Digital VAX
260
+ EM_CRIS = 76 # Axis Communications 32-bit embedded processor
261
+ EM_JAVELIN = 77 # Infineon Technologies 32-bit embedded cpu
262
+ EM_FIREPATH = 78 # Element 14 64-bit DSP processor
263
+ EM_ZSP = 79 # LSI Logic's 16-bit DSP processor
264
+ EM_MMIX = 80 # Donald Knuth's educational 64-bit processor
265
+ EM_HUANY = 81 # Harvard's machine-independent format
266
+ EM_PRISM = 82 # SiTera Prism
267
+ EM_AVR = 83 # Atmel AVR 8-bit microcontroller
268
+ EM_FR30 = 84 # Fujitsu FR30
269
+ EM_D10V = 85 # Mitsubishi D10V
270
+ EM_D30V = 86 # Mitsubishi D30V
271
+ EM_V850 = 87 # Renesas V850
272
+ EM_M32R = 88 # Renesas M32R
273
+ EM_MN10300 = 89 # Matsushita MN10300
274
+ EM_MN10200 = 90 # Matsushita MN10200
275
+ EM_PJ = 91 # picoJava
276
+ EM_OPENRISC = 92 # OpenRISC 32-bit embedded processor
277
+ EM_ARC_COMPACT = 93 # ARC International ARCompact processor
278
+ EM_XTENSA = 94 # Tensilica Xtensa Architecture
279
+ EM_VIDEOCORE = 95 # Alphamosaic VideoCore processor
280
+ EM_TMM_GPP = 96 # Thompson Multimedia General Purpose Processor
281
+ EM_NS32K = 97 # National Semiconductor 32000 series
282
+ EM_TPC = 98 # Tenor Network TPC processor
283
+ EM_SNP1K = 99 # Trebia SNP 1000 processor
284
+ EM_ST200 = 100 # STMicroelectronics ST200 microcontroller
285
+ EM_IP2K = 101 # Ubicom IP2022 micro controller
286
+ EM_MAX = 102 # MAX Processor
287
+ EM_CR = 103 # National Semiconductor CompactRISC
288
+ EM_F2MC16 = 104 # Fujitsu F2MC16
289
+ EM_MSP430 = 105 # TI msp430 micro controller
290
+ EM_BLACKFIN = 106 # ADI Blackfin Processor
291
+ EM_SE_C33 = 107 # S1C33 Family of Seiko Epson processors
292
+ EM_SEP = 108 # Sharp embedded microprocessor
293
+ EM_ARCA = 109 # Arca RISC Microprocessor
294
+ EM_UNICORE = 110 # Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University
295
+ EM_EXCESS = 111 # eXcess: 16/32/64-bit configurable embedded CPU
296
+ EM_DXP = 112 # Icera Semiconductor Inc. Deep Execution Processor
297
+ EM_ALTERA_NIOS2 = 113 # Altera Nios II soft-core processor
298
+ EM_CRX = 114 # National Semiconductor CRX
299
+ EM_XGATE = 115 # Motorola XGATE embedded processor
300
+ EM_C116 = 116 # Infineon C16x/XC16x processor
301
+ EM_M16C = 117 # Renesas M16C series microprocessors
302
+ EM_DSPIC30F = 118 # Microchip Technology dsPIC30F Digital Signal Controller
303
+ EM_CE = 119 # Freescale Communication Engine RISC core
304
+ EM_M32C = 120 # Freescale Communication Engine RISC core
305
+ EM_TSK3000 = 131 # Altium TSK3000 core
306
+ EM_RS08 = 132 # Freescale RS08 embedded processor
307
+ EM_SHARC = 133 # Analog Devices SHARC family of 32-bit DSP processors
308
+ EM_ECOG2 = 134 # Cyan Technology eCOG2 microprocessor
309
+ EM_SCORE7 = 135 # Sunplus S+core7 RISC processor
310
+ EM_DSP24 = 136 # New Japan Radio (NJR) 24-bit DSP Processor
311
+ EM_VIDEOCORE3 = 137 # Broadcom VideoCore III processor
312
+ EM_LATTICEMICO32 = 138 # RISC processor for Lattice FPGA architecture
313
+ EM_SE_C17 = 139 # Seiko Epson C17 family
314
+ EM_TI_C6000 = 140 # The Texas Instruments TMS320C6000 DSP family
315
+ EM_TI_C2000 = 141 # The Texas Instruments TMS320C2000 DSP family
316
+ EM_TI_C5500 = 142 # The Texas Instruments TMS320C55x DSP family
317
+ EM_TI_ARP32 = 143 # Texas Instruments Application Specific RISC Processor, 32bit fetch
318
+ EM_TI_PRU = 144 # Texas Instruments Programmable Realtime Unit
319
+ EM_MMDSP_PLUS = 160 # STMicroelectronics 64bit VLIW Data Signal Processor
320
+ EM_CYPRESS_M8C = 161 # Cypress M8C microprocessor
321
+ EM_R32C = 162 # Renesas R32C series microprocessors
322
+ EM_TRIMEDIA = 163 # NXP Semiconductors TriMedia architecture family
323
+ EM_QDSP6 = 164 # QUALCOMM DSP6 Processor
324
+ EM_8051 = 165 # Intel 8051 and variants
325
+ EM_STXP7X = 166 # STMicroelectronics STxP7x family
326
+ EM_NDS32 = 167 # Andes Technology compact code size embedded RISC processor family
327
+ EM_ECOG1 = 168 # Cyan Technology eCOG1X family
328
+ EM_ECOG1X = 168 # Cyan Technology eCOG1X family
329
+ EM_MAXQ30 = 169 # Dallas Semiconductor MAXQ30 Core Micro-controllers
330
+ EM_XIMO16 = 170 # New Japan Radio (NJR) 16-bit DSP Processor
331
+ EM_MANIK = 171 # M2000 Reconfigurable RISC Microprocessor
332
+ EM_CRAYNV2 = 172 # Cray Inc. NV2 vector architecture
333
+ EM_RX = 173 # Renesas RX family
334
+ EM_METAG = 174 # Imagination Technologies Meta processor architecture
335
+ EM_MCST_ELBRUS = 175 # MCST Elbrus general purpose hardware architecture
336
+ EM_ECOG16 = 176 # Cyan Technology eCOG16 family
337
+ EM_CR16 = 177 # National Semiconductor CompactRISC 16-bit processor
338
+ EM_ETPU = 178 # Freescale Extended Time Processing Unit
339
+ EM_SLE9X = 179 # Infineon Technologies SLE9X core
340
+ EM_L1OM = 180 # Intel L1OM
341
+ EM_K1OM = 181 # Intel K1OM
342
+ EM_AARCH64 = 183 # ARM 64 bit
343
+ EM_AVR32 = 185 # Atmel Corporation 32-bit microprocessor family
344
+ EM_STM8 = 186 # STMicroeletronics STM8 8-bit microcontroller
345
+ EM_TILE64 = 187 # Tilera TILE64 multicore architecture family
346
+ EM_TILEPRO = 188 # Tilera TILEPro
347
+ EM_MICROBLAZE = 189 # Xilinx MicroBlaze
348
+ EM_CUDA = 190 # NVIDIA CUDA architecture
349
+ EM_TILEGX = 191 # Tilera TILE-Gx
350
+ EM_CLOUDSHIELD = 192 # CloudShield architecture family
351
+ EM_COREA_1ST = 193 # KIPO-KAIST Core-A 1st generation processor family
352
+ EM_COREA_2ND = 194 # KIPO-KAIST Core-A 2nd generation processor family
353
+ EM_ARC_COMPACT2 = 195 # Synopsys ARCompact V2
354
+ EM_OPEN8 = 196 # Open8 8-bit RISC soft processor core
355
+ EM_RL78 = 197 # Renesas RL78 family
356
+ EM_VIDEOCORE5 = 198 # Broadcom VideoCore V processor
357
+ EM_78K0R = 199 # Renesas 78K0R
358
+ EM_56800EX = 200 # Freescale 56800EX Digital Signal Controller (DSC)
359
+ EM_BA1 = 201 # Beyond BA1 CPU architecture
360
+ EM_BA2 = 202 # Beyond BA2 CPU architecture
361
+ EM_XCORE = 203 # XMOS xCORE processor family
362
+ EM_MCHP_PIC = 204 # Microchip 8-bit PIC(r) family
363
+ EM_INTELGT = 205 # Intel Graphics Technology
364
+ EM_KM32 = 210 # KM211 KM32 32-bit processor
365
+ EM_KMX32 = 211 # KM211 KMX32 32-bit processor
366
+ EM_KMX16 = 212 # KM211 KMX16 16-bit processor
367
+ EM_KMX8 = 213 # KM211 KMX8 8-bit processor
368
+ EM_KVARC = 214 # KM211 KVARC processor
369
+ EM_CDP = 215 # Paneve CDP architecture family
370
+ EM_COGE = 216 # Cognitive Smart Memory Processor
371
+ EM_COOL = 217 # Bluechip Systems CoolEngine
372
+ EM_NORC = 218 # Nanoradio Optimized RISC
373
+ EM_CSR_KALIMBA = 219 # CSR Kalimba architecture family
374
+ EM_Z80 = 220 # Zilog Z80
375
+ EM_VISIUM = 221 # Controls and Data Services VISIUMcore processor
376
+ EM_FT32 = 222 # FTDI Chip FT32 high performance 32-bit RISC architecture
377
+ EM_MOXIE = 223 # Moxie processor family
378
+ EM_AMDGPU = 224 # AMD GPU architecture
379
+ EM_LANAI = 244 # Lanai 32-bit processor
380
+ EM_CEVA = 245 # CEVA Processor Architecture Family
381
+ EM_CEVA_X2 = 246 # CEVA X2 Processor Family
382
+ EM_BPF = 247 # Linux BPF - in-kernel virtual machine
383
+ EM_GRAPHCORE_IPU = 248 # Graphcore Intelligent Processing Unit
384
+ EM_IMG1 = 249 # Imagination Technologies
385
+ EM_NFP = 250 # Netronome Flow Processor (NFP)
386
+ EM_VE = 251 # NEC Vector Engine
387
+ EM_CSKY = 252 # C-SKY processor family
388
+ EM_ARC_COMPACT3_64 = 253 # Synopsys ARCv2.3 64-bit
389
+ EM_MCS6502 = 254 # MOS Technology MCS 6502 processor
390
+ EM_ARC_COMPACT3 = 255 # Synopsys ARCv2.3 32-bit
391
+ EM_KVX = 256 # Kalray VLIW core of the MPPA processor family
392
+ EM_65816 = 257 # WDC 65816/65C816
393
+ EM_LOONGARCH = 258 # LoongArch
394
+ EM_KF32 = 259 # ChipON KungFu32
395
+ EM_U16_U8CORE = 260 # LAPIS nX-U16/U8
396
+ EM_TACHYUM = 261 # Tachyum
397
+ EM_56800EF = 262 # NXP 56800EF Digital Signal Controller (DSC)
398
+
399
+ EM_FRV = 0x5441 # Fujitsu FR-V
149
400
 
150
401
  # This is an interim value that we will use until the committee comes up with a final number.
151
- EM_ALPHA = 0x9026
402
+ EM_ALPHA = 0x9026
152
403
 
153
404
  # Bogus old m32r magic number, used by old tools.
154
- EM_CYGNUS_M32R = 0x9041
405
+ EM_CYGNUS_M32R = 0x9041
155
406
  # This is the old interim value for S/390 architecture
156
- EM_S390_OLD = 0xA390
407
+ EM_S390_OLD = 0xA390
157
408
  # Also Panasonic/MEI MN10300, AM33
158
- EM_CYGNUS_MN10300 = 0xbeef
409
+ EM_CYGNUS_MN10300 = 0xbeef
159
410
 
160
411
  # Return the architecture name according to +val+.
161
412
  # Used by {ELFTools::ELFFile#machine}.
@@ -191,7 +442,7 @@ module ELFTools
191
442
  end
192
443
  include EM
193
444
 
194
- # This module defines elf file types.
445
+ # This module defines ELF file types.
195
446
  module ET
196
447
  ET_NONE = 0 # no file type
197
448
  ET_REL = 1 # relocatable file
@@ -215,61 +466,209 @@ module ELFTools
215
466
 
216
467
  # Program header permission flags, records bitwise OR value in +p_flags+.
217
468
  module PF
218
- PF_X = 1
219
- PF_W = 2
220
- PF_R = 4
469
+ PF_X = 1 # executable
470
+ PF_W = 2 # writable
471
+ PF_R = 4 # readable
221
472
  end
222
473
  include PF
223
474
 
224
475
  # Program header types, records in +p_type+.
225
476
  module PT
226
- PT_NULL = 0 # null segment
227
- PT_LOAD = 1 # segment to be load
228
- PT_DYNAMIC = 2 # dynamic tags
229
- PT_INTERP = 3 # interpreter, same as .interp section
230
- PT_NOTE = 4 # same as .note* section
231
- PT_SHLIB = 5 # reserved
232
- PT_PHDR = 6 # where program header starts
233
- PT_TLS = 7 # thread local storage segment
234
- PT_LOOS = 0x60000000 # OS-specific
235
- PT_HIOS = 0x6fffffff # OS-specific
477
+ PT_NULL = 0 # null segment
478
+ PT_LOAD = 1 # segment to be load
479
+ PT_DYNAMIC = 2 # dynamic tags
480
+ PT_INTERP = 3 # interpreter, same as .interp section
481
+ PT_NOTE = 4 # same as .note* section
482
+ PT_SHLIB = 5 # reserved
483
+ PT_PHDR = 6 # where program header starts
484
+ PT_TLS = 7 # thread local storage segment
485
+
486
+ PT_LOOS = 0x60000000 # OS-specific
487
+ PT_GNU_EH_FRAME = 0x6474e550 # for exception handler
488
+ PT_GNU_STACK = 0x6474e551 # permission of stack
489
+ PT_GNU_RELRO = 0x6474e552 # read only after relocation
490
+ PT_GNU_PROPERTY = 0x6474e553 # GNU property
491
+ PT_GNU_MBIND_HI = 0x6474f554 # Mbind segments (upper bound)
492
+ PT_GNU_MBIND_LO = 0x6474e555 # Mbind segments (lower bound)
493
+ PT_OPENBSD_RANDOMIZE = 0x65a3dbe6 # Fill with random data
494
+ PT_OPENBSD_WXNEEDED = 0x65a3dbe7 # Program does W^X violations
495
+ PT_OPENBSD_BOOTDATA = 0x65a41be6 # Section for boot arguments
496
+ PT_HIOS = 0x6fffffff # OS-specific
497
+
236
498
  # Values between {PT_LOPROC} and {PT_HIPROC} are reserved for processor-specific semantics.
237
- PT_LOPROC = 0x70000000
238
- PT_HIPROC = 0x7fffffff # see {PT_LOPROC}
239
- PT_GNU_EH_FRAME = 0x6474e550 # for exception handler
240
- PT_GNU_STACK = 0x6474e551 # permission of stack
241
- PT_GNU_RELRO = 0x6474e552 # read only after relocation
499
+ PT_LOPROC = 0x70000000
500
+
501
+ PT_ARM_ARCHEXT = 0x70000000 # platform architecture compatibility information
502
+ PT_ARM_EXIDX = 0x70000001 # exception unwind tables
503
+
504
+ PT_MIPS_REGINFO = 0x70000000 # register usage information
505
+ PT_MIPS_RTPROC = 0x70000001 # runtime procedure table
506
+ PT_MIPS_OPTIONS = 0x70000002 # +.MIPS.options+ section
507
+ PT_MIPS_ABIFLAGS = 0x70000003 # +.MIPS.abiflags+ section
508
+
509
+ PT_AARCH64_ARCHEXT = 0x70000000 # platform architecture compatibility information
510
+ PT_AARCH64_UNWIND = 0x70000001 # exception unwind tables
511
+
512
+ PT_S390_PGSTE = 0x70000000 # 4k page table size
513
+
514
+ PT_HIPROC = 0x7fffffff # see {PT_LOPROC}
242
515
  end
243
516
  include PT
244
517
 
245
518
  # Special indices to section. These are used when there is no valid index to section header.
246
519
  # The meaning of these values is left upto the embedding header.
247
520
  module SHN
248
- SHN_UNDEF = 0 # undefined section
249
- SHN_LORESERVE = 0xff00 # start of reserved indices
521
+ SHN_UNDEF = 0 # undefined section
522
+ SHN_LORESERVE = 0xff00 # start of reserved indices
523
+
524
+ # Values between {SHN_LOPROC} and {SHN_HIPROC} are reserved for processor-specific semantics.
525
+ SHN_LOPROC = 0xff00
526
+
527
+ SHN_MIPS_ACOMMON = 0xff00 # defined and allocated common symbol
528
+ SHN_MIPS_TEXT = 0xff01 # defined and allocated text symbol
529
+ SHN_MIPS_DATA = 0xff02 # defined and allocated data symbol
530
+ SHN_MIPS_SCOMMON = 0xff03 # small common symbol
531
+ SHN_MIPS_SUNDEFINED = 0xff04 # small undefined symbol
532
+
533
+ SHN_X86_64_LCOMMON = 0xff02 # large common symbol
534
+
535
+ SHN_HIPROC = 0xff1f # see {SHN_LOPROC}
536
+
537
+ # Values between {SHN_LOOS} and {SHN_HIOS} are reserved for operating system-specific semantics.
538
+ SHN_LOOS = 0xff20
539
+ SHN_HIOS = 0xff3f # see {SHN_LOOS}
540
+ SHN_ABS = 0xfff1 # specifies absolute values for the corresponding reference
541
+ SHN_COMMON = 0xfff2 # symbols defined relative to this section are common symbols
542
+ SHN_XINDEX = 0xffff # escape value indicating that the actual section header index is too large to fit
543
+ SHN_HIRESERVE = 0xffff # end of reserved indices
250
544
  end
251
545
  include SHN
252
546
 
547
+ # Section flag mask types, records in +sh_flag+.
548
+ module SHF
549
+ SHF_WRITE = (1 << 0) # Writable
550
+ SHF_ALLOC = (1 << 1) # Occupies memory during execution
551
+ SHF_EXECINSTR = (1 << 2) # Executable
552
+ SHF_MERGE = (1 << 4) # Might be merged
553
+ SHF_STRINGS = (1 << 5) # Contains nul-terminated strings
554
+ SHF_INFO_LINK = (1 << 6) # `sh_info' contains SHT index
555
+ SHF_LINK_ORDER = (1 << 7) # Preserve order after combining
556
+ SHF_OS_NONCONFORMING = (1 << 8) # Non-standard OS specific handling required
557
+ SHF_GROUP = (1 << 9) # Section is member of a group.
558
+ SHF_TLS = (1 << 10) # Section hold thread-local data.
559
+ SHF_COMPRESSED = (1 << 11) # Section with compressed data.
560
+ SHF_MASKOS = 0x0ff00000 # OS-specific.
561
+ SHF_MASKPROC = 0xf0000000 # Processor-specific
562
+ SHF_GNU_RETAIN = (1 << 21) # Not to be GCed by linker.
563
+ SHF_GNU_MBIND = (1 << 24) # Mbind section
564
+ SHF_ORDERED = (1 << 30) # Special ordering requirement
565
+ SHF_EXCLUDE = (1 << 31) # Section is excluded unless referenced or allocated (Solaris).
566
+ end
567
+ include SHF
568
+
253
569
  # Section header types, records in +sh_type+.
254
570
  module SHT
255
- SHT_NULL = 0 # null section
256
- SHT_PROGBITS = 1 # information defined by program itself
257
- SHT_SYMTAB = 2 # symbol table section
258
- SHT_STRTAB = 3 # string table section
259
- SHT_RELA = 4 # relocation with addends
260
- SHT_HASH = 5 # symbol hash table
261
- SHT_DYNAMIC = 6 # information of dynamic linking
262
- SHT_NOTE = 7 # note section
263
- SHT_NOBITS = 8 # section occupies no space
264
- SHT_REL = 9 # relocation
265
- SHT_SHLIB = 10 # reserved
266
- SHT_DYNSYM = 11 # symbols for dynamic
571
+ SHT_NULL = 0 # null section
572
+ SHT_PROGBITS = 1 # information defined by program itself
573
+ SHT_SYMTAB = 2 # symbol table section
574
+ SHT_STRTAB = 3 # string table section
575
+ SHT_RELA = 4 # relocation with addends
576
+ SHT_HASH = 5 # symbol hash table
577
+ SHT_DYNAMIC = 6 # information of dynamic linking
578
+ SHT_NOTE = 7 # section for notes
579
+ SHT_NOBITS = 8 # section occupies no space
580
+ SHT_REL = 9 # relocation
581
+ SHT_SHLIB = 10 # reserved
582
+ SHT_DYNSYM = 11 # symbols for dynamic
583
+ SHT_INIT_ARRAY = 14 # array of initialization functions
584
+ SHT_FINI_ARRAY = 15 # array of termination functions
585
+ SHT_PREINIT_ARRAY = 16 # array of functions that are invoked before all other initialization functions
586
+ SHT_GROUP = 17 # section group
587
+ SHT_SYMTAB_SHNDX = 18 # indices for SHN_XINDEX entries
588
+ SHT_RELR = 19 # RELR relative relocations
589
+
590
+ # Values between {SHT_LOOS} and {SHT_HIOS} are reserved for operating system-specific semantics.
591
+ SHT_LOOS = 0x60000000
592
+ SHT_GNU_INCREMENTAL_INPUTS = 0x6fff4700 # incremental build data
593
+ SHT_GNU_INCREMENTAL_SYMTAB = 0x6fff4701 # incremental build data
594
+ SHT_GNU_INCREMENTAL_RELOCS = 0x6fff4702 # incremental build data
595
+ SHT_GNU_INCREMENTAL_GOT_PLT = 0x6fff4703 # incremental build data
596
+ SHT_GNU_ATTRIBUTES = 0x6ffffff5 # object attributes
597
+ SHT_GNU_HASH = 0x6ffffff6 # GNU style symbol hash table
598
+ SHT_GNU_LIBLIST = 0x6ffffff7 # list of prelink dependencies
599
+ SHT_SUNW_verdef = 0x6ffffffd # versions defined by file
600
+ SHT_GNU_verdef = 0x6ffffffd # versions defined by file
601
+ SHT_SUNW_verneed = 0x6ffffffe # versions needed by file
602
+ SHT_GNU_verneed = 0x6ffffffe # versions needed by file
603
+ SHT_SUNW_versym = 0x6fffffff # symbol versions
604
+ SHT_GNU_versym = 0x6fffffff # symbol versions
605
+ SHT_HIOS = 0x6fffffff # see {SHT_LOOS}
606
+
267
607
  # Values between {SHT_LOPROC} and {SHT_HIPROC} are reserved for processor-specific semantics.
268
- SHT_LOPROC = 0x70000000
269
- SHT_HIPROC = 0x7fffffff # see {SHT_LOPROC}
608
+ SHT_LOPROC = 0x70000000
609
+
610
+ SHT_SPARC_GOTDATA = 0x70000000 # :nodoc:
611
+
612
+ SHT_ARM_EXIDX = 0x70000001 # exception index table
613
+ SHT_ARM_PREEMPTMAP = 0x70000002 # BPABI DLL dynamic linking pre-emption map
614
+ SHT_ARM_ATTRIBUTES = 0x70000003 # object file compatibility attributes
615
+ SHT_ARM_DEBUGOVERLAY = 0x70000004 # support for debugging overlaid programs
616
+ SHT_ARM_OVERLAYSECTION = 0x70000005 # support for debugging overlaid programs
617
+
618
+ SHT_X86_64_UNWIND = 0x70000001 # x86_64 unwind information
619
+
620
+ SHT_MIPS_LIBLIST = 0x70000000 # set of dynamic shared objects
621
+ SHT_MIPS_MSYM = 0x70000001 # :nodoc:
622
+ SHT_MIPS_CONFLICT = 0x70000002 # list of symbols whose definitions conflict with shared objects
623
+ SHT_MIPS_GPTAB = 0x70000003 # global pointer table
624
+ SHT_MIPS_UCODE = 0x70000004 # microcode information
625
+ SHT_MIPS_DEBUG = 0x70000005 # register usage information
626
+ SHT_MIPS_REGINFO = 0x70000006 # section contains register usage information
627
+ SHT_MIPS_PACKAGE = 0x70000007 # :nodoc:
628
+ SHT_MIPS_PACKSYM = 0x70000008 # :nodoc:
629
+ SHT_MIPS_RELD = 0x70000009 # :nodoc:
630
+ SHT_MIPS_IFACE = 0x7000000b # interface information
631
+ SHT_MIPS_CONTENT = 0x7000000c # description of contents of another section
632
+ SHT_MIPS_OPTIONS = 0x7000000d # miscellaneous options
633
+ SHT_MIPS_SHDR = 0x70000010 # :nodoc:
634
+ SHT_MIPS_FDESC = 0x70000011 # :nodoc:
635
+ SHT_MIPS_EXTSYM = 0x70000012 # :nodoc:
636
+ SHT_MIPS_DENSE = 0x70000013 # :nodoc:
637
+ SHT_MIPS_PDESC = 0x70000014 # :nodoc:
638
+ SHT_MIPS_LOCSYM = 0x70000015 # :nodoc:
639
+ SHT_MIPS_AUXSYM = 0x70000016 # :nodoc:
640
+ SHT_MIPS_OPTSYM = 0x70000017 # :nodoc:
641
+ SHT_MIPS_LOCSTR = 0x70000018 # :nodoc:
642
+ SHT_MIPS_LINE = 0x70000019 # :nodoc:
643
+ SHT_MIPS_RFDESC = 0x7000001a # :nodoc:
644
+ SHT_MIPS_DELTASYM = 0x7000001b # delta C++ symbol table
645
+ SHT_MIPS_DELTAINST = 0x7000001c # delta C++ instance table
646
+ SHT_MIPS_DELTACLASS = 0x7000001d # delta C++ class table
647
+ SHT_MIPS_DWARF = 0x7000001e # DWARF debugging section
648
+ SHT_MIPS_DELTADECL = 0x7000001f # delta C++ declarations
649
+ SHT_MIPS_SYMBOL_LIB = 0x70000020 # list of libraries the binary depends on
650
+ SHT_MIPS_EVENTS = 0x70000021 # events section
651
+ SHT_MIPS_TRANSLATE = 0x70000022 # :nodoc:
652
+ SHT_MIPS_PIXIE = 0x70000023 # :nodoc:
653
+ SHT_MIPS_XLATE = 0x70000024 # address translation table
654
+ SHT_MIPS_XLATE_DEBUG = 0x70000025 # SGI internal address translation table
655
+ SHT_MIPS_WHIRL = 0x70000026 # intermediate code
656
+ SHT_MIPS_EH_REGION = 0x70000027 # C++ exception handling region info
657
+ SHT_MIPS_PDR_EXCEPTION = 0x70000029 # runtime procedure descriptor table exception information
658
+ SHT_MIPS_ABIFLAGS = 0x7000002a # ABI related flags
659
+ SHT_MIPS_XHASH = 0x7000002b # GNU style symbol hash table with xlat
660
+
661
+ SHT_AARCH64_ATTRIBUTES = 0x70000003 # :nodoc:
662
+
663
+ SHT_CSKY_ATTRIBUTES = 0x70000001 # object file compatibility attributes
664
+
665
+ SHT_ORDERED = 0x7fffffff # :nodoc:
666
+
667
+ SHT_HIPROC = 0x7fffffff # see {SHT_LOPROC}
668
+
270
669
  # Values between {SHT_LOUSER} and {SHT_HIUSER} are reserved for application programs.
271
- SHT_LOUSER = 0x80000000
272
- SHT_HIUSER = 0xffffffff # see {SHT_LOUSER}
670
+ SHT_LOUSER = 0x80000000
671
+ SHT_HIUSER = 0xffffffff # see {SHT_LOUSER}
273
672
  end
274
673
  include SHT
275
674
 
@@ -296,7 +695,9 @@ module ELFTools
296
695
  STT_FILE = 4 # Symbol's name is file name
297
696
  STT_COMMON = 5 # Symbol is a common data object
298
697
  STT_TLS = 6 # Symbol is thread-local data object
299
- STT_NUM = 7 # Number of defined types.
698
+ STT_NUM = 7 # Deprecated.
699
+ STT_RELC = 8 # Complex relocation expression
700
+ STT_SRELC = 9 # Signed Complex relocation expression
300
701
 
301
702
  # GNU extension: symbol value points to a function which is called
302
703
  # at runtime to determine the final value of the symbol.
@@ -314,6 +715,7 @@ module ELFTools
314
715
  # ARM: a THUMB function. This is not defined in ARM ELF Specification but
315
716
  # used by the GNU tool-chain.
316
717
  STT_ARM_TFUNC = 13
718
+ STT_ARM_16BIT = 15 # ARM: a THUMB label.
317
719
  end
318
720
  include STT
319
721
  end
@@ -318,7 +318,7 @@ module ELFTools
318
318
  patches.each do |pos, val|
319
319
  all[pos, val.size] = val
320
320
  end
321
- IO.binwrite(filename, all)
321
+ File.binwrite(filename, all)
322
322
  end
323
323
 
324
324
  private
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'delegate'
4
+
3
5
  module ELFTools
4
6
  # A helper class for {ELFTools} easy to implement
5
7
  # 'lazy loading' objects.
6
8
  # Mainly used when loading sections, segments, and
7
9
  # symbols.
8
- class LazyArray
10
+ class LazyArray < SimpleDelegator
9
11
  # Instantiate a {LazyArray} object.
10
12
  # @param [Integer] size
11
13
  # The size of array.
@@ -26,7 +28,7 @@ module ELFTools
26
28
  # p arr[3]
27
29
  # # 9
28
30
  def initialize(size, &block)
29
- @internal = Array.new(size)
31
+ super(Array.new(size))
30
32
  @block = block
31
33
  end
32
34
 
@@ -39,9 +41,9 @@ module ELFTools
39
41
  # return type of block given in {#initialize}.
40
42
  def [](i)
41
43
  # XXX: support negative index?
42
- return nil unless i.between?(0, @internal.size - 1)
44
+ return nil unless i.between?(0, __getobj__.size - 1)
43
45
 
44
- @internal[i] ||= @block.call(i)
46
+ __getobj__[i] ||= @block.call(i)
45
47
  end
46
48
  end
47
49
  end
@@ -11,9 +11,9 @@ module ELFTools
11
11
  # The base structure to define common methods.
12
12
  class ELFStruct < BinData::Record
13
13
  # DRY. Many fields have different type in different arch.
14
- CHOICE_SIZE_T = {
15
- selection: :elf_class, choices: { 32 => :uint32, 64 => :uint64 }
16
- }.freeze
14
+ CHOICE_SIZE_T = proc do |t = 'uint'|
15
+ { selection: :elf_class, choices: { 32 => :"#{t}32", 64 => :"#{t}64" }, copy_on_change: true }
16
+ end
17
17
 
18
18
  attr_accessor :elf_class # @return [Integer] 32 or 64.
19
19
  attr_accessor :offset # @return [Integer] The file offset of this header.
@@ -24,6 +24,9 @@ module ELFTools
24
24
  @patches ||= {}
25
25
  end
26
26
 
27
+ # BinData hash(Snapshot) that behaves like HashWithIndifferentAccess
28
+ alias to_h snapshot
29
+
27
30
  class << self
28
31
  # Hooks the constructor.
29
32
  #
@@ -51,7 +54,7 @@ module ELFTools
51
54
  # Gets the endianness of current class.
52
55
  # @return [:little, :big] The endianness.
53
56
  def self_endian
54
- bindata_name[-2..-1] == 'be' ? :big : :little
57
+ bindata_name[-2..] == 'be' ? :big : :little
55
58
  end
56
59
 
57
60
  # Packs an integer to string.
@@ -89,9 +92,9 @@ module ELFTools
89
92
  uint16 :e_machine
90
93
  uint32 :e_version
91
94
  # entry point
92
- choice :e_entry, **CHOICE_SIZE_T
93
- choice :e_phoff, **CHOICE_SIZE_T
94
- choice :e_shoff, **CHOICE_SIZE_T
95
+ choice :e_entry, **CHOICE_SIZE_T['uint']
96
+ choice :e_phoff, **CHOICE_SIZE_T['uint']
97
+ choice :e_shoff, **CHOICE_SIZE_T['uint']
95
98
  uint32 :e_flags
96
99
  uint16 :e_ehsize # size of this header
97
100
  uint16 :e_phentsize # size of each segment
@@ -106,14 +109,14 @@ module ELFTools
106
109
  endian :big_and_little
107
110
  uint32 :sh_name
108
111
  uint32 :sh_type
109
- choice :sh_flags, **CHOICE_SIZE_T
110
- choice :sh_addr, **CHOICE_SIZE_T
111
- choice :sh_offset, **CHOICE_SIZE_T
112
- choice :sh_size, **CHOICE_SIZE_T
112
+ choice :sh_flags, **CHOICE_SIZE_T['uint']
113
+ choice :sh_addr, **CHOICE_SIZE_T['uint']
114
+ choice :sh_offset, **CHOICE_SIZE_T['uint']
115
+ choice :sh_size, **CHOICE_SIZE_T['uint']
113
116
  uint32 :sh_link
114
117
  uint32 :sh_info
115
- choice :sh_addralign, **CHOICE_SIZE_T
116
- choice :sh_entsize, **CHOICE_SIZE_T
118
+ choice :sh_addralign, **CHOICE_SIZE_T['uint']
119
+ choice :sh_entsize, **CHOICE_SIZE_T['uint']
117
120
  end
118
121
 
119
122
  # Program header structure for 32-bit.
@@ -187,25 +190,30 @@ module ELFTools
187
190
  # Dynamic tag header.
188
191
  class ELF_Dyn < ELFStruct
189
192
  endian :big_and_little
190
- choice :d_tag, selection: :elf_class, choices: { 32 => :int32, 64 => :int64 }
193
+ choice :d_tag, **CHOICE_SIZE_T['int']
191
194
  # This is an union type named +d_un+ in original source,
192
195
  # simplify it to be +d_val+ here.
193
- choice :d_val, **CHOICE_SIZE_T
196
+ choice :d_val, **CHOICE_SIZE_T['uint']
194
197
  end
195
198
 
196
199
  # Rel header in .rel section.
197
200
  class ELF_Rel < ELFStruct
198
201
  endian :big_and_little
199
- choice :r_offset, **CHOICE_SIZE_T
200
- choice :r_info, **CHOICE_SIZE_T
202
+ choice :r_offset, **CHOICE_SIZE_T['uint']
203
+ choice :r_info, **CHOICE_SIZE_T['uint']
204
+
205
+ # Compatibility with ELF_Rela, both can be used interchangeably
206
+ def r_addend
207
+ nil
208
+ end
201
209
  end
202
210
 
203
211
  # Rela header in .rela section.
204
212
  class ELF_Rela < ELFStruct
205
213
  endian :big_and_little
206
- choice :r_offset, **CHOICE_SIZE_T
207
- choice :r_info, **CHOICE_SIZE_T
208
- choice :r_addend, selection: :elf_class, choices: { 32 => :int32, 64 => :int64 }
214
+ choice :r_offset, **CHOICE_SIZE_T['uint']
215
+ choice :r_info, **CHOICE_SIZE_T['uint']
216
+ choice :r_addend, **CHOICE_SIZE_T['int']
209
217
  end
210
218
  end
211
219
  end
data/lib/elftools/util.rb CHANGED
@@ -44,7 +44,7 @@ module ELFTools
44
44
  end
45
45
  val = val.to_s.upcase
46
46
  prefix = module_name.split('::')[-1]
47
- val = prefix + '_' + val unless val.start_with?(prefix)
47
+ val = "#{prefix}_#{val}" unless val.start_with?(prefix)
48
48
  val = val.to_sym
49
49
  raise ArgumentError, "No constants in #{module_name} named \"#{val}\"" unless mod.const_defined?(val)
50
50
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  module ELFTools
4
4
  # Current gem version
5
- VERSION = '1.1.3'
5
+ VERSION = '1.2.0'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elftools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - david942j
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-09 00:00:00.000000000 Z
11
+ date: 2022-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: os
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: pry
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -72,28 +86,28 @@ dependencies:
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '0.59'
89
+ version: '1'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '0.59'
96
+ version: '1'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: simplecov
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '0.17'
103
+ version: '0.21'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '0.17'
110
+ version: '0.21'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: yard
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -145,7 +159,8 @@ files:
145
159
  homepage: https://github.com/david942j/rbelftools
146
160
  licenses:
147
161
  - MIT
148
- metadata: {}
162
+ metadata:
163
+ rubygems_mfa_required: 'true'
149
164
  post_install_message:
150
165
  rdoc_options: []
151
166
  require_paths:
@@ -154,14 +169,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
169
  requirements:
155
170
  - - ">="
156
171
  - !ruby/object:Gem::Version
157
- version: '2.3'
172
+ version: '2.6'
158
173
  required_rubygems_version: !ruby/object:Gem::Requirement
159
174
  requirements:
160
175
  - - ">="
161
176
  - !ruby/object:Gem::Version
162
177
  version: '0'
163
178
  requirements: []
164
- rubygems_version: 3.1.2
179
+ rubygems_version: 3.1.6
165
180
  signing_key:
166
181
  specification_version: 4
167
182
  summary: ELFTools - Pure ruby library for parsing and patching ELF files