Open sajattack opened 2 months ago
It looks like I should be using from_fd
instead of from_bytes
Reopening, from_fd doesn't work either.
use std::{fs::File, io::{Seek, SeekFrom}};
use goblin::elf32::{header::Header, section_header::SectionHeader, section_header::SHT_REL};
fn main() {
let mut fd = File::open("psp-cube-example").unwrap();
let header = Header::from_fd(&mut fd).unwrap();
println!("header: {:?}" , header);
//fd.rewind().unwrap();
let section_headers = SectionHeader::from_fd(
&mut fd,
header.e_shoff.into(),
header.e_shnum.into(),
).unwrap();
let reloc_count = section_headers.iter().filter(|sh| sh.sh_type == SHT_REL).count();
println!("reloc_count: {}", reloc_count);
println!("section_headers: {:?}", section_headers);
}
Running `target/debug/goblin-repro`
header: Header { e_ident: [127, 69, 76, 70, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0], e_type: "UNKNOWN_ET", e_machine: 0x800, e_version: 0x1000000, e_entry: 0x10040000, e_phoff: 0x34000000, e_shoff: 0x446d0400, e_flags: 5100010, e_ehsize: 13312, e_phentsize: 8192, e_phnum: 1792, e_shentsize: 10240, e_shnum: 8704, e_shstrndx: 8192 }
thread 'main' panicked at src/main.rs:16:7:
called `Result::unwrap()` on an `Err` value: IO(Error { kind: UnexpectedEof, message: "failed to fill whole buffer" })
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Actual values:
[0x00000410]> iH
0x00000000 ELF MAGIC 0x464c457f
0x00000010 Type 0x0002
0x00000012 Machine 0x0008
0x00000014 Version 0x00000001
0x00000018 Entrypoint 0x00000410
0x0000001c PhOff 0x00000034
0x00000020 ShOff 0x00046d44
0x00000024 Flags 0x10001005
0x00000028 EhSize 52
0x0000002a PhentSize 32
0x0000002c PhNum 7
0x0000002e ShentSize 40
0x00000030 ShNum 34
0x00000032 ShrStrndx 32
Hello, I seem to have stumbled upon some endian-awareness issues, unless you think I'm somehow misusing the library.
I have this goblin program (simplified from my actual usecase for ease of troubleshooting)
and I have this 32-bit MIPS2 LE ELF file (uploaded as zip because github is dumb) psp-cube-example.zip
When I run this program on x86_64 Little Endian - I get the correct result. goblin_repro_x86_64.txt
When I run this program on 64-bit PowerPC - I do not. goblin_repro_ppc64.txt
I am using the default
endian_fd
feature of goblin.Here is the output of readelf -S
Let me know if there's any other details you need, I hope you may be able to reproduce using qemu-system-ppc64, but I have not explored it myself.
For extra background on what I'm actually doing, because it's kind of fun :smile: I'm trying to use rust-psp to compile a psp homebrew app on a ps3 running linux. And I hit this assertion in our psp executable repacker: https://github.com/overdrivenpotato/rust-psp/blob/bfaa487ea4881395cc64fdd82158745885222a29/cargo-psp/src/bin/prxgen.rs#L98