Skip to content

Commit 82264ef

Browse files
committed
libmwemu logger for direct lib usage, use emu.init_logger(), readme update, and crate update
1 parent 0408093 commit 82264ef

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/libmwemu/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "libmwemu"
3-
version = "0.22.0"
3+
version = "0.22.1"
44
edition = "2018"
55
authors = ["sha0coder"]
66
license = "MIT"
@@ -34,6 +34,7 @@ slab = { version = "0.4.10", features=["serde"] }
3434
bytemuck = "1.23.1"
3535
minidump = "0.26.0"
3636
serde_yaml = "0.9"
37+
fast_log = { version = "1.7" }
3738

3839
[dev-dependencies]
3940
env_logger = "0.11.8"

crates/libmwemu/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ use libmwemu::emu32;
1818
fn main() {
1919
let mut emu = emu32();
2020
emu.set_maps_folder("/tmp/maps32/");
21-
emu.init(false, false);
21+
emu.init_logger();
2222
```
2323

2424
Load your shellcode or PE binary and run the emulator.
2525
None parameter means emulate for-ever.
2626

2727
```rust
28+
// emu.init(false, false); needed if load_code is not called
2829
emu.load_code("shellcodes32/shikata.bin");
2930
emu.set_verbose(2);
3031
emu.run(None).unwrap();

crates/libmwemu/src/emu/initialization.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,28 @@ use crate::peb::{peb32, peb64};
1414
use crate::{get_bit, kuser_shared, set_bit, structures, winapi::winapi32, winapi::winapi64};
1515
use crate::{banzai::Banzai, breakpoint::Breakpoints, colors::Colors, config::Config, global_locks::GlobalLocks, hooks::Hooks, maps::Maps, thread_context::ThreadContext};
1616

17+
use fast_log::appender::{Command, FastLogRecord, RecordFormat};
18+
19+
pub struct CustomLogFormat;
20+
impl RecordFormat for CustomLogFormat {
21+
fn do_format(&self, arg: &mut FastLogRecord) {
22+
match &arg.command {
23+
Command::CommandRecord => {
24+
arg.formated = format!("{}\n", arg.args);
25+
}
26+
Command::CommandExit => {}
27+
Command::CommandFlush(_) => {}
28+
}
29+
}
30+
}
31+
32+
impl CustomLogFormat {
33+
pub fn new() -> CustomLogFormat {
34+
Self {}
35+
}
36+
37+
}
38+
1739
impl Emu {
1840
pub fn new() -> Emu {
1941
let mut formatter = IntelFormatter::new();
@@ -179,6 +201,13 @@ impl Emu {
179201
self.flags_mut().f_nt = false;
180202
}
181203

204+
pub fn init_logger(&mut self) {
205+
fast_log::init(fast_log::Config::new()
206+
.format(CustomLogFormat::new())
207+
.console()
208+
.chan_len(Some(100000))).unwrap();
209+
}
210+
182211
/// Initialize windows simulator, this does like init_cpu() but also setup the windows memory.
183212
/// This is called from load_code if the code is a PE or shellcode.
184213
/// load_code_bytes() and other loading ways don't call this, if you need windows simulation call this.

crates/libmwemu/src/emu/maps.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use crate::emu::Emu;
55
impl Emu {
66
/// For simulating a windows process space, select the folder with maps32 or maps64 depending upon the arch, do this before loading the binary.
77
pub fn set_maps_folder(&mut self, folder: &str) {
8-
let mut f = folder.to_string();
9-
f.push('/');
8+
//let mut f = folder.to_string();
9+
//f.push('/');
1010
self.cfg.maps_folder = folder.to_string();
1111

1212
// Check if maps folder exists and contains essential files
@@ -142,4 +142,4 @@ impl Emu {
142142
addr
143143
}
144144

145-
}
145+
}

0 commit comments

Comments
 (0)