mirror of
https://github.com/encounter/decomp-toolkit.git
synced 2025-09-30 23:19:49 +00:00
Compare commits
No commits in common. "5ee3daaf09ed83197d224a42a1ce353c1ac13157" and "5f0befc69dace41d25d2ff736f1c2144e1d26975" have entirely different histories.
5ee3daaf09
...
5f0befc69d
@ -20,6 +20,8 @@ use crate::util::{
|
|||||||
},
|
},
|
||||||
file::{buf_writer, map_file},
|
file::{buf_writer, map_file},
|
||||||
};
|
};
|
||||||
|
use crate::util::dwarf::ENDIAN;
|
||||||
|
use crate::util::reader::Endian;
|
||||||
|
|
||||||
#[derive(FromArgs, PartialEq, Debug)]
|
#[derive(FromArgs, PartialEq, Debug)]
|
||||||
/// Commands for processing DWARF 1.1 information.
|
/// Commands for processing DWARF 1.1 information.
|
||||||
@ -66,6 +68,7 @@ fn dump(args: DumpArgs) -> Result<()> {
|
|||||||
let theme = theme_set.themes.get("Solarized (dark)").context("Failed to load theme")?;
|
let theme = theme_set.themes.get("Solarized (dark)").context("Failed to load theme")?;
|
||||||
let syntax = syntax_set.find_syntax_by_name("C++").context("Failed to find syntax")?.clone();
|
let syntax = syntax_set.find_syntax_by_name("C++").context("Failed to find syntax")?.clone();
|
||||||
|
|
||||||
|
// Set Endian
|
||||||
let file = map_file(&args.in_file)?;
|
let file = map_file(&args.in_file)?;
|
||||||
let buf = file.as_slice();
|
let buf = file.as_slice();
|
||||||
if buf.starts_with(b"!<arch>\n") {
|
if buf.starts_with(b"!<arch>\n") {
|
||||||
@ -108,6 +111,11 @@ fn dump(args: DumpArgs) -> Result<()> {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let obj_file = object::read::File::parse(buf)?;
|
let obj_file = object::read::File::parse(buf)?;
|
||||||
|
|
||||||
|
// [.elf] e_ident.ei_data == ELFDATA2LSB
|
||||||
|
if obj_file.endianness() == object::Endianness::Little {
|
||||||
|
unsafe { ENDIAN = Endian::Little };
|
||||||
|
}
|
||||||
let debug_section = obj_file
|
let debug_section = obj_file
|
||||||
.section_by_name(".debug")
|
.section_by_name(".debug")
|
||||||
.ok_or_else(|| anyhow!("Failed to locate .debug section"))?;
|
.ok_or_else(|| anyhow!("Failed to locate .debug section"))?;
|
||||||
@ -130,8 +138,8 @@ fn dump_debug_section<W>(
|
|||||||
obj_file: &object::File<'_>,
|
obj_file: &object::File<'_>,
|
||||||
debug_section: Section,
|
debug_section: Section,
|
||||||
) -> Result<()>
|
) -> Result<()>
|
||||||
where
|
where
|
||||||
W: Write + ?Sized,
|
W: Write + ?Sized,
|
||||||
{
|
{
|
||||||
let mut data = debug_section.uncompressed_data()?.into_owned();
|
let mut data = debug_section.uncompressed_data()?.into_owned();
|
||||||
|
|
||||||
@ -154,14 +162,14 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut reader = Cursor::new(&*data);
|
let mut reader = Cursor::new(&*data);
|
||||||
let info = read_debug_section(&mut reader, obj_file.endianness().into())?;
|
let tags = read_debug_section(&mut reader)?;
|
||||||
|
|
||||||
for (&addr, tag) in &info.tags {
|
for (&addr, tag) in &tags {
|
||||||
log::debug!("{}: {:?}", addr, tag);
|
log::debug!("{}: {:?}", addr, tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut units = Vec::<String>::new();
|
let mut units = Vec::<String>::new();
|
||||||
if let Some((_, mut tag)) = info.tags.first_key_value() {
|
if let Some((_, mut tag)) = tags.first_key_value() {
|
||||||
loop {
|
loop {
|
||||||
match tag.kind {
|
match tag.kind {
|
||||||
TagKind::CompileUnit => {
|
TagKind::CompileUnit => {
|
||||||
@ -175,10 +183,10 @@ where
|
|||||||
}
|
}
|
||||||
writeln!(w, "\n// Compile unit: {}", unit)?;
|
writeln!(w, "\n// Compile unit: {}", unit)?;
|
||||||
|
|
||||||
let children = tag.children(&info.tags);
|
let children = tag.children(&tags);
|
||||||
let mut typedefs = BTreeMap::<u32, Vec<u32>>::new();
|
let mut typedefs = BTreeMap::<u32, Vec<u32>>::new();
|
||||||
for child in children {
|
for child in children {
|
||||||
let tag_type = match process_root_tag(&info, child) {
|
let tag_type = match process_root_tag(&tags, child) {
|
||||||
Ok(tag_type) => tag_type,
|
Ok(tag_type) => tag_type,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!(
|
log::error!(
|
||||||
@ -198,7 +206,7 @@ where
|
|||||||
if should_skip_tag(&tag_type) {
|
if should_skip_tag(&tag_type) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
match tag_type_string(&info, &typedefs, &tag_type) {
|
match tag_type_string(&tags, &typedefs, &tag_type) {
|
||||||
Ok(s) => writeln!(w, "{}", s)?,
|
Ok(s) => writeln!(w, "{}", s)?,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!(
|
log::error!(
|
||||||
@ -238,7 +246,7 @@ where
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(next) = tag.next_sibling(&info.tags) {
|
if let Some(next) = tag.next_sibling(&tags) {
|
||||||
tag = next;
|
tag = next;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -11,15 +11,6 @@ pub enum Endian {
|
|||||||
Little,
|
Little,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<object::Endianness> for Endian {
|
|
||||||
fn from(value: object::Endianness) -> Self {
|
|
||||||
match value {
|
|
||||||
object::Endianness::Big => Endian::Big,
|
|
||||||
object::Endianness::Little => Endian::Little,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const DYNAMIC_SIZE: usize = 0;
|
pub const DYNAMIC_SIZE: usize = 0;
|
||||||
|
|
||||||
pub const fn struct_size<const N: usize>(fields: [usize; N]) -> usize {
|
pub const fn struct_size<const N: usize>(fields: [usize; N]) -> usize {
|
||||||
@ -61,23 +52,9 @@ pub trait FromReader: Sized {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait FromBytes<const N: usize>: Sized {
|
|
||||||
fn from_bytes(bytes: [u8; N], e: Endian) -> Self;
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! impl_from_reader {
|
macro_rules! impl_from_reader {
|
||||||
($($t:ty),*) => {
|
($($t:ty),*) => {
|
||||||
$(
|
$(
|
||||||
impl FromBytes<{ <$t>::STATIC_SIZE }> for $t {
|
|
||||||
#[inline]
|
|
||||||
fn from_bytes(bytes: [u8; Self::STATIC_SIZE], e: Endian) -> Self {
|
|
||||||
match e {
|
|
||||||
Endian::Big => Self::from_be_bytes(bytes),
|
|
||||||
Endian::Little => Self::from_le_bytes(bytes),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FromReader for $t {
|
impl FromReader for $t {
|
||||||
const STATIC_SIZE: usize = std::mem::size_of::<Self>();
|
const STATIC_SIZE: usize = std::mem::size_of::<Self>();
|
||||||
|
|
||||||
@ -88,7 +65,10 @@ macro_rules! impl_from_reader {
|
|||||||
where R: Read + Seek + ?Sized {
|
where R: Read + Seek + ?Sized {
|
||||||
let mut buf = [0u8; Self::STATIC_SIZE];
|
let mut buf = [0u8; Self::STATIC_SIZE];
|
||||||
reader.read_exact(&mut buf)?;
|
reader.read_exact(&mut buf)?;
|
||||||
Ok(Self::from_bytes(buf, e))
|
Ok(match e {
|
||||||
|
Endian::Big => Self::from_be_bytes(buf),
|
||||||
|
Endian::Little => Self::from_le_bytes(buf),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user