420 Commits

Author SHA1 Message Date
Christopher Cole
929e099769
Add VerNeed parsing for entries in the GNU extension section .gnu.version_r
These are one type of entries found in the .gnu.version_r section of type SHT_GNU_VERNEED.
This only parses the type, and is not hooked up to anything else yet.
2022-10-25 18:19:06 -07:00
Christopher Cole
c8cb21089e
Add VerDefAux parsing for entries in the GNU extension section .gnu.version_d
These other type of entries are found in the .gnu.version_d section of type SHT_GNU_VERDEF.
This only parses the type, and is not hooked up to anything else yet.
2022-10-25 17:31:16 -07:00
Christopher Cole
f35a2936b4
Add VerDef parsing for entries in the GNU extension section .gnu.version_d
These type of entries are found in the .gnu.version_d section of type SHT_GNU_VERDEF,
alongside VerDefAux (not yet defined).
This only parses the type, and is not hooked up to anything else yet.
2022-10-25 17:22:28 -07:00
Christopher Cole
2142af70e0
Add VersionIndex parsing for entries in the GNU extension section .gnu.version
These are the entries found in the .gnu.version section of type SHT_GNU_VERSYM.
This only parses the entry type, and is not hooked up to anything in File yet.
2022-10-25 13:06:58 -07:00
Christopher Cole
8206eed68e
Add more OS and application-specific constants for .dynamic section types 2022-10-25 00:13:03 -07:00
Christopher Cole
720e54b377
Add some processor-specific SHT_ definitions 2022-10-24 20:45:21 -07:00
Christopher Cole
59274c16f7
Restructure use imports in file.rs to make code less verbose
The module paths are pretty intuitive, so I think it actually hurts
code legibility by having them spelled out as they were before.
2022-10-24 18:39:44 -07:00
Christopher Cole
d3ca1bf095
Add File::section_data() which opportunistically parses the CompressionHeader if present
I don't plan on implementing any actual compression as part of this library and think that
it is reasonable for users to do the decompression themselves based on the description
provided by the parsed CompressionHeader.

Also, deprecate File::section_data_for_header() in favor of section_data()
2022-10-24 18:17:57 -07:00
Christopher Cole
90eb25f8b6
Add rust type and parsing for CompressionHeader
This header is found at the start of sections whose flags contain SHF_COMPRESSED,
indicating that the section's data in the file is compressed with a given algorithm.
2022-10-24 17:55:12 -07:00
Christopher Cole
5e73835772
Add ELFCOMPRESS constants to gabi.rs
These define possible values for the elf compression header's ch_type field, which
signals the compression algorithm used for compressed sections (shdr.sh_flags & SHF_COMPRESSED)
2022-10-24 17:51:53 -07:00
Christopher Cole
531ad77d04
Fix File::section_data_as_rels to properly parse Rels (not Relas) 2022-10-24 17:27:14 -07:00
Christopher Cole
f44860bfc5
Bump crate version to v0.4.0
New Features:
* .note section and segment parsing
* .dynamic section and segment parsing
* .rel and .rela section parsing
* File::section_headers_with_strtab to get both a header iter and strtab concurrently.
  This is useful if you want to iterate over shdrs and get their names at the same time.

