442 Commits

Author SHA1 Message Date
Christopher Cole c5fba3b0ab Refactor section_headers_with_strtab to work with files that have shdrs but no shstrtab
The spec allows for ELF files that have section header tables but no shstrtab. In this case,
we want to still be able to get the section headers, but signal that there was no shstrtab with
an empty option.
2022-11-10 12:05:32 -08:00
Christopher Cole 2faf0ca1b0 Update common fuzz target for hash table change
Also, fuzz the gnu_hash table
2022-11-09 19:44:23 -08:00
Christopher Cole 4bdcb7db5f Rework the top level documentation a bit 2022-11-09 19:35:14 -08:00
Christopher Cole 44f84dd0d8 Remove redundant hash arg from SysVHashTable.find()
We can just calculate this from the requested name bytes.
2022-11-09 18:45:19 -08:00
Christopher Cole aea8a233e2 Add some more unit tests for ParsingTable
These check that there's no special alignment constraint for parsing a ParseAt out of a bytes buffer,
and a simple error case for failing to parse because the bytes are too small to parse the type.
2022-11-09 17:39:37 -08:00
Christopher Cole 4df35c65ca Exclude .gitignore, .github/ and sample-objects/ from packaged crate 2022-11-09 16:33:10 -08:00
Christopher Cole 33e3435a7f Add sample object with with > 0xff00 section headers
Also add unit tests that we properly parse e_shnum and e_shstrndx out of
shdr0 in that case.
2022-11-09 16:04:28 -08:00
Christopher Cole f747747929 Add abi constants for powerpc and powerpc64 2022-11-08 14:02:26 -08:00
Christopher Cole 19d26ae4e5 Add abi constants for RISC-V
See: https://github.com/riscv-non-isa/riscv-elf-psabi-doc
2022-11-08 13:16:32 -08:00
Christopher Cole 8e5b699c6e Add abi constants for x86_64
See https://gitlab.com/x86-psABIs/x86-64-ABI
2022-11-08 12:39:45 -08:00
Christopher Cole 6fc477c645 Tweak some doc comments 2022-11-08 11:56:32 -08:00
Christopher Cole 1ce4958375 Rename ElfStream::dynamic_section() -> dynamic() to match ElfBytes 2022-11-08 11:25:42 -08:00
Christopher Cole 92f3d361c3 Change ElfStream::dynamic() to yield a DynamicTable just like in ElfBytes 2022-11-08 11:23:27 -08:00
Christopher Cole 39fe7f1a93 Add elf::to_str::d_tag_to_str()
Converts known abi::DT_* to &'static str
2022-11-08 11:00:07 -08:00
Christopher Cole 8752084524 Move elf file Class enum over into file.rs
It's already exported publicly here, and it feels like it really should live here.
2022-11-08 09:54:05 -08:00
Christopher Cole 1161178443 Use helper ReadBytesExt trait in a few more places
This just helps avoid manually writing out the SliceReadError
2022-11-08 09:46:25 -08:00
Christopher Cole 4fa888778f Add GnuHashTable which interprets the contents of a SHT_GNU_HASH section
Also, integrate gnu_hash lookups into the arch smoke tests which look up all the dynamic symbols
in their .gnu.hash tables.

