Skip to content

Commit 8f0f631

Browse files
authored
Merge branch 'main' into main
2 parents 78979b8 + c87155f commit 8f0f631

File tree

22 files changed

+5399
-3
lines changed

22 files changed

+5399
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
It's a hardware emulator + OS process simulator implemented in pure rust.
1616

17-
This approach is very convinient to malware analysis and other stuff (PE, shellcode etc)
17+
This approach is very convenient to malware analysis and other stuff (PE, shellcode etc)
1818

1919
The OS is mainly windows, it emulates a windows process, some very basic support for linux.
2020

crates/libmwemu/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,6 @@ hex = "0.4.3"
4949

5050
[features]
5151
default = []
52+
rax_x86_tests = []
5253
log_mem_read = []
5354
log_mem_write = []

crates/libmwemu/src/elf/elf32.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ impl Elf32 {
116116
let path = base.join(filename);
117117
let mut fd = File::open(filename).expect("file not found");
118118
let mut raw = vec![0u8; 5];
119-
fd.read_exact(&mut raw).expect("couldnt read the file");
119+
let r = fd.read_exact(&mut raw);
120+
if r.is_err() {
121+
return false;
122+
}
120123

121124
if raw[0] == 0x7f
122125
&& raw[1] == b'E'

crates/libmwemu/src/elf/elf64.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,10 @@ impl Elf64 {
482482
//log::info!("checking if elf64: {}", filename);
483483
let mut fd = File::open(filename).expect("file not found");
484484
let mut raw = vec![0u8; 5];
485-
fd.read_exact(&mut raw).expect("couldnt read the file");
485+
let r = fd.read_exact(&mut raw);
486+
if r.is_err() {
487+
return false;
488+
}
486489

487490
if raw[0] == 0x7f
488491
&& raw[1] == b'E'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use crate::color;
2+
use crate::emu::Emu;
3+
use iced_x86::Instruction;
4+
5+
pub fn execute(emu: &mut Emu, ins: &Instruction, instruction_sz: usize, _rep_step: bool) -> bool {
6+
emu.show_instruction(color!("Green"), ins);
7+
false
8+
}

crates/libmwemu/src/engine/instructions/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,4 @@ pub mod xgetbv;
344344
pub mod xor;
345345
pub mod xorpd;
346346
pub mod xorps;
347+
pub mod hlt;

crates/libmwemu/src/engine/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ pub fn emulate_instruction(
366366
Mnemonic::Enqcmds => instructions::enqcmds::execute(emu, ins, instruction_sz, rep_step),
367367
Mnemonic::Enter => instructions::enter::execute(emu, ins, instruction_sz, rep_step),
368368
Mnemonic::Rdmsr => instructions::rdmsr::execute(emu, ins, instruction_sz, rep_step),
369+
Mnemonic::Hlt => instructions::hlt::execute(emu, ins, instruction_sz, rep_step),
369370
_ => {
370371
log::info!(
371372
"{} Unimplemented instruction: {:?}",

crates/libmwemu/src/flags.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,25 @@ macro_rules! set_bit {
5050
};
5151
}
5252

53+
pub const F_CF: u32 = 0;
54+
pub const F_PF: u32 = 2;
55+
pub const F_AF: u32 = 4;
56+
pub const F_ZF: u32 = 6;
57+
pub const F_SF: u32 = 7;
58+
pub const F_TF: u32 = 8;
59+
pub const F_IF: u32 = 9;
60+
pub const F_DF: u32 = 10;
61+
pub const F_OF: u32 = 11;
62+
pub const F_IOPL1: u32 = 12;
63+
pub const F_IOPL2: u32 = 13;
64+
pub const F_NT: u32 = 14;
65+
pub const F_RF: u32 = 16;
66+
pub const F_VM: u32 = 17;
67+
pub const F_AC: u32 = 18;
68+
pub const F_VIF: u32 = 19;
69+
pub const F_VIP: u32 = 20;
70+
pub const F_ID: u32 = 21;
71+
5372
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
5473
pub struct Flags {
5574
pub f_cf: bool,
@@ -123,6 +142,27 @@ impl Flags {
123142
self.f_id = false;
124143
}
125144

145+
pub fn set(&mut self) {
146+
self.f_cf = true;
147+
self.f_pf = true;
148+
self.f_af = true;
149+
self.f_zf = true;
150+
self.f_sf = true;
151+
self.f_tf = true;
152+
self.f_if = true;
153+
self.f_df = true;
154+
self.f_of = true;
155+
self.f_iopl1 = true;
156+
self.f_iopl2 = true;
157+
self.f_nt = true;
158+
self.f_rf = true;
159+
self.f_vm = true;
160+
self.f_ac = true;
161+
self.f_vif = true;
162+
self.f_vip = true;
163+
self.f_id = true;
164+
}
165+
126166
pub fn print_trace(&self, pos: u64) {
127167
let mut fs = String::new();
128168
fs.push_str("[ ");

crates/libmwemu/src/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,4 @@ mod tls_fls_tests;
6565
mod utility_functions_tests;
6666
mod winapi32_tests;
6767
mod winapi64_tests;
68+
mod rax_x86_tests;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
This x86 specific test-set are created by Kenan Sulayman https://github.com/19h/
2+
and is part of his RAX project:
3+
4+
`https://github.com/19h/rax/tree/master/tests/x86_64`
5+
6+
The tests have been converted to use libmwemu's api using some regex I prepared on regex.vim
7+
8+
9+
To trigger this tests use:
10+
```
11+
cargo test --features rax_x86_tests rax_x86_tests
12+
```

0 commit comments

Comments
 (0)