Interface changes:
The ReadBytesAt trait was changed to be implemented for an owned CachedReadBytes.
This means that File::open_stream now expects to move-own the CachedReadBytes
as opposed to taking a mutable reference.
2022-10-24 14:42:43 -07:00
Christopher Cole
59f298d54b
Make NoteHeader private to note.rs
The implementation panned out where this header is parsed but then
only used to drive the further parsed Note but not included in the result,
so there's no need for pub(crate) here.
2022-10-24 14:27:47 -07:00
Christopher Cole
d24a57fb3b
Fix doc comments for File::section_data_as_rel and File::section_data_as_rela 2022-10-24 14:22:29 -07:00
Christopher Cole
bcb12eeaff
Add File::segment_data_as_notes() for an iterator which yields parsed Notes 2022-10-24 14:21:19 -07:00
Christopher Cole
485338bc23
Add File::section_data_as_notes() for an iterator which yields parsed Notes 2022-10-24 14:12:50 -07:00
Christopher Cole
5b57ff1c4f
Add Note and NoteIterator to yield parsed Notes
Note: (haha) It looks like gcc/clang choose to emit 32-bit note headers
even for 64-bit objects. I discovered this when writing the parse tests
with data from a 64-bit LSB ELF object that I slurped the .note.gnu.build-id
section from. I kept the 64-bit nhdr parsing around in case someone finds
a use-case for it in the future.
2022-10-24 14:11:12 -07:00
Christopher Cole
269c86c85e
Add parsing of .note section entry headers
These fixed size headers prefix and describe variable-sized note data.
I made it pub(crate) to keep this out of the public interface, since
I plan to have the actual note iterator parse out the name and desc and
have that result be the actual public interface. pub(crate) might still
be more visibility than is needed, but it's a safe place to start.
2022-10-24 12:08:41 -07:00
Christopher Cole
b937ef93a1
Add File::section_headers_with_strtab() to get both shdr iterator and strtab
This allows for a more convenient way of interacting with the SectionHeaders so
that you can concurrently look up the names of the sections as you're iterating
through the SectionHeaderIterator
2022-10-23 20:06:19 -07:00
Christopher Cole
674ed56d57
Add simple interfaces to File to get Rel and Rela iterators for a given section
Note, while this may satisfy some use-cases, it is likely insufficient for those
who want to actually do linking and to concurrently iterate over the returned Rels
while also looking at the sectin's associated SymbolTable and the section to which
they're applied.
2022-10-23 19:02:44 -07:00
Christopher Cole
26b7a6d66c
Add Rel and Rela parsing and parsing iterators
I didn't have a strong motivating factor for deciding whether to represent this as I did,
with r_sym and r_type parsed out as data members, or as an alternative approach where
the rust type keeps a private r_info and then parses out those data members as needed with
getter methods. So I arbitrarily chose to parse them out up front.
2022-10-23 19:02:43 -07:00
Christopher Cole
f7a801bf6a Implement ReadBytesAt for owned CachedReadBytes
As suggested in #21
This changes it from being implemented for a &mut CachedReadBytes, which forced
users to keep a separate variable for the reader when passing it to File::open_stream().
There wasn't a specific reason for it to be implemented that way, and it's actually
something that tenuously even desireable, since ultimately CachedReadBytes is
a more an internal wrapper used within the File for lazy parsing than something
that a user of the interface will want to keep around and use themselves for other things.
2022-10-23 17:15:42 -07:00
Christopher Cole
1f09b43e5b
Dedupe the various lazy parsing iterators into ParsingIterator
This centralizes the iter implementation to one place and leverages the new ParseAt
trait which was already functionally being implemented by all the various types
being iteratively parsed.
2022-10-22 14:44:40 -07:00
Christopher Cole
d28e14a68e
Fix Dyn::d_un type to be unsigned
I accidentally read this as signed when I was looking at the ELF spec, but
upon a second look, only d_tag is signed - d_un is unsigned.
2022-10-21 18:59:41 -07:00
Christopher Cole
5494189ffa
Add File::dynamic_section() interface an iterator over .dynamic section entries
ELF Object files can have either or both a ProgramHeader and SectionHeader that
describes how to locate the .dynamic entries in the file. We try the SectionHeaders
first, and if there are none (a loadable-only ELF object) then we check for it in
the ProgramHeaders. It is also Ok for there to be no .dynamic entries in the file.
2022-10-21 18:28:05 -07:00
Christopher Cole
9bb0b310ce
Add DynIterator which can yield Dyn structs from a .dynamic section's data 2022-10-21 18:28:05 -07:00
Christopher Cole
89c1a34575
Add parser and rust representation of Elf(32|64)_Dyn
These are the entries that make up the .dynamic section
2022-10-21 18:28:05 -07:00
Christopher Cole
1739773778
Add GABI constants for DF_* 2022-10-21 18:28:05 -07:00
Christopher Cole
969bb74628
Add GABI constants for DT_* 2022-10-21 18:28:04 -07:00
Christopher Cole
3d0a090ab2
Add parse methods for parsing signed integers 2022-10-21 18:28:04 -07:00
Christopher Cole
d1022af46f
Add no_std build step to github action 2022-10-21 14:51:37 -07:00
Christopher Cole
2332a54a29
Bump crate version to v0.3.1
This picks up the fixes to section table parsing for large table sizes,
and provides the new File::section_data_for_header() method.
2022-10-21 13:49:37 -07:00
Christopher Cole
dd2685a864
Add some categories to Cargo.toml 2022-10-21 13:48:10 -07:00
Christopher Cole
f715bd7a2b
Add File::section_data_for_header() for reading the section data as found in the file 2022-10-21 12:03:58 -07:00
Christopher Cole
dae40248b8
Properly handle reading section header string table with index > SHN_XINDEX 2022-10-21 11:29:55 -07:00
Christopher Cole
5469c59037
Properly handle reading section header tables with > SHN_LORESERVE number of sections 2022-10-21 11:20:28 -07:00
Christopher Cole
5a4e556d68
Bump crate version to v0.3.0
This fully moves the parser over to the lazy zero-alloc approach which enables
a no_std option.
2022-10-20 23:17:10 -07:00
Christopher Cole
af28e55c30
Expose CachedReadBytes in the public interface
This is necessary for users of this crate to utilize the lazy i/o parsing interface
2022-10-20 23:13:05 -07:00
Christopher Cole
a010016831
Add documentation calling out this parser's is zero-alloc capability 2022-10-20 23:07:31 -07:00
Christopher Cole
1be248c4bb
Add default std feature to allow no_std use-cases
This addresses the ask in #19
2022-10-20 23:00:57 -07:00
Christopher Cole
9c5e4b62d6
Remove now-unused SectionTable impl that eagerly parses all headers and section data 2022-10-20 22:55:55 -07:00
Christopher Cole
7abba88d76
Fix up some copy-pasted rustdoc markdown in README.md
third time's a charm :)
2022-10-20 22:50:57 -07:00
Christopher Cole
3ffb08a11c
Remove typoed duplicate header in README.md 2022-10-20 22:48:28 -07:00
Christopher Cole
e9bc799ec7
Remove eager symbol table parsing from File::open_stream
Now, all section parsing is done lazily on-demand by the other File methods

Also, update README.md and lib.rs doc comment to reflect current library development state
2022-10-20 22:45:27 -07:00
Christopher Cole
4e706431e3
Reimplement File::symbol_table() and File::dynamic_symbol_table() using lazy parsing
These use the lazy parsing methods to read the section headers and section data when requested
as opposed to reading and parsing the section headers and section data all up front when the File
is created.
2022-10-20 22:15:03 -07:00
Christopher Cole
c74566cf9f
Extend the ReadAtExt trait with a pair of load/get methods
These can drive use-cases where we need to read and work with multiple
references to disjoint parts of the ELF file data at the same time.
2022-10-20 21:38:38 -07:00
Christopher Cole
5a6f99c451
Add interface test for File::segments() 2022-10-20 20:59:01 -07:00
Christopher Cole
31689794ba
Add interfaces for reading and interpreting a section's data as a strtab 2022-10-20 20:50:17 -07:00
Christopher Cole
c029fe4b88
Add interface for parsing a single SectionHeader at a given index 2022-10-20 20:09:13 -07:00
Christopher Cole
6ec11531d2
Add File::section_headers() iterator method for lazy header parsing
When called, this reads the section header table and wraps the data reference
in an iterator which lazily parses SectionHeader structs out of it.
2022-10-20 19:19:08 -07:00