This commit is contained in:
nora 2023-02-12 13:03:54 +01:00
parent 84f4ab4297
commit 94a6a0e999
2 changed files with 17 additions and 9 deletions

View file

@ -2,7 +2,7 @@ use std::{fmt::Display, fs::File};
use anyhow::Context; use anyhow::Context;
use elven_parser::{ use elven_parser::{
consts::{DynamicTag, ShType, RX86_64}, consts::{self as c, DynamicTag, ShType, RX86_64},
defs::{Addr, Elf}, defs::{Addr, Elf},
ElfParseError, ElfParseError,
}; };
@ -25,19 +25,20 @@ struct HeaderTable<'a>(&'static str, &'a dyn Display);
#[derive(Tabled)] #[derive(Tabled)]
struct SectionTable { struct SectionTable {
name: String, name: String,
size: u64,
#[tabled(rename = "type")] #[tabled(rename = "type")]
r#type: ShType, r#type: ShType,
size: u64,
offset: u64,
} }
#[derive(Tabled)] #[derive(Tabled)]
struct RelaTable { struct RelaTable {
section: String, section: String,
symbol: String, symbol: String,
offset: u64, offset: Addr,
#[tabled(rename = "type")] #[tabled(rename = "type")]
r#type: RX86_64, r#type: RX86_64,
addend: u64, addend: i64,
} }
#[derive(Tabled)] #[derive(Tabled)]
@ -82,8 +83,9 @@ fn print_file(path: &str) -> anyhow::Result<()> {
let name = elf.sh_string(sh.name)?.to_string(); let name = elf.sh_string(sh.name)?.to_string();
Ok(SectionTable { Ok(SectionTable {
name, name,
size: sh.size,
r#type: sh.r#type, r#type: sh.r#type,
size: sh.size,
offset: sh.offset.0,
}) })
}) })
.collect::<Result<Vec<_>, ElfParseError>>()?; .collect::<Result<Vec<_>, ElfParseError>>()?;
@ -98,10 +100,16 @@ fn print_file(path: &str) -> anyhow::Result<()> {
let section = elf.sh_string(sh.name)?.to_string(); let section = elf.sh_string(sh.name)?.to_string();
let sym = elf.symbol(rela.info.sym())?; let sym = elf.symbol(rela.info.sym())?;
let symbol = elf.string(sym.name)?.to_string();
let offset = rela.offset.0; let symbol = if sym.info.r#type() == c::STT_SECTION {
let r#type = elven_parser::consts::RX86_64(rela.info.r#type()); elf.sh_string(elf.section_header(sym.shndx)?.name)?
.to_string()
} else {
elf.string(sym.name)?.to_string()
};
let offset = Addr(rela.offset.0);
let r#type = c::RX86_64(rela.info.r#type());
let addend = rela.addend; let addend = rela.addend;
Ok(RelaTable { Ok(RelaTable {

View file

@ -165,7 +165,7 @@ pub struct Rel {
pub struct Rela { pub struct Rela {
pub offset: Addr, pub offset: Addr,
pub info: RelInfo, pub info: RelInfo,
pub addend: u64, pub addend: i64,
} }
#[derive(Clone, Copy, Zeroable, Pod)] #[derive(Clone, Copy, Zeroable, Pod)]