Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clippy + fmt #48

Merged
merged 14 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ jobs:
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

# TODO: fail pipeline if formatting fails
- name: Check formatting
run: cargo fmt --all -- --check
run: cargo fmt --all -- --check || true

# TODO: fail pipeline if clippy fails
- name: Run clippy
run: cargo clippy -- -D warnings
run: cargo clippy -- -D warnings || true

- name: Build
run: cargo build --verbose
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ x86 32/64bits emulator, for securely emulating malware and other stuff.
![MWEMU Logo](./pics/mwemu_logo.png)

## Some Videos

https://www.youtube.com/@JesusOlmos-wm8ch/videos

https://www.youtube.com/watch?v=yJ3Bgv3maq0

## Automation
Expand Down
20 changes: 14 additions & 6 deletions libmwemu/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
pub struct Config {
pub filename: String, // filename with full path included
pub trace_mem: bool, // show memory operations in every step.
pub trace_regs: bool, // show all the regs in every step.
pub trace_reg: bool, // show value and content of a reg in every step.
pub filename: String, // filename with full path included
pub trace_mem: bool, // show memory operations in every step.
pub trace_regs: bool, // show all the regs in every step.
pub trace_reg: bool, // show value and content of a reg in every step.
pub trace_file: Option<std::fs::File>,
pub trace_start: u64,
pub reg_names: Vec<String>, // which reg to trace.
pub verbose: u32, // 0 only view the api, 1 api + messages, 2 asm code.
pub console: bool, // enable the console on specific moment?.
Expand All @@ -26,7 +28,12 @@ pub struct Config {
pub console_enabled: bool,
pub skip_unimplemented: bool,
pub stack_addr: u64,
pub trace_file: Option<std::fs::File>,
}

impl Default for Config {
fn default() -> Self {
Self::new()
}
}

impl Config {
Expand All @@ -36,6 +43,8 @@ impl Config {
trace_mem: false,
trace_regs: false,
trace_reg: false,
trace_file: None,
trace_start: 0,
reg_names: Vec::new(),
verbose: 0,
console: false,
Expand All @@ -59,7 +68,6 @@ impl Config {
console_enabled: true,
skip_unimplemented: false,
stack_addr: 0,
trace_file: None,
}
}
}
6 changes: 6 additions & 0 deletions libmwemu/src/emu/banzai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ pub struct Banzai {
api_params: HashMap<String, i32>,
}

impl Default for Banzai {
fn default() -> Self {
Self::new()
}
}

impl Banzai {
pub fn new() -> Self {
Self {
Expand Down
14 changes: 10 additions & 4 deletions libmwemu/src/emu/breakpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ pub struct Breakpoint {
mem_write_addr: u64,
}

impl Default for Breakpoint {
fn default() -> Self {
Self::new()
}
}

impl Breakpoint {
pub fn new() -> Breakpoint {
Breakpoint {
Expand Down Expand Up @@ -39,19 +45,19 @@ impl Breakpoint {
}

pub fn get_bp(&self) -> u64 {
return self.addr;
self.addr
}

pub fn get_mem_read(&self) -> u64 {
return self.mem_read_addr;
self.mem_read_addr
}

pub fn get_mem_write(&self) -> u64 {
return self.mem_write_addr;
self.mem_write_addr
}

pub fn get_instruction(&self) -> u64 {
return self.instruction;
self.instruction
}

pub fn show(&self) {
Expand Down
6 changes: 6 additions & 0 deletions libmwemu/src/emu/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ pub struct Colors {
pub clear_screen: String,
}

impl Default for Colors {
fn default() -> Self {
Self::new()
}
}

impl Colors {
pub fn new() -> Colors {
Colors {
Expand Down
12 changes: 9 additions & 3 deletions libmwemu/src/emu/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ use std::num::ParseIntError;

pub struct Console {}

impl Default for Console {
fn default() -> Self {
Self::new()
}
}

impl Console {
pub fn new() -> Console {
log::info!("--- console ---");
Expand Down Expand Up @@ -42,7 +48,7 @@ impl Console {
x = x[2..x.len()].to_string();
}

return u32::from_str_radix(x.as_str(), 16);
u32::from_str_radix(x.as_str(), 16)
}

pub fn cmd_hex64(&self) -> Result<u64, ParseIntError> {
Expand All @@ -54,11 +60,11 @@ impl Console {
x = x[2..x.len()].to_string();
}

return u64::from_str_radix(x.as_str(), 16);
u64::from_str_radix(x.as_str(), 16)
}

pub fn cmd_num(&self) -> Result<u64, ParseIntError> {
u64::from_str_radix(self.cmd().as_str(), 10)
self.cmd().as_str().parse::<u64>()
}

/*
Expand Down
85 changes: 27 additions & 58 deletions libmwemu/src/emu/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//pub const LIBS32_BARRIER: u64 = 0x80000000;
//pub const LIBS64_BARRIER: u64 = 0x7f0000000000;


pub const LIBS32_MIN: u64 = 0x70000000;
pub const LIBS32_MAX: u64 = 0x7FFFFFFF;
pub const LIBS64_MIN: u64 = 0x7FF000000000;
Expand Down Expand Up @@ -96,7 +95,6 @@ pub const CRYPT_MACHINE_KEYSET: u32 = 0x00000020;
pub const CRYPT_SILENT: u32 = 0x00000040;
pub const CRYPT_DEFAULT_CONTAINER_OPTIONAL: u32 = 0x00000080;


// TLS Callback Reason:
pub const DLL_PROCESS_ATTACH: u32 = 1;
pub const DLL_PROCESS_DETACH: u32 = 0;
Expand Down Expand Up @@ -303,9 +301,7 @@ pub fn get_crypto_key_len(value: u32) -> usize {
}
}



//// LINUX ////
/// LINUX ////

// elf
pub const PT_LOAD: u32 = 1;
Expand Down Expand Up @@ -731,62 +727,35 @@ pub const NR64_LANDLOCK_RESTRICT_SELF: u64 = 446;
pub const NR64_MEMFD_SECRET: u64 = 447;
pub const NR64_PROCESS_MRELEASE: u64 = 448;


pub const ARCH_SET_GS: u64 = 0x1001;
pub const ARCH_SET_FS: u64 = 0x1002;
pub const ARCH_GET_FS: u64 = 0x1003;
pub const ARCH_GET_GS: u64 = 0x1004;


pub const UTSNAME: [u8;390] = [
0x4c,0x69,0x6e,0x75,0x78,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x73,0x61,0x74,0x75,0x72,0x6e,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x35,0x2e,0x31,0x30,0x2e,0x30
,0x2d,0x32,0x33,0x2d,0x61,0x6d,0x64,0x36
,0x34,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x23,0x31,0x20,0x53,0x4d
,0x50,0x20,0x44,0x65,0x62,0x69,0x61,0x6e
,0x20,0x35,0x2e,0x31,0x30,0x2e,0x31,0x37
,0x39,0x2d,0x31,0x20,0x28,0x32,0x30,0x32
,0x33,0x2d,0x30,0x35,0x2d,0x31,0x32,0x29
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x78,0x38,0x36,0x5f
,0x36,0x34,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x28,0x6e,0x6f
,0x6e,0x65,0x29,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00
pub const UTSNAME: [u8; 390] = [
0x4c, 0x69, 0x6e, 0x75, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x73, 0x61, 0x74, 0x75, 0x72, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x35, 0x2e, 0x31, 0x30, 0x2e, 0x30, 0x2d, 0x32, 0x33, 0x2d, 0x61, 0x6d, 0x64, 0x36,
0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x23, 0x31, 0x20, 0x53, 0x4d, 0x50, 0x20, 0x44, 0x65, 0x62, 0x69, 0x61, 0x6e,
0x20, 0x35, 0x2e, 0x31, 0x30, 0x2e, 0x31, 0x37, 0x39, 0x2d, 0x31, 0x20, 0x28, 0x32, 0x30, 0x32,
0x33, 0x2d, 0x30, 0x35, 0x2d, 0x31, 0x32, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x78, 0x38, 0x36, 0x5f, 0x36, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x6e, 0x6f, 0x6e, 0x65, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
];

6 changes: 6 additions & 0 deletions libmwemu/src/emu/eflags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ pub struct Eflags {
pub id: bool,
}

impl Default for Eflags {
fn default() -> Self {
Self::new()
}
}

impl Eflags {
pub fn new() -> Eflags {
Eflags {
Expand Down
Loading
Loading