440 Commits

Author SHA1 Message Date
1436aab797 Add no-std ElfStream support 2023-07-19 17:13:56 +03:00
Christopher Cole
b7067d3307
Enable #![warn(rust_2018_idioms)]
This helps catch deprecated idioms so we can be proactively clean

The only warnings fixed were:
* warning: hidden lifetime parameters in types are deprecated
2023-06-08 13:57:34 -07:00
Christopher Cole
bee2d247bd
Turn on #![deny(missing_debug_implementations)]
This helps ensure we're deriving Debug, as it's generally always helpful. This helps avoid issues like #33
2023-06-08 13:52:43 -07:00
Christopher Cole
a853cb24bd
Add NoteAny::name_str() helper to parse the note name as valid UTF8 2023-06-06 12:07:55 -07:00
Christopher Cole
d29e9964dc
Relax NoteAny parsing to allow notes with names that contain invalid utf8 sequences
We want NoteAny to be a catch-all note type that can represent any valid note that we don't know how to parse into something more specific.

The ELF spec only claims: "The first namesz bytes in name contain a null-terminated character representation of the entry's owner or originator.",
and while it does say "null-terminated character representaion", it does not specify that those bytes must be valid UTF8, so we were being unnecessarily
strict in forcing all parsed notes to have valid utf8 names. All the standard note types I know about use simple ascii sequences.
2023-06-06 11:34:54 -07:00
Christopher Cole
10957838b8
Fix doc comment on file::Class 2023-05-16 21:48:17 -07:00
Christopher Cole
a2fa6a194e
Derive Debug on LittleEndian and BigEndian
This addresses #33
2023-05-05 12:01:16 -07:00
Christopher Cole
969c18469d
Replace some range loop expressions in tests with iterators
This cleans up clippy warnings
2023-05-05 11:52:38 -07:00
Christopher Cole
a488df66db
Explicitly specify test data literals as hex in note.rs 2023-05-05 11:42:35 -07:00
Christopher Cole
2ad70e5db2
Fix up README example so it compiles
Patch 9a6a265a forgot to update the old name of find_common_sections in the README, and since cargo test only compiles doc comments and
doesn't know about the README, I missed this.

Fixes #31
2023-02-20 18:28:11 -08:00
Christopher Cole
c2799a1d75
Bump crate version to 0.7.2
New Features:
* Implement core::error::Error for ParsingError accessible via a new non-default "nightly" cargo feature
* Add abi constants for note descriptor types (n_type)
* Add C-style struct definitions for various abi structs (Elf[32|64]_Ehdr etc). These aren't used by the parser, but are useful definitions for folks wanting to manually muck with elf bytes.

Bug Fixes:
* Fix an 'attempt to shift right with overflow' panic in the GnuHashTable if nshift is wider than the bloom filter word size

Misc Improvements:
* Add doc comments for EM_* abi constants
* Tweak formatting and update language for various doc comments
2023-02-15 15:39:24 -08:00
Christopher Cole
1181e6b70b
Reorder README/doc comment feature list 2023-02-15 15:21:13 -08:00
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