From fdafe59e13b88eb1d23e74de7d69a45598947c7e Mon Sep 17 00:00:00 2001 From: Luke Street Date: Tue, 30 Apr 2024 18:03:45 -0600 Subject: [PATCH] Adds `data:int` and `data:short` for asm output Fixes #41 --- src/analysis/objects.rs | 4 ++-- src/obj/symbols.rs | 2 ++ src/util/asm.rs | 12 ++++++++++-- src/util/config.rs | 4 ++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/analysis/objects.rs b/src/analysis/objects.rs index 6a84b6f..7a40382 100644 --- a/src/analysis/objects.rs +++ b/src/analysis/objects.rs @@ -19,8 +19,8 @@ pub fn detect_objects(obj: &mut ObjInfo) -> Result<()> { } let expected_size = match symbol.data_kind { ObjDataKind::Byte => 1, - ObjDataKind::Byte2 => 2, - ObjDataKind::Byte4 | ObjDataKind::Float => 4, + ObjDataKind::Byte2 | ObjDataKind::Short => 2, + ObjDataKind::Byte4 | ObjDataKind::Float | ObjDataKind::Int => 4, ObjDataKind::Byte8 | ObjDataKind::Double => 8, _ => 0, }; diff --git a/src/obj/symbols.rs b/src/obj/symbols.rs index 76f77e7..9f00e3d 100644 --- a/src/obj/symbols.rs +++ b/src/obj/symbols.rs @@ -172,6 +172,8 @@ pub enum ObjDataKind { String16, StringTable, String16Table, + Int, + Short, } #[derive(Debug, Clone, Default, Eq, PartialEq)] diff --git a/src/util/asm.rs b/src/util/asm.rs index 813d273..9a0133d 100644 --- a/src/util/asm.rs +++ b/src/util/asm.rs @@ -704,8 +704,8 @@ where W: Write + ?Sized { _ => {} } let chunk_size = match data_kind { - ObjDataKind::Byte2 => 2, - ObjDataKind::Unknown | ObjDataKind::Byte4 | ObjDataKind::Float => 4, + ObjDataKind::Byte2 | ObjDataKind::Short => 2, + ObjDataKind::Unknown | ObjDataKind::Byte4 | ObjDataKind::Float | ObjDataKind::Int => 4, ObjDataKind::Byte | ObjDataKind::Byte8 | ObjDataKind::Double => 8, ObjDataKind::String | ObjDataKind::String16 @@ -740,10 +740,18 @@ where W: Write + ?Sized { writeln!(w, "\t.float {data}")?; } } + 4 if data_kind == ObjDataKind::Int => { + let data = i32::from_be_bytes(chunk.try_into().unwrap()); + writeln!(w, "\t.int {data}")?; + } 4 => { let data = u32::from_be_bytes(chunk.try_into().unwrap()); writeln!(w, "\t.4byte {data:#010X}")?; } + 2 if data_kind == ObjDataKind::Short => { + let data = i16::from_be_bytes(chunk.try_into().unwrap()); + writeln!(w, "\t.short {data}")?; + } 2 => { writeln!(w, "\t.2byte {:#06X}", u16::from_be_bytes(chunk.try_into().unwrap()))?; } diff --git a/src/util/config.rs b/src/util/config.rs index 41855bf..82e9361 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -321,6 +321,8 @@ fn symbol_data_kind_to_str(kind: ObjDataKind) -> Option<&'static str> { ObjDataKind::String16 => Some("wstring"), ObjDataKind::StringTable => Some("string_table"), ObjDataKind::String16Table => Some("wstring_table"), + ObjDataKind::Int => Some("int"), + ObjDataKind::Short => Some("short"), } } @@ -372,6 +374,8 @@ fn symbol_data_kind_from_str(s: &str) -> Option { "wstring" => Some(ObjDataKind::String16), "string_table" => Some(ObjDataKind::StringTable), "wstring_table" => Some(ObjDataKind::String16Table), + "int" => Some(ObjDataKind::Int), + "short" => Some(ObjDataKind::Short), _ => None, } }