412 Commits

Author SHA1 Message Date
Christopher Cole
b1883750b1
Add comment explaining what the nightly cargo feature provides 2023-01-21 12:01:38 -08:00
Christopher Cole
b53647d782
Add a changelog comparison link for v0.7.1 2023-01-17 21:43:33 -08:00
jlxip
bddf58a950
Implement core::error::Error for ParsingError 2023-01-11 02:57:24 +01:00
Christopher Cole
da1e25f338
Bump crate version to v0.7.1
Bug Fixes:
* Fix a divide by zero panic in GnuHashTable.find() for tables with nbloom = 0
2023-01-08 14:28:58 -08:00
CT
f45969a2e2 fix comment 2022-12-22 17:19:34 -08:00
CT
9192854af5 return None if nbloom is zero to avoid potential overflows in malformed gnu hash headers 2022-12-22 17:19:34 -08:00
Christopher Cole
1ed0bdd654
Add tag comparison links for changelog versions 2022-11-14 13:25:34 -08:00
Christopher Cole
9f552d85f1
Bump crate version to v0.7.0
New Features:
* Add new ElfBytes type with better ergonomics for parsing from a &[u8]
* Add GnuHashTable which interprets the contents of a SHT_GNU_HASH section
* Add convenience method section_header_by_name to ElfBytes and ElfStream
* Add GnuBuildIdNote and parsing for NT_GNU_BUILD_ID note contents
* Add GnuAbiTagNote and parsing for NT_GNU_ABI_TAG note contents
* Add ElfBytes::symbol_version_table() to get the GNU extension symbol version table.
* Add ElfBytes::find_common_data() to efficiently discover common ELF structures
* Add a new endian-aware integer parsing trait impl
* Add ParsingTable.is_empty()
* Add abi constants for powerpc and powerpc64
* Add abi constants for RISC-V
* Add abi constants for x86_64
* Add abi constants for ARM32 and ARM64 (AARCH64)
* Add abi constant for GNU-extension ELF note name ELF_NOTE_GNU
* Add abi constant for PT_GNU_PROPERTY
* Add abi constants for SHN_ABS and SHN_COMMON
* Add elf::to_str::d_tag_to_str()
* Add elf::to_str::note_abi_tag_os_to_str()

Changed Interfaces:
* Rename elf::File -> elf::ElfStream and make it specific to the Read + Seek interface
* Rename gabi -> abi since it also includes extension constants
* Make ELF structures generic across the new endian-aware integer parsing trait EndianParse
* Refactor parsed Note type to be a typed enum
* Rename ElfStream::dynamic_section() -> dynamic() to match ElfBytes
* Change ElfStream::dynamic() to yield a DynamicTable just like in ElfBytes
* Standardize ElfBytes' interfaces for the .dynamic contents to return a DynamicTable
* Export the parsing utilities ParsingTable, ParsingIterator in the public interface
* Refactor section_headers_with_strtab to work with files that have shdrs but no shstrtab
* Remove redundant hash arg from SysVHashTable.find()
* Expose Class in the public interface alongside FileHeader
* Remove opinionated Display impl for file::Class
* Remove section_data_as_symbol_table() from public ElfBytes interface
* Change SymbolVersionTable::new() to take Options instead of Default-empty iterators
* Change ElfStream to parse out the ProgramHeaders into an allocated vec as part of ElfStream::open_stream()
* Change ElfStream to parse out the SectionHeaders into an allocated Vec as part of ElfStream::open_stream()

Bug Fixes:
* Properly parse program header table when ehdr.e_phnum > 0xffff
* Fix OOM in ElfStream parsing when parsing corrupted files
* Fix a divide by zero panic in SysVHashTable.find() for empty tables

Misc Improvements:
* Add more fuzz testing
* Add some simple parsing smoke tests for the various sample architecture objects
* Add sample object and testing with > 0xff00 section headers
* Add a lot more doc comments to each of the modules
2022-11-14 12:22:56 -08:00
Christopher Cole
6ce804dbd2
Add a CHANGELOG.md to track changes in each released version 2022-11-14 12:14:03 -08:00
Christopher Cole
73e5e94c39
Export the parsing utilities in the public interface
This allows external users to see ParsingTable, ParsingIterator.
This helps users know what they can do with these structures, and makes them
show up in docs, etc.
2022-11-13 19:23:16 -08:00
Christopher Cole
5a933389a8
Add fuzz/coverage/ to .gitignore
These are generated coverage report files from `cargo fuzz coverage ...`
2022-11-13 19:06:41 -08:00
Christopher Cole
f0ef935418
Use symver.so in GNU symbol versioning interface tests
This lets us test parsing VERDEFs as well as VERNEEDs
2022-11-13 18:39:55 -08:00
Christopher Cole
ea3605ed29
Simplify the notes fuzz target to just fuzz note parsing
The other ElfBytes logic is fuzzed elsewhere - this simplifies the fuzz
target space to get more coverage of the notes parsing specifics.
2022-11-13 17:24:26 -08:00
Christopher Cole
a8c1125fa5
Move U32Table definition over to its one usage in hash.rs 2022-11-13 13:59:48 -08:00
Christopher Cole
910a46ef9d
Add ParsingTable.is_empty() 2022-11-13 13:53:13 -08:00
Christopher Cole
0f849a1e17
Run cargo clippy --fix 2022-11-13 13:14:12 -08:00
Christopher Cole
9a6a265afc
Rename CommonElfSections -> CommonElfData
These aren't only found in sections, so I felt "Data" fit better as a name here
2022-11-12 13:37:09 -08:00
Christopher Cole
19e7f685c8
Refactor endianness storage so its not duplicated on FileHeader and ElfBytes+ElfStream
This eliminates the funky double-storage of the endianness spec and removes the unparsed u8 storage
of ei_data off FileHeader. Now, FileHeader just stores the appropriate parsed endianness spec enum,
and all methods that want to use it grab it from there.
2022-11-12 13:28:58 -08:00
Christopher Cole
4875ff8981
Remove opinionated Display impl for file::Class
This type derives Debug, so you can "{:?}" format it to get a string like ELF32/ELF64,
which is intuitive to me. If someone wants some other human readable format, they can implement
it themselves.
2022-11-12 12:12:49 -08:00
Christopher Cole
2e05d70302
Handle the case where ehdr.e_phnum > 0xffff
If the number of segments is greater than or equal to PN_XNUM (0xffff),
e_phnum is set to PN_XNUM, and the actual number of program header table
entries is contained in the sh_info field of the section header at index 0.

The phnum.m68k.so is a sample object file that tests this code path but then
actually only has 1 segment - it just indirects phnum through shdr0.
2022-11-10 13:36:58 -08:00
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