303 Commits

Author SHA1 Message Date
Christopher Cole
34ab5c54b7 Move STT_* and STB_* and STV_* constants into the gabi module 2022-10-06 15:14:32 -07:00
Christopher Cole
11b7addf97 Specify edition 2021 and fix it up
```
$ cargo fix --edition
    Checking elf v0.0.12 (/Users/chris/code/rust-elf)
   Migrating src/lib.rs from 2015 edition to 2018
       Fixed src/lib.rs (1 fix)
       Fixed src/file.rs (3 fixes)
       Fixed src/parse.rs (1 fix)
       Fixed src/section.rs (4 fixes)
       Fixed src/segment.rs (4 fixes)
       Fixed src/utils.rs (3 fixes)
       Fixed src/segment.rs (4 fixes)
       Fixed src/lib.rs (1 fix)
       Fixed src/section.rs (4 fixes)
       Fixed src/file.rs (3 fixes)
    Finished dev [unoptimized + debuginfo] target(s) in 0.47s
```
2022-10-06 13:49:07 -07:00
Christopher Cole
8427ef124e Move Symbol type definitions into symbol.rs
Also, remove types.rs now that its empty! Yay!
2022-10-06 13:35:10 -07:00
Christopher Cole
c6e4073af4 Implement FileHeader parsing with the Parse trait
Also move FileHeader into file.rs
2022-10-06 13:26:19 -07:00
Christopher Cole
3abd5b445e Move SHT_* and SHF_* constants into the gabi module 2022-10-06 12:07:04 -07:00
Christopher Cole
d9dd934f8c Change Parse trait implementers to shorten/rename utils::read_* imports to just the method names
This declutters the code a bit. It's obvious what these methods are doing and
its not important to state which module they're defined in on each invocation.
2022-10-06 01:17:41 -07:00
Christopher Cole
fcac7d79cc Implement SectionHeader parsing with the Parse trait
Also move SectionHeader into section.rs
Also, refactor the code for reading section data and section names from the section string table to be more idiomatic
2022-10-06 01:06:04 -07:00
Christopher Cole
ae9e24420d Simplify ParseError to implement the std::error::Error trait
This addresses issue #15
2022-10-05 22:39:04 -07:00
Christopher Cole
c3b560d3ae Move PF_* and PT_* constants into the gabi module 2022-10-05 20:47:07 -07:00
Christopher Cole
ea991f2c7f Implement ProgramHeader parsing with the Parse trait
Also move ProgramHeader into segment.rs
2022-10-05 20:18:09 -07:00
Christopher Cole
9aab0d1096 Add simple Parse trait
My plan is to make the various ELF data structures implement this Parse trait which knows
how to parse that structure based on the given endianness and data width (32- or 64-bit).
2022-10-05 20:14:41 -07:00
Christopher Cole
a1ac44be39 Remove unused .travis.yml now that we use github actions 2022-10-05 02:10:01 -07:00
Christopher Cole
f9d4b29ea9 Remove unnecessary macro_use from utils
It no longer implements any macros
Also, remove the pub on mod utils, since it's only needed internally and shouldn't be considered part of the public interface
2022-10-04 17:19:24 -07:00
Christopher Cole
8fabd83f8b Remove unnecessary File::new and FileHeader::new 2022-10-04 17:06:13 -07:00
Christopher Cole
3354ce5553 Extract parse_ehdr function that handles 32/64 bit Elf_Ehdr parsing
with some simple unit tests
2022-10-04 16:49:04 -07:00
Christopher Cole
147b8c404b Run rustfmt with default config 2022-10-04 15:30:06 -07:00
Christopher Cole
75adb4f1a5 Extract ELF File Headdr e_ident[] parsing into its own tested function 2022-10-04 13:57:39 -07:00
Christopher Cole
8373835dd8 Compare ELFMAGIC bits as a byte slice 2022-10-04 12:31:52 -07:00
Christopher Cole
aff2d776ee Add the rest of the ELF File Header e_* fields to FileHeader
These were already being parsed but not put onto the struct.
2022-10-03 22:45:17 -07:00
Christopher Cole
4db2b9065e Split Generic System V Application Binary Interface ELF File Header constants out into gabi.rs
This patch starts changing the type representations for our ELF types. It splits out the raw constants defined in
the Generic System V Application Binary Interface out into its own file (gabi.rs) as native type constants. The
type definitions in types.rs are now left to be higher level semantic representations of these fields which may
or may not directly map to the on-disk ELF data layout.

