elf_utils 0.3.0
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/.rspec +3 -0
- data/.standard.yml +3 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/CONTRIBUTING.md +55 -0
- data/Gemfile +23 -0
- data/LICENSE.txt +21 -0
- data/MAINTAINERS.md +3 -0
- data/README.md +126 -0
- data/Rakefile +76 -0
- data/SECURITY.md +57 -0
- data/elf_utils.gemspec +41 -0
- data/ext/elf_utils/elf_utils.c +53 -0
- data/ext/elf_utils/extconf.rb +3 -0
- data/lib/elf_utils/elf_file.rb +312 -0
- data/lib/elf_utils/section/base.rb +77 -0
- data/lib/elf_utils/section/debug_abbrev/abbreviation.rb +171 -0
- data/lib/elf_utils/section/debug_abbrev/abbreviation_table.rb +27 -0
- data/lib/elf_utils/section/debug_abbrev.rb +15 -0
- data/lib/elf_utils/section/debug_addr.rb +9 -0
- data/lib/elf_utils/section/debug_arange.rb +54 -0
- data/lib/elf_utils/section/debug_info/compilation_unit.rb +189 -0
- data/lib/elf_utils/section/debug_info/debug_str_offsets_ref.rb +15 -0
- data/lib/elf_utils/section/debug_info/debug_str_ref.rb +17 -0
- data/lib/elf_utils/section/debug_info/die/base.rb +130 -0
- data/lib/elf_utils/section/debug_info/die.rb +470 -0
- data/lib/elf_utils/section/debug_info/die_ref.rb +22 -0
- data/lib/elf_utils/section/debug_info/header.rb +26 -0
- data/lib/elf_utils/section/debug_info.rb +93 -0
- data/lib/elf_utils/section/debug_line/line_number_program/header.rb +48 -0
- data/lib/elf_utils/section/debug_line/line_number_program/state_machine.rb +206 -0
- data/lib/elf_utils/section/debug_line/line_number_program.rb +134 -0
- data/lib/elf_utils/section/debug_line.rb +35 -0
- data/lib/elf_utils/section/debug_ranges.rb +22 -0
- data/lib/elf_utils/section/debug_str_offsets.rb +16 -0
- data/lib/elf_utils/section/dynsym.rb +14 -0
- data/lib/elf_utils/section/strtab.rb +9 -0
- data/lib/elf_utils/section/symtab.rb +11 -0
- data/lib/elf_utils/section.rb +50 -0
- data/lib/elf_utils/segment/base.rb +72 -0
- data/lib/elf_utils/segment.rb +9 -0
- data/lib/elf_utils/string_pread.rb +18 -0
- data/lib/elf_utils/symbol.rb +144 -0
- data/lib/elf_utils/types/dwarf/expression.rb +34 -0
- data/lib/elf_utils/types/dwarf.rb +639 -0
- data/lib/elf_utils/types/dwarf32/v2.rb +44 -0
- data/lib/elf_utils/types/dwarf32/v3.rb +40 -0
- data/lib/elf_utils/types/dwarf32/v4.rb +41 -0
- data/lib/elf_utils/types/dwarf32/v5.rb +44 -0
- data/lib/elf_utils/types/dwarf32.rb +12 -0
- data/lib/elf_utils/types/dwarf64/v3.rb +42 -0
- data/lib/elf_utils/types/dwarf64/v4.rb +43 -0
- data/lib/elf_utils/types/dwarf64/v5.rb +46 -0
- data/lib/elf_utils/types/dwarf64.rb +8 -0
- data/lib/elf_utils/types/sleb128.rb +66 -0
- data/lib/elf_utils/types/uleb128.rb +56 -0
- data/lib/elf_utils/types/unit_length.rb +51 -0
- data/lib/elf_utils/types.rb +328 -0
- data/lib/elf_utils/version.rb +5 -0
- data/lib/elf_utils.rb +83 -0
- data/sig/elf_utils.rbs +4 -0
- metadata +120 -0
@@ -0,0 +1,328 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ctypes"
|
4
|
+
|
5
|
+
# The various types & structures needed to parse the ELF & DWARF formats.
|
6
|
+
#
|
7
|
+
# @api private
|
8
|
+
module ElfUtils::Types
|
9
|
+
extend CTypes::Helpers
|
10
|
+
extend self
|
11
|
+
|
12
|
+
Elf_Ident = struct({
|
13
|
+
ei_magic: string(4),
|
14
|
+
ei_class: uint8,
|
15
|
+
ei_data: enum(uint8, {none: 0, lsb: 1, msb: 2}),
|
16
|
+
ei_version: uint8,
|
17
|
+
ei_osabi: uint8,
|
18
|
+
ei_abiversion: uint8,
|
19
|
+
ei_pad: array(uint8, 7)
|
20
|
+
})
|
21
|
+
ELFMAGIC = "\x7fELF"
|
22
|
+
ELFCLASS32 = 1
|
23
|
+
ELFCLASS64 = 2
|
24
|
+
|
25
|
+
# Elf file types
|
26
|
+
Elf_Et = enum(uint16, %(none rel exec dyn core)).permissive
|
27
|
+
|
28
|
+
## Elf Program Header Types
|
29
|
+
Elf_Pt = enum(uint32, {
|
30
|
+
null: 0, # program header table entry unused
|
31
|
+
load: 1, # loadable program segment
|
32
|
+
dynamic: 2, # dynamic linking information
|
33
|
+
interp: 3, # program interpreter
|
34
|
+
note: 4, # auxiliary information
|
35
|
+
shlib: 5, # reserved
|
36
|
+
phdr: 6, # entry for header table itself
|
37
|
+
tls: 7, # thread-local storage segment
|
38
|
+
num: 8, # number of defined types
|
39
|
+
loos: 0x60000000, # start of os-specific
|
40
|
+
gnu_eh_frame: 0x6474e550, # gcc .eh_frame_hdr segment
|
41
|
+
gnu_stack: 0x6474e551, # indicates stack executability
|
42
|
+
gnu_relro: 0x6474e552, # read-only after relocation
|
43
|
+
gnu_property: 0x6474e553, # gnu property
|
44
|
+
sunwbss: 0x6ffffffa, # sun specific segment
|
45
|
+
sunwstack: 0x6ffffffb # stack segment
|
46
|
+
}).permissive
|
47
|
+
|
48
|
+
# Elf file types
|
49
|
+
Elf_Pf = enum(uint32, %i[exec write read]).permissive
|
50
|
+
|
51
|
+
# special section header numbers
|
52
|
+
SHN_UNDEF = 0 # Undefined section
|
53
|
+
SHN_LORESERVE = 0xff00 # Start of reserved indices
|
54
|
+
SHN_LOPROC = 0xff00 # Start of processor-specific
|
55
|
+
SHN_BEFORE = 0xff00 # Order section before all others (Solaris).
|
56
|
+
SHN_AFTER = 0xff01 # Order section after all others (Solaris).
|
57
|
+
SHN_HIPROC = 0xff1f # End of processor-specific
|
58
|
+
SHN_LOOS = 0xff20 # Start of OS-specific
|
59
|
+
SHN_HIOS = 0xff3f # End of OS-specific
|
60
|
+
SHN_ABS = 0xfff1 # Associated symbol is absolute
|
61
|
+
SHN_COMMON = 0xfff2 # Associated symbol is common
|
62
|
+
SHN_XINDEX = 0xffff # Index is in extra table.
|
63
|
+
SHN_HIRESERVE = 0xffff # End of reserved indices
|
64
|
+
|
65
|
+
## Elf Section Header Types
|
66
|
+
Elf_Sht = enum(uint32, {
|
67
|
+
null: 0, # section header table entry unused
|
68
|
+
progbits: 1, # program data
|
69
|
+
symtab: 2, # symbol table
|
70
|
+
strtab: 3, # string table
|
71
|
+
rela: 4, # relocation entries with addends
|
72
|
+
hash: 5, # symbol hash table
|
73
|
+
dynamic: 6, # dynamic linking information
|
74
|
+
note: 7, # notes
|
75
|
+
nobits: 8, # program space with no data (bss)
|
76
|
+
rel: 9, # relocation entries, no addends
|
77
|
+
shlib: 10, # reserved
|
78
|
+
dynsym: 11, # dynamic linker symbol table
|
79
|
+
init_array: 14, # array of constructors
|
80
|
+
fini_array: 15, # array of destructors
|
81
|
+
preinit_array: 16, # array of pre-constructors
|
82
|
+
group: 17, # section group
|
83
|
+
symtab_shndx: 18, # extended section indices
|
84
|
+
num: 19, # number of defined types.
|
85
|
+
gnu_attributes: 0x6ffffff5, # object attributes.
|
86
|
+
gnu_hash: 0x6ffffff6, # gnu-style hash table.
|
87
|
+
gnu_liblist: 0x6ffffff7, # prelink library list
|
88
|
+
checksum: 0x6ffffff8, # checksum for dso content.
|
89
|
+
sunw_move: 0x6ffffffa,
|
90
|
+
sunw_comdat: 0x6ffffffb,
|
91
|
+
sunw_syminfo: 0x6ffffffc,
|
92
|
+
gnu_verdef: 0x6ffffffd, # version definition section.
|
93
|
+
gnu_verneed: 0x6ffffffe, # version needs section.
|
94
|
+
gnu_versym: 0x6fffffff # version symbol table.
|
95
|
+
}).permissive
|
96
|
+
|
97
|
+
# ELF section header flag bits
|
98
|
+
Elf_Shf = enum(uint8, {
|
99
|
+
write: 0, # writable
|
100
|
+
alloc: 1, # occupies memory during execution
|
101
|
+
execinstr: 2, # executable
|
102
|
+
merge: 4, # might be merged
|
103
|
+
strings: 5, # contains nul-terminated strings
|
104
|
+
info_link: 6, # `sh_info' contains sht index
|
105
|
+
link_order: 7, # preserve order after combining
|
106
|
+
os_nonconforming: 8, # non-standard os specific handling required
|
107
|
+
group: 9, # section is member of a group.
|
108
|
+
tls: 10, # section hold thread-local data.
|
109
|
+
compressed: 11, # section with compressed data.
|
110
|
+
gnu_retain: 21, # not to be gced by linker.
|
111
|
+
ordered: 30, # special ordering requirement (solaris).
|
112
|
+
exclude: 31 # section is excluded unless referenced or allocated (solaris).
|
113
|
+
}).permissive
|
114
|
+
|
115
|
+
## Elf Symbol Types
|
116
|
+
Elf_Stt = [ # standard:disable Naming/ConstantName
|
117
|
+
:notype,
|
118
|
+
:object,
|
119
|
+
:func,
|
120
|
+
:section,
|
121
|
+
:file,
|
122
|
+
:common,
|
123
|
+
:tls,
|
124
|
+
:unused_7,
|
125
|
+
:unused_8,
|
126
|
+
:unused_9,
|
127
|
+
:os_10,
|
128
|
+
:os_11,
|
129
|
+
:os_12,
|
130
|
+
:proc_13,
|
131
|
+
:proc_14,
|
132
|
+
:proc_15
|
133
|
+
]
|
134
|
+
|
135
|
+
Elf32_Addr = uint32
|
136
|
+
Elf32_Chdr = struct({ch_type: uint32, ch_size: uint32, ch_addralign: uint32})
|
137
|
+
Elf32_Conflict = uint32
|
138
|
+
Elf32_Dyn = struct({d_tag: int32, d_un: union({d_val: uint32, d_ptr: uint32})})
|
139
|
+
Elf32_Ehdr = struct({e_ident: Elf_Ident,
|
140
|
+
e_type: Elf_Et,
|
141
|
+
e_machine: uint16,
|
142
|
+
e_version: uint32,
|
143
|
+
e_entry: uint32,
|
144
|
+
e_phoff: uint32,
|
145
|
+
e_shoff: uint32,
|
146
|
+
e_flags: uint32,
|
147
|
+
e_ehsize: uint16,
|
148
|
+
e_phentsize: uint16,
|
149
|
+
e_phnum: uint16,
|
150
|
+
e_shentsize: uint16,
|
151
|
+
e_shnum: uint16,
|
152
|
+
e_shstrndx: uint16})
|
153
|
+
Elf32_Half = uint16
|
154
|
+
Elf32_Lib = struct({l_name: uint32,
|
155
|
+
l_time_stamp: uint32,
|
156
|
+
l_checksum: uint32,
|
157
|
+
l_version: uint32,
|
158
|
+
l_flags: uint32})
|
159
|
+
Elf32_Move = struct({m_value: uint64,
|
160
|
+
m_info: uint32,
|
161
|
+
m_poffset: uint32,
|
162
|
+
m_repeat: uint16,
|
163
|
+
m_stride: uint16})
|
164
|
+
Elf32_Nhdr = struct({n_namesz: uint32, n_descsz: uint32, n_type: uint32})
|
165
|
+
Elf32_Off = uint32
|
166
|
+
Elf32_Phdr = struct({p_type: Elf_Pt,
|
167
|
+
p_offset: uint32,
|
168
|
+
p_vaddr: uint32,
|
169
|
+
p_paddr: uint32,
|
170
|
+
p_filesz: uint32,
|
171
|
+
p_memsz: uint32,
|
172
|
+
p_flags: bitmap(uint32, Elf_Pf),
|
173
|
+
p_align: uint32})
|
174
|
+
Elf32_RegInfo = struct({ri_gprmask: uint32,
|
175
|
+
ri_cprmask: array(uint32, 4),
|
176
|
+
ri_gp_value: int32})
|
177
|
+
Elf32_Rel = struct({r_offset: uint32, r_info: uint32})
|
178
|
+
Elf32_Rela = struct({r_offset: uint32, r_info: uint32, r_addend: int32})
|
179
|
+
Elf32_Section = uint16
|
180
|
+
Elf32_Shdr = struct({sh_name: uint32,
|
181
|
+
sh_type: Elf_Sht,
|
182
|
+
sh_flags: bitmap(uint32, Elf_Shf),
|
183
|
+
sh_addr: uint32,
|
184
|
+
sh_offset: uint32,
|
185
|
+
sh_size: uint32,
|
186
|
+
sh_link: uint32,
|
187
|
+
sh_info: uint32,
|
188
|
+
sh_addralign: uint32,
|
189
|
+
sh_entsize: uint32})
|
190
|
+
Elf32_Sword = int32
|
191
|
+
Elf32_Sxword = int64
|
192
|
+
Elf32_Sym = struct({st_name: uint32,
|
193
|
+
st_value: uint32,
|
194
|
+
st_size: uint32,
|
195
|
+
st_info: uint8,
|
196
|
+
st_other: uint8,
|
197
|
+
st_shndx: uint16})
|
198
|
+
Elf32_Syminfo = struct({si_boundto: uint16, si_flags: uint16})
|
199
|
+
Elf32_Verdaux = struct({vda_name: uint32, vda_next: uint32})
|
200
|
+
Elf32_Verdef = struct({vd_version: uint16,
|
201
|
+
vd_flags: uint16,
|
202
|
+
vd_ndx: uint16,
|
203
|
+
vd_cnt: uint16,
|
204
|
+
vd_hash: uint32,
|
205
|
+
vd_aux: uint32,
|
206
|
+
vd_next: uint32})
|
207
|
+
Elf32_Vernaux = struct({vna_hash: uint32,
|
208
|
+
vna_flags: uint16,
|
209
|
+
vna_other: uint16,
|
210
|
+
vna_name: uint32,
|
211
|
+
vna_next: uint32})
|
212
|
+
Elf32_Verneed = struct({vn_version: uint16,
|
213
|
+
vn_cnt: uint16,
|
214
|
+
vn_file: uint32,
|
215
|
+
vn_aux: uint32,
|
216
|
+
vn_next: uint32})
|
217
|
+
Elf32_Versym = uint16
|
218
|
+
Elf32_Word = uint32
|
219
|
+
Elf32_Xword = uint64
|
220
|
+
Elf32_auxv_t = struct({a_type: uint32, a_un: union({a_val: uint32})})
|
221
|
+
Elf32_gptab = union({gt_thing: struct({gt_g_value: uint32, gt_bytes: uint32}),
|
222
|
+
gt_header: struct({gt_current_g_value: uint32, gt_unused: uint32}),
|
223
|
+
gt_entry: struct({gt_g_value: uint32, gt_bytes: uint32})})
|
224
|
+
Elf64_Addr = uint64
|
225
|
+
Elf64_Chdr = struct({ch_type: uint32,
|
226
|
+
ch_reserved: uint32,
|
227
|
+
ch_size: uint64,
|
228
|
+
ch_addralign: uint64})
|
229
|
+
Elf64_Dyn = struct({d_tag: int64, d_un: union({d_val: uint64, d_ptr: uint64})})
|
230
|
+
Elf64_Ehdr = struct({e_ident: Elf_Ident,
|
231
|
+
e_type: Elf_Et,
|
232
|
+
e_machine: uint16,
|
233
|
+
e_version: uint32,
|
234
|
+
e_entry: uint64,
|
235
|
+
e_phoff: uint64,
|
236
|
+
e_shoff: uint64,
|
237
|
+
e_flags: uint32,
|
238
|
+
e_ehsize: uint16,
|
239
|
+
e_phentsize: uint16,
|
240
|
+
e_phnum: uint16,
|
241
|
+
e_shentsize: uint16,
|
242
|
+
e_shnum: uint16,
|
243
|
+
e_shstrndx: uint16})
|
244
|
+
Elf64_Half = uint16
|
245
|
+
Elf64_Lib = struct({l_name: uint32,
|
246
|
+
l_time_stamp: uint32,
|
247
|
+
l_checksum: uint32,
|
248
|
+
l_version: uint32,
|
249
|
+
l_flags: uint32})
|
250
|
+
Elf64_Move = struct({m_value: uint64,
|
251
|
+
m_info: uint64,
|
252
|
+
m_poffset: uint64,
|
253
|
+
m_repeat: uint16,
|
254
|
+
m_stride: uint16})
|
255
|
+
Elf64_Nhdr = struct({n_namesz: uint32, n_descsz: uint32, n_type: uint32})
|
256
|
+
Elf64_Off = uint64
|
257
|
+
Elf64_Phdr = struct({p_type: Elf_Pt,
|
258
|
+
p_flags: bitmap(uint32, Elf_Pf),
|
259
|
+
p_offset: uint64,
|
260
|
+
p_vaddr: uint64,
|
261
|
+
p_paddr: uint64,
|
262
|
+
p_filesz: uint64,
|
263
|
+
p_memsz: uint64,
|
264
|
+
p_align: uint64})
|
265
|
+
Elf64_Rel = struct({r_offset: uint64, r_info: uint64})
|
266
|
+
Elf64_Rela = struct({r_offset: uint64, r_info: uint64, r_addend: int64})
|
267
|
+
Elf64_Section = uint16
|
268
|
+
Elf64_Shdr = struct({sh_name: uint32,
|
269
|
+
sh_type: Elf_Sht,
|
270
|
+
sh_flags: bitmap(uint64, Elf_Shf),
|
271
|
+
sh_addr: uint64,
|
272
|
+
sh_offset: uint64,
|
273
|
+
sh_size: uint64,
|
274
|
+
sh_link: uint32,
|
275
|
+
sh_info: uint32,
|
276
|
+
sh_addralign: uint64,
|
277
|
+
sh_entsize: uint64})
|
278
|
+
Elf64_Sword = int32
|
279
|
+
Elf64_Sxword = int64
|
280
|
+
Elf64_Sym = struct({st_name: uint32,
|
281
|
+
st_info: uint8,
|
282
|
+
st_other: uint8,
|
283
|
+
st_shndx: uint16,
|
284
|
+
st_value: uint64,
|
285
|
+
st_size: uint64})
|
286
|
+
Elf64_Syminfo = struct({si_boundto: uint16, si_flags: uint16})
|
287
|
+
Elf64_Verdaux = struct({vda_name: uint32, vda_next: uint32})
|
288
|
+
Elf64_Verdef = struct({vd_version: uint16,
|
289
|
+
vd_flags: uint16,
|
290
|
+
vd_ndx: uint16,
|
291
|
+
vd_cnt: uint16,
|
292
|
+
vd_hash: uint32,
|
293
|
+
vd_aux: uint32,
|
294
|
+
vd_next: uint32})
|
295
|
+
Elf64_Vernaux = struct({vna_hash: uint32,
|
296
|
+
vna_flags: uint16,
|
297
|
+
vna_other: uint16,
|
298
|
+
vna_name: uint32,
|
299
|
+
vna_next: uint32})
|
300
|
+
Elf64_Verneed = struct({vn_version: uint16,
|
301
|
+
vn_cnt: uint16,
|
302
|
+
vn_file: uint32,
|
303
|
+
vn_aux: uint32,
|
304
|
+
vn_next: uint32})
|
305
|
+
Elf64_Versym = uint16
|
306
|
+
Elf64_Word = uint32
|
307
|
+
Elf64_Xword = uint64
|
308
|
+
Elf64_auxv_t = struct({a_type: uint64, a_un: union({a_val: uint64})})
|
309
|
+
Elf_MIPS_ABIFlags_v0 = struct({version: uint16,
|
310
|
+
isa_level: uint8,
|
311
|
+
isa_rev: uint8,
|
312
|
+
gpr_size: uint8,
|
313
|
+
cpr1_size: uint8,
|
314
|
+
cpr2_size: uint8,
|
315
|
+
fp_abi: uint8,
|
316
|
+
isa_ext: uint32,
|
317
|
+
ases: uint32,
|
318
|
+
flags1: uint32,
|
319
|
+
flags2: uint32})
|
320
|
+
Elf_Options = struct({kind: uint8, size: uint8, section: uint16, info: uint32})
|
321
|
+
Elf_Options_Hw = struct({hwp_flags1: uint32, hwp_flags2: uint32})
|
322
|
+
end
|
323
|
+
|
324
|
+
require_relative "types/uleb128"
|
325
|
+
require_relative "types/sleb128"
|
326
|
+
require_relative "types/dwarf"
|
327
|
+
require_relative "types/dwarf32"
|
328
|
+
require_relative "types/dwarf64"
|
data/lib/elf_utils.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "elf_utils/version"
|
4
|
+
|
5
|
+
# ElfUtils for working with ELF & DWARF files
|
6
|
+
#
|
7
|
+
# ElfUtils provides a user-friendly wrapper around core ELF & DWARF types to
|
8
|
+
# make it easier to extract common information from ELF files. The {ElfFile}
|
9
|
+
# and {Symbol} classes are the primary interface into ELF file contents. For
|
10
|
+
# complex tasks not currently provided there, you can directly access the
|
11
|
+
# ELF and DWARF structures from {ElfFile#sections}, {ElfFile#segments}, and
|
12
|
+
# {ElfFile#debug_info}.
|
13
|
+
#
|
14
|
+
# ElfUtils supports 32-bit & 64-bit ELF formats, both little and big endian.
|
15
|
+
# ElfUtils supports DWARF v2, v3, v4, and v5, but not exhaustively.
|
16
|
+
#
|
17
|
+
# Here are some quick examples of ElfUtils functionality.
|
18
|
+
#
|
19
|
+
# @example Get the source of a function from a binary with DWARF debug info
|
20
|
+
# ElfUtils.open("spec/data/complex_64be-dwarf64-v5") do |elf_file|
|
21
|
+
# elf_file.symbol("main").source_location
|
22
|
+
# end # => {:file=>"spec/data/test.c", :line=>25 (0x19), :column=>0}
|
23
|
+
#
|
24
|
+
# @example Get the address of a variable in memory
|
25
|
+
# ElfUtils.open("spec/data/complex_64be-dwarf64-v5") do |elf_file|
|
26
|
+
# symbol = elf_file.symbol("global_buf") # => #<ElfUtils::Symbol ... >
|
27
|
+
# symbol.addr # => 0x000206d0
|
28
|
+
#
|
29
|
+
# # adjust the load segment location for ASLR
|
30
|
+
# symbol.section.load_segment.relocate(0x10000000)
|
31
|
+
# symbol.addr # => 0x10000090
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# @example Extract the initial value for a variable from an elf file
|
35
|
+
# # open the elf file
|
36
|
+
# elf_file = ElfUtils.open("spec/data/complex_64be-dwarf64-v5")
|
37
|
+
#
|
38
|
+
# # lookup the symbol for a global variable, and get its type
|
39
|
+
# symbol = elf_file.symbol("struct_with_bitfield") # => #<ElfUtils::Symbol>
|
40
|
+
# ctype = symbol.ctype # => #<CTypes::Type ...>
|
41
|
+
#
|
42
|
+
# # read the bytes for the symbol from the elf file
|
43
|
+
# buf = symbol.section.bytes[symbol.section_offset, symbol.size]
|
44
|
+
# # => "\xE0\x80\x00\x00"
|
45
|
+
#
|
46
|
+
# # unpack the bytes into a human-readable structure
|
47
|
+
# value = ctype.unpack(buf) # => { a: 1, b: -1, c: 1}
|
48
|
+
#
|
49
|
+
# @see ElfFile
|
50
|
+
# @see Symbol
|
51
|
+
module ElfUtils
|
52
|
+
class Error < StandardError; end
|
53
|
+
|
54
|
+
class InvalidFormat < Error; end
|
55
|
+
|
56
|
+
# open a file path, and return an ElfFile instance
|
57
|
+
# @overload open(path)
|
58
|
+
# @param path [String] file path
|
59
|
+
# @return [ElfFile]
|
60
|
+
#
|
61
|
+
# @overload open(path)
|
62
|
+
# @param path [String] file path
|
63
|
+
# @yield [ElfFile] invokes block with opened file, will close when block
|
64
|
+
# returns
|
65
|
+
#
|
66
|
+
# @example Open an ELF file and print all symbols
|
67
|
+
# elf_file = ElfUtils.open("spec/data/complex_64be-dwarf64-v5")
|
68
|
+
# pp(elf_file.symbols)
|
69
|
+
# elf_file.close
|
70
|
+
#
|
71
|
+
# @example print all symbols using a block invocation
|
72
|
+
# ElfUtils.open("spec/data/complex_64be-dwarf64-v5") do |elf_file|
|
73
|
+
# pp(elf_file.symbols)
|
74
|
+
# end
|
75
|
+
#
|
76
|
+
def self.open(path, &block)
|
77
|
+
ElfFile.open(path, &block)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
require_relative "elf_utils/types"
|
82
|
+
require_relative "elf_utils/elf_file"
|
83
|
+
require_relative "elf_utils/elf_utils"
|
data/sig/elf_utils.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: elf_utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David M. Lary
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-02-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ctypes
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.2'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- dmlary@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions:
|
32
|
+
- ext/elf_utils/extconf.rb
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- ".rspec"
|
36
|
+
- ".standard.yml"
|
37
|
+
- CODE_OF_CONDUCT.md
|
38
|
+
- CONTRIBUTING.md
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE.txt
|
41
|
+
- MAINTAINERS.md
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- SECURITY.md
|
45
|
+
- elf_utils.gemspec
|
46
|
+
- ext/elf_utils/elf_utils.c
|
47
|
+
- ext/elf_utils/extconf.rb
|
48
|
+
- lib/elf_utils.rb
|
49
|
+
- lib/elf_utils/elf_file.rb
|
50
|
+
- lib/elf_utils/section.rb
|
51
|
+
- lib/elf_utils/section/base.rb
|
52
|
+
- lib/elf_utils/section/debug_abbrev.rb
|
53
|
+
- lib/elf_utils/section/debug_abbrev/abbreviation.rb
|
54
|
+
- lib/elf_utils/section/debug_abbrev/abbreviation_table.rb
|
55
|
+
- lib/elf_utils/section/debug_addr.rb
|
56
|
+
- lib/elf_utils/section/debug_arange.rb
|
57
|
+
- lib/elf_utils/section/debug_info.rb
|
58
|
+
- lib/elf_utils/section/debug_info/compilation_unit.rb
|
59
|
+
- lib/elf_utils/section/debug_info/debug_str_offsets_ref.rb
|
60
|
+
- lib/elf_utils/section/debug_info/debug_str_ref.rb
|
61
|
+
- lib/elf_utils/section/debug_info/die.rb
|
62
|
+
- lib/elf_utils/section/debug_info/die/base.rb
|
63
|
+
- lib/elf_utils/section/debug_info/die_ref.rb
|
64
|
+
- lib/elf_utils/section/debug_info/header.rb
|
65
|
+
- lib/elf_utils/section/debug_line.rb
|
66
|
+
- lib/elf_utils/section/debug_line/line_number_program.rb
|
67
|
+
- lib/elf_utils/section/debug_line/line_number_program/header.rb
|
68
|
+
- lib/elf_utils/section/debug_line/line_number_program/state_machine.rb
|
69
|
+
- lib/elf_utils/section/debug_ranges.rb
|
70
|
+
- lib/elf_utils/section/debug_str_offsets.rb
|
71
|
+
- lib/elf_utils/section/dynsym.rb
|
72
|
+
- lib/elf_utils/section/strtab.rb
|
73
|
+
- lib/elf_utils/section/symtab.rb
|
74
|
+
- lib/elf_utils/segment.rb
|
75
|
+
- lib/elf_utils/segment/base.rb
|
76
|
+
- lib/elf_utils/string_pread.rb
|
77
|
+
- lib/elf_utils/symbol.rb
|
78
|
+
- lib/elf_utils/types.rb
|
79
|
+
- lib/elf_utils/types/dwarf.rb
|
80
|
+
- lib/elf_utils/types/dwarf/expression.rb
|
81
|
+
- lib/elf_utils/types/dwarf32.rb
|
82
|
+
- lib/elf_utils/types/dwarf32/v2.rb
|
83
|
+
- lib/elf_utils/types/dwarf32/v3.rb
|
84
|
+
- lib/elf_utils/types/dwarf32/v4.rb
|
85
|
+
- lib/elf_utils/types/dwarf32/v5.rb
|
86
|
+
- lib/elf_utils/types/dwarf64.rb
|
87
|
+
- lib/elf_utils/types/dwarf64/v3.rb
|
88
|
+
- lib/elf_utils/types/dwarf64/v4.rb
|
89
|
+
- lib/elf_utils/types/dwarf64/v5.rb
|
90
|
+
- lib/elf_utils/types/sleb128.rb
|
91
|
+
- lib/elf_utils/types/uleb128.rb
|
92
|
+
- lib/elf_utils/types/unit_length.rb
|
93
|
+
- lib/elf_utils/version.rb
|
94
|
+
- sig/elf_utils.rbs
|
95
|
+
homepage: https://github.com/cisco-open/elf_utils
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata:
|
99
|
+
homepage_uri: https://github.com/cisco-open/elf_utils
|
100
|
+
source_code_uri: https://github.com/cisco-open/elf_utils
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 3.1.0
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubygems_version: 3.3.7
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Library for parsing ELF files and DWARF debugging information
|
120
|
+
test_files: []
|