fix: read data section as words, not bytes

This commit is contained in:
2025-06-03 10:30:35 +09:00
parent 4c63b7a21a
commit 5ee80c9364

View File

@@ -3,6 +3,8 @@
use core::fmt; use core::fmt;
use std::ffi::{c_uchar, c_ushort}; use std::ffi::{c_uchar, c_ushort};
use crate::operands::{Byte, Word};
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub type c_long = i32; // we use a a.out with 32 byte 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. /// Internal representation of the a.out binary format.
pub struct Aout { pub struct Aout {
pub header: Header, pub header: Header,
pub text: Vec<u8>, pub text: Vec<Byte>,
pub data: Vec<u8>, pub data: Vec<Word>,
} }
impl fmt::Display for Aout { impl fmt::Display for Aout {
@@ -46,11 +48,15 @@ impl Aout {
let text_section = &buf[text_start..text_end]; let text_section = &buf[text_start..text_end];
let data_section = &buf[data_start..data_end]; let data_section = &buf[data_start..data_end];
let data_words: Vec<Word> = data_section
.chunks_exact(2)
.map(|chunk| u16::from_le_bytes(chunk.try_into().unwrap()))
.collect();
Aout { Aout {
header: hdr, header: hdr,
text: Vec::from(text_section), text: Vec::from(text_section),
data: Vec::from(data_section), data: Vec::from(data_words),
} }
} }
} }