428 Commits

Author SHA1 Message Date
Christopher Cole
db0c3938a0
Rewrite docs section about unsafe code
This addresses feedback from #30
2023-02-09 01:44:38 -08:00
Christopher Cole
dea6edfdf7
Fix an 'attempt to shift right with overflow' panic in the GnuHashTable if nshift is wider than the bloom filter word size
This changes the case to be an IntegerOverflow error instead of a crash/panic by using checked_shr

This was found by fuzz testing
2023-02-07 22:49:34 -08:00
Christopher Cole
5f4014de1f
Fix some abi comments so that they don't accidentally pollute unrelated doc comments
These are just comments that are helpful for delineating groups of constants and were incorrectly
being rendered as part of the doc comment of the immediately-following symbol.
2023-01-26 18:05:08 -08:00
Christopher Cole
72c6af75b0
Change abi EM_* comments into doc comments 2023-01-26 17:56:13 -08:00
Christopher Cole
e6a1b963f6
Add C-style definitions for Elf[32|64]_Ehdr 2023-01-26 17:43:14 -08:00
Christopher Cole
e786ecfcf9
Add C-style definitions for Elf[32|64]_Dyn 2023-01-26 13:47:05 -08:00
Christopher Cole
ff57f74d26
Add abi constants for note descriptor types (n_type) 2023-01-26 13:38:07 -08:00
Christopher Cole
04242deb6f
Add C-style definitions for Elf[32|64]_Phdr 2023-01-26 13:18:58 -08:00
Christopher Cole
840dd99239
Add C-style definitions for Elf[32|64]_Rel and Elf[32|64]_Rela 2023-01-26 13:14:41 -08:00
Christopher Cole
ee705369b0
Add C-style definitions for Elf[32|64]_Sym 2023-01-26 13:06:13 -08:00
Christopher Cole
8ed49b6a4c
Add C-style definitions for Elf[32|64]_Chdr 2023-01-26 12:58:58 -08:00
Christopher Cole
161f679004
Combine some derives into one directive in endian.rs 2023-01-26 12:54:59 -08:00
Christopher Cole
9d4c50ad18
Add C-style definitions for Elf[32|64]_Shdr 2023-01-26 12:54:33 -08:00
Christopher Cole
332a42a2a3
Fix doc comment formatting to keep [] subscripting in some abi.rs comments 2023-01-26 12:09:36 -08:00
Christopher Cole
9035474869
Tweak formatting of doc comments on reloc abi constants 2023-01-26 12:05:29 -08:00
Christopher Cole
a502f95b01
Apply fixes suggested by cargo +nightly clippy 2023-01-21 12:08:41 -08:00
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