From 5ee80c93644d4298976a8d64c62895b430d90cd3 Mon Sep 17 00:00:00 2001 From: Marco Thomas Date: Tue, 3 Jun 2025 10:30:35 +0900 Subject: [PATCH] fix: read data section as words, not bytes --- src/aout.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/aout.rs b/src/aout.rs index 2cac670..b690eb2 100644 --- a/src/aout.rs +++ b/src/aout.rs @@ -3,6 +3,8 @@ use core::fmt; use std::ffi::{c_uchar, c_ushort}; +use crate::operands::{Byte, Word}; + #[allow(non_camel_case_types)] pub type c_long = i32; // we use a a.out with 32 byte @@ -10,8 +12,8 @@ pub type c_long = i32; // we use a a.out with 32 byte /// Internal representation of the a.out binary format. pub struct Aout { pub header: Header, - pub text: Vec, - pub data: Vec, + pub text: Vec, + pub data: Vec, } impl fmt::Display for Aout { @@ -46,11 +48,15 @@ impl Aout { let text_section = &buf[text_start..text_end]; let data_section = &buf[data_start..data_end]; + let data_words: Vec = data_section + .chunks_exact(2) + .map(|chunk| u16::from_le_bytes(chunk.try_into().unwrap())) + .collect(); Aout { header: hdr, text: Vec::from(text_section), - data: Vec::from(data_section), + data: Vec::from(data_words), } } }