The intent here is to structure the code such that the opinionated rust representation of these parsed ELF structures
live separately from the official gabi definitions. This could set us up for a future where consumers of this library that
desire their own different rust representations of parsed ELF structures to consume the gabi definitions without
also having to much about with our representations here.
2022-10-03 20:34:23 -07:00
Christopher Cole
4965746e79 Update Cargo.toml documentation link to point to docs.rs 2022-10-03 17:57:45 -07:00
Christopher Cole
6a4bd829cf Bump crate version to 0.0.12 to remove byteorder dependency 2022-10-03 17:44:47 -07:00
Christopher Cole
9b152e99de Replace byteorder crate dependency with safe transmute methods from std:: integer types 2022-10-03 17:38:22 -07:00
Christopher Cole
1354885276
Use docs.rs for Documentation link in README.md 2022-10-03 12:33:37 -07:00
Christopher Cole
c772d63b93
Change README.md badges
Point them to github action results, crates.io, and docs.rs
2022-10-03 12:28:09 -07:00
Christopher Cole
f9cfa292c1
Add initial github action CI configuration 2022-10-03 12:12:52 -07:00
Christopher Cole
a42f74c08d Add EM_BPF for linux eBPF vm programs 2022-10-03 00:33:15 -07:00
Christopher Cole
2c428df23c Sync ELF File Header e_machine definitions into type definitions
Values and Names pulled from http://www.sco.com/developers/gabi/latest/ch4.eheader.html
2022-10-03 00:14:39 -07:00
Christopher Cole
ce65abaecc Update byteorder to 1.x and bump our crate version now that this builds on rust 1.64.0 2022-10-02 23:19:44 -07:00
Christopher Cole
c4a9732fef Prefix unused parsing vars with _ to signal to the compiler that its intended 2022-10-02 23:04:19 -07:00
Christopher Cole
e1ba759253 Use a ParseError::EndianError rather than panicking 2022-10-02 23:02:43 -07:00
Christopher Cole
e604816c15 Replace usages of try with the ? operator 2022-10-02 23:02:07 -07:00
Christopher Cole
48e4313ce4 Use the dyn keyword to specify parse_symbol takes a ref to a Read trait object. 2022-10-02 22:43:27 -07:00
Christopher Cole
44654da0c6 Merge pull request #14 from Wilfred/patch-1
Vec<u8> values cannot be printed
2016-10-09 09:32:22 -07:00
Wilfred Hughes
a4416bc638 env is also unused 2016-10-08 11:00:30 -04:00
Wilfred Hughes
fa22515e06 Vec<u8> values cannot be printed
So show the debug format instead.
2016-10-08 00:03:13 -04:00
Christopher Cole
4141543ed9 Bump version to 0.0.10 2016-09-22 21:28:42 -07:00
Christopher Cole
0d3fc977d3 Merge pull request #12 from isra17/master
Fix NOBITS section parsing.
2016-09-22 21:16:55 -07:00
isra17
b48cf9088b Fix NOBITS section parsing.
Old behaviour was panicking when an ELF file has a .bss offset + size greater
than the file size.
2016-09-15 23:48:58 -04:00
Christopher Cole
8a31cdbff5 Merge pull request #11 from philipc/get_symbols
Add File::get_symbols()
2016-07-06 09:02:12 -07:00
Philip Craig
d957556a49 Add File::get_symbols() 2016-06-21 14:44:53 +10:00
Philip Craig
f889fad958 Use read_exact()
`take(len).read_to_end()` can read less `len` bytes.
2016-06-19 14:50:07 +10:00
Christopher Cole
e45bb844f6 Bump version to 0.0.9 2016-04-20 21:55:34 -07:00
Christopher Cole
2810b1b803 Move rust-readelf out into its own package 2016-04-20 21:03:18 -07:00
Christopher Cole
0a9f684c9b Bump version to 0.0.8 2016-04-06 14:01:13 -07:00
Christopher Cole
02863a2e9b Update README.md example to reflect reality 2016-04-06 14:00:24 -07:00
Christopher Cole
07f2242f59 Clean up compiler warnings
Intermediate parsing variables don't need to be mut.
2016-04-06 13:43:58 -07:00
Christopher Cole
66c5d77a46 Merge pull request #10 from jcreekmore/bug-fixes
Remove the read_u8!() macro
2016-04-06 13:43:12 -07:00
Jonathan Creekmore
a81e7e7b54 Remove the read_u8!() macro
The read_u8!() macro is unnecessary since there are not endianness
considers reading a u8. Additionally, the macro is broken because it
tries to specialize the read_u8 function in the ReadBytesExt trait
for LittleEndian and BigEndian which is not supported by that API.
2016-04-06 12:51:54 -05:00
Christopher Cole
e10b5fbbb8 Bump version to 0.0.7 2016-04-05 02:51:24 +00:00