fix(interpreter): impl fetch and decode
I parsed all instructions before executing, but this is not how intel works. We need to decode the instructions, pointed to by IP, on the fly.
This commit is contained in:
22
src/aout.rs
22
src/aout.rs
@@ -1,9 +1,13 @@
|
||||
//! Internal a.out File abstraction.
|
||||
|
||||
use core::fmt;
|
||||
use std::ffi::{c_uchar, c_ushort};
|
||||
use std::{
|
||||
ffi::{c_uchar, c_ushort},
|
||||
fs::File,
|
||||
io::Read,
|
||||
};
|
||||
|
||||
use crate::operands::Byte;
|
||||
use crate::{Args, disasm::DisasmError, operands::Byte};
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub type c_long = i32; // we use a a.out with 32 byte
|
||||
@@ -25,6 +29,20 @@ impl fmt::Display for Aout {
|
||||
}
|
||||
|
||||
impl Aout {
|
||||
pub fn new_from_args(args: &Args) -> Self {
|
||||
let path = args
|
||||
.path
|
||||
.clone()
|
||||
.ok_or(DisasmError::NoFile(args.path.clone()))
|
||||
.unwrap();
|
||||
let mut file = File::open(path).unwrap();
|
||||
let mut buf = Vec::new();
|
||||
file.read_to_end(&mut buf).unwrap();
|
||||
let aout = Aout::new(buf);
|
||||
log::debug!("{:?}", aout);
|
||||
aout
|
||||
}
|
||||
|
||||
pub fn new(buf: Vec<u8>) -> Self {
|
||||
let hdr = Header {
|
||||
magic: [buf[0], buf[1]],
|
||||
|
||||
Reference in New Issue
Block a user