Note that the GnuHashTable::find() method does not currently take any symbol versioning
into account.
2022-11-07 23:21:05 -08:00
Christopher Cole b50d19c244 Add some simple parsing smoke tests for the various sample architecture objects 2022-11-07 15:26:03 -08:00
Christopher Cole dd8e9c7814 Add some sample objects for various architectures 2022-11-07 14:54:24 -08:00
Christopher Cole 073bd44ee3 Parse the ProgramHeaders into an allocated vec as part of ElfStream::open_stream() 2022-11-07 14:11:46 -08:00
Christopher Cole 643d83f078 Add abi constants for ARM32 and ARM64 (AARCH64)
See:
https://github.com/ARM-software/abi-aa/blob/main/aaelf32/aaelf32.rst
https://github.com/ARM-software/abi-aa/blob/main/aaelf64/aaelf64.rst
2022-11-07 13:34:19 -08:00
Christopher Cole 2fa91412c2 CI: Go back to manual rustup+cargo install
The actions-rs helpers spew out a bunch of warnings about using deprecated features that are going away soon. They also aren't any faster than the old manual way of doing things which worked fine.
2022-11-06 19:54:24 -08:00
Christopher Cole af1b4145ac Github action: make corpus cache additive
The old way would just always use the cached corpus from the first run then never update the cache. If I understand this restore-keys configuration, then this should change the behavior to always update the corpus used in this latest run then try to restore from the most recent run the next time around.
2022-11-06 19:41:42 -08:00
Christopher Cole 324ccfd14f Use actions-rs toolchain step in our fuzz action
this seems "better" than rolling our own rustup cmd
2022-11-06 19:32:41 -08:00
Christopher Cole 16eed7f136 Run the stream fuzz target during github action 2022-11-06 19:27:35 -08:00
Christopher Cole b73ed8ebd8 CI: Attempt at caching the fuzzing corpus 2022-11-06 19:15:30 -08:00
Christopher Cole 7672d5cf93 Rename sample object files used in tests to be more descriptive 2022-11-06 18:54:41 -08:00
Christopher Cole 73a847719f Add to_str method note_abi_tag_os_to_str() 2022-11-06 18:36:20 -08:00
Christopher Cole 0bdefe6ebf Remove section_data_as_symbol_table() from public ElfBytes interface
It's easier to use symbol_table(), dynamic_symbol_table() or find_common_sections(),
so there's no need to clutter up the public interface with this.
2022-11-06 17:43:04 -08:00
Christopher Cole 498232ee7e Add interface test for sysv_hash table on ElfBytes from find_common_sections() 2022-11-06 17:31:04 -08:00
Christopher Cole cb987d1846 Update the README.md and top-level crate doc comment with new example 2022-11-06 14:33:50 -08:00
Christopher Cole 6d20b5a8f0 Add convenience method section_header_by_name to ElfBytes and ElfStream
This parses out SectionHeaders from the section header table until it finds
one with a name that matches the given name.
2022-11-06 14:05:08 -08:00
Christopher Cole f72ce6d26b Add doc comment example for getting parsed notes 2022-11-06 13:34:15 -08:00
Christopher Cole 043238d83f Refactor parsed Note type to lift enum up to the top level
This gives a nice typed enum interface for parsed notes which can be easily
used in match statements etc.
2022-11-06 13:21:16 -08:00
Christopher Cole c436b84eba Include the os field when parsing an NT_GNU_ABI_TAG desc
also rename patch -> subminor
2022-11-06 12:30:49 -08:00
Christopher Cole bc5e3c4f60 Add GnuBuildIdDesc and associated NoteDesc::GnuBuildId variant 2022-11-06 12:18:15 -08:00
Christopher Cole d4ee10f532 Add NoteDesc enum and parsing for NT_GNU_ABI_TAG note desc contents 2022-11-06 12:02:37 -08:00
Christopher Cole 2efd9b2ec7 Add abi constant for GNU-extension ELF note name ELF_NOTE_GNU 2022-11-06 11:19:54 -08:00
Christopher Cole b845d2736a Remove pub from CachingReader methods - this is an internal type 2022-11-05 18:56:50 -07:00
Christopher Cole b53237960b Fix OOM in ElfStream parsing when parsing corrupted files
When parsing invalid ELF data with ranges larger than actual file size, CachedReader would
eagerly allocate a buffer to land the read of that huge size even though the read would later fail.
This could cause unbounded vec allocations.

CachedReader now seeks to find the actual stream lengthh at the beginning and validates read requests
against that.

Also, add fuzz testing for some basic ElfStream interfaces (that's what caught this bug).
Also, rustfmt the fuzz targets.
2022-11-05 18:40:58 -07:00
Christopher Cole f9d1e47589 Make ElfStream parse out the SectionHeaders into an allocated Vec as part of open_stream()
The shdrs are commonly used for nearly every other interface method, so there's no need to parse them
out lazily all the time. This interface can (and does) allocate, so let's just allocate and parse
them up front to get it out of the way for the other interface methods.
2022-11-05 18:13:07 -07:00
Christopher Cole c06ae21afa Expose Class in the public interface alongside FileHeader (where its used) 2022-11-05 15:07:23 -07:00
Christopher Cole 903653eba2 Update fuzzing github action for new common target 2022-11-05 14:25:34 -07:00
Christopher Cole 40240fc4af Fix a divide by zero panic in SysVHashTable.find() for empty tables
Also, add fuzz coverage for ElfBytes::find_common_sections() and its
associated types. This fuzzing is what discovered that panic in find().
2022-11-05 14:18:58 -07:00
Christopher Cole 6efd7c177f Standardize ElfBytes' interfaces for the .dynamic contents to return a DynamicTable 2022-11-05 13:55:23 -07:00
Christopher Cole 40799c6961 Add ElfBytes::symbol_version_table() to get the GNU extension symbol version table. 2022-11-05 13:39:02 -07:00
Christopher Cole bd36bba238 Update the crate doc comment 2022-11-04 23:52:54 -07:00
Christopher Cole 765dd6984a Change endian parse to return ParseError::SliceReadError when failing to get the slice to parse from
This error more accurately reflects the operation that failed - we're trying to get a slice
out of an in-memory buffer to perform the endian-aware integer parse. The error also has the full
slice range in its details too, which can be helpful.
2022-11-04 23:20:34 -07:00
Christopher Cole 5ec40c8731 Move FileHeader back into file.rs 2022-11-04 23:16:58 -07:00
Christopher Cole ae16e4762e Rename file.rs -> elf_stream.rs
This keeps the git history intact for git blame. The next patch will move FileHeader
back over to file.rs
2022-11-04 23:08:26 -07:00