mod cfg;
mod decoder;
mod flags;
mod ssa;
mod types;
pub use cfg::{X86BasicBlock, X86Function};
pub use decoder::{
x86_decode_all, x86_decode_single, x86_decode_traversal, x86_detect_epilogue,
x86_detect_prologue, x86_native_body_size, X86TraversalDecodeResult,
};
pub use types::{
X86Condition, X86DecodedInstruction, X86EdgeKind, X86EpilogueInfo, X86Instruction, X86Memory,
X86Operand, X86PrologueInfo, X86PrologueKind, X86Register,
};
pub use ssa::X86ToSsaTranslator;
#[cfg(test)]
mod tests {
use crate::analysis::{
x86::{
x86_decode_all, x86_detect_prologue, X86Function, X86Instruction, X86Operand,
X86PrologueKind, X86Register, X86ToSsaTranslator,
},
ConstValue, SsaEvaluator, SsaOp,
};
use crate::metadata::typesystem::PointerSize;
#[test]
fn test_full_pipeline_linear() {
let bytes = [
0x58, 0x83, 0xc0, 0x05, 0xc3, ];
let instructions = x86_decode_all(&bytes, 32, 0).unwrap();
assert_eq!(instructions.len(), 3);
let cfg = X86Function::new(&instructions, 32, 0);
assert_eq!(cfg.block_count(), 1);
assert!(!cfg.has_loops());
assert!(cfg.is_reducible());
}
#[test]
fn test_full_pipeline_conditional() {
let bytes = [
0x58, 0x83, 0xf8, 0x0a, 0x7d, 0x03, 0x83, 0xc0, 0x05, 0xc3, ];
let instructions = x86_decode_all(&bytes, 32, 0).unwrap();
let cfg = X86Function::new(&instructions, 32, 0);
assert!(cfg.block_count() >= 2);
assert!(!cfg.has_loops());
assert!(cfg.is_reducible());
}
#[test]
fn test_full_pipeline_loop() {
let bytes = [
0x58, 0x83, 0xf8, 0x00, 0x7e, 0x04, 0x48, 0xeb, 0xf8, 0xc3, ];
let instructions = x86_decode_all(&bytes, 32, 0).unwrap();
let cfg = X86Function::new(&instructions, 32, 0);
assert!(cfg.has_loops());
assert!(cfg.is_reducible()); }
#[test]
fn test_dyncipher_prologue_detection() {
let prologue_bytes = [
0x89, 0xe0, 0x53, 0x57, 0x56, 0x29, 0xe0, 0x83, 0xf8, 0x18, 0x74, 0x07, 0x8b, 0x44, 0x24, 0x10, 0x50, 0xeb, 0x01, 0x51, 0xb8, 0x01, 0x00, 0x00, 0x00, 0x5e, 0x5f, 0x5b, 0xc3, ];
let prologue = x86_detect_prologue(&prologue_bytes, 32);
assert_eq!(prologue.kind, X86PrologueKind::DynCipher);
assert_eq!(prologue.size, 20);
}
#[test]
fn test_64bit_support() {
let bytes = [
0x48, 0xb8, 0x89, 0x67, 0x45, 0x23, 0x01, 0x00, 0x00,
0x00, 0xc3, ];
let instructions = x86_decode_all(&bytes, 64, 0).unwrap();
assert_eq!(instructions.len(), 2);
match &instructions[0].instruction {
X86Instruction::Mov { dst, src } => {
assert_eq!(dst.as_register(), Some(X86Register::Rax));
assert_eq!(src.as_immediate(), Some(0x123456789));
}
_ => panic!("Expected Mov instruction"),
}
}
#[test]
fn test_memory_operand() {
let bytes = [
0x8b, 0x44, 0x8b, 0x08, 0xc3, ];
let instructions = x86_decode_all(&bytes, 32, 0).unwrap();
match &instructions[0].instruction {
X86Instruction::Mov { src, .. } => match src {
X86Operand::Memory(mem) => {
assert_eq!(mem.base, Some(X86Register::Ebx));
assert_eq!(mem.index, Some(X86Register::Ecx));
assert_eq!(mem.scale, 4);
assert_eq!(mem.displacement, 8);
}
_ => panic!("Expected memory operand"),
},
_ => panic!("Expected Mov instruction"),
}
}
fn eval_x86_stub(body: &[u8], input: i32) -> i32 {
let instructions =
x86_decode_all(body, 32, 0).unwrap_or_else(|e| panic!("decode failed: {e}"));
let cfg = X86Function::new(&instructions, 32, 0);
let translator = X86ToSsaTranslator::new(&cfg);
let ssa = translator
.translate()
.unwrap_or_else(|e| panic!("SSA translation failed: {e}"));
assert_eq!(ssa.block_count(), 1, "expected single-block function");
let arg_var = ssa
.argument_variables()
.next()
.expect("no argument variable");
let arg_id = arg_var.id();
let mut eval = SsaEvaluator::new(&ssa, PointerSize::Bit32);
eval.set_concrete(arg_id, ConstValue::I32(input));
let trace = eval.execute(0, None, 50);
assert!(trace.is_complete(), "evaluation did not complete");
let block = ssa.block(0).unwrap();
for instr in block.instructions() {
if let SsaOp::Return {
value: Some(ret_var),
} = instr.op()
{
return eval
.get_concrete(*ret_var)
.and_then(|v| v.as_i32())
.expect("return value not concrete i32");
}
}
panic!("no Return instruction found");
}
fn verify_x86_stub_ssa(body: &[u8], expected_instructions: usize) {
let instructions =
x86_decode_all(body, 32, 0).unwrap_or_else(|e| panic!("decode failed: {e}"));
assert_eq!(
instructions.len(),
expected_instructions,
"instruction count mismatch"
);
let cfg = X86Function::new(&instructions, 32, 0);
assert_eq!(cfg.block_count(), 1, "expected single-block CFG");
assert!(!cfg.has_loops(), "no loops expected");
let translator = X86ToSsaTranslator::new(&cfg);
let ssa = translator
.translate()
.unwrap_or_else(|e| panic!("SSA translation failed: {e}"));
assert_eq!(ssa.block_count(), 1, "expected single-block SSA");
let block = ssa.block(0).unwrap();
let last = block.instructions().last().expect("no instructions");
assert!(
matches!(last.op(), SsaOp::Return { value: Some(_) }),
"expected Return with value, got {:?}",
last.op()
);
}
#[test]
fn test_confuserex_constants_x86_stub1() {
let body: &[u8] = &[
0x58, 0xb9, 0x06, 0x13, 0xa4, 0x66, 0xf7, 0xd1, 0x29, 0xc8, 0xf7, 0xd8, 0xf7, 0xd0,
0xf7, 0xd8, 0x5e, 0x5f, 0x5b, 0xc3,
];
verify_x86_stub_ssa(body, 11);
let not_c = !0x66a41306i32; for input in [0, 100, -1, i32::MAX] {
let result = eval_x86_stub(body, input);
let step1 = input.wrapping_sub(not_c); let step2 = step1.wrapping_neg(); let step3 = !step2; let expected = step3.wrapping_neg(); assert_eq!(result, expected, "stub1 failed for input {input}");
}
}
#[test]
fn test_confuserex_constants_x86_stub2() {
let body: &[u8] = &[
0x58, 0x69, 0xc0, 0x0b, 0x5c, 0x1c, 0xb1, 0x69, 0xc0, 0x27, 0xdc, 0xae, 0x1a, 0xf7,
0xd0, 0x5e, 0x5f, 0x5b, 0xc3,
];
verify_x86_stub_ssa(body, 8);
let result = eval_x86_stub(body, 42);
let expected = !42i32.wrapping_mul(-1323541493).wrapping_mul(447667239);
assert_eq!(result, expected);
}
#[test]
fn test_confuserex_constants_x86_stub3() {
let body: &[u8] = &[
0xb8, 0x65, 0x11, 0x90, 0x52, 0x81, 0xf0, 0xab, 0x5d, 0xfc, 0xf5, 0xf7, 0xd0, 0xb9,
0x10, 0x3c, 0x13, 0xf3, 0xf7, 0xd1, 0xba, 0x8c, 0xe0, 0xc2, 0x76, 0x81, 0xf2, 0xb7,
0x0a, 0x54, 0x5b, 0x31, 0xd1, 0x31, 0xc8, 0x59, 0x29, 0xc8, 0xf7, 0xd0, 0x69, 0xc0,
0x85, 0x46, 0x7b, 0xd6, 0xf7, 0xd8, 0x5e, 0x5f, 0x5b, 0xc3,
];
verify_x86_stub_ssa(body, 18);
let r1 = eval_x86_stub(body, 1000);
let r2 = eval_x86_stub(body, 1000);
assert_eq!(r1, r2);
let r3 = eval_x86_stub(body, 1001);
assert_ne!(r1, r3);
}
#[test]
fn test_confuserex_controlflow_x86_stub1() {
let body: &[u8] = &[
0x58, 0xb9, 0x70, 0x92, 0x47, 0x1d, 0x69, 0xc9, 0xdb, 0x75, 0x70, 0x90, 0xf7, 0xd9,
0x31, 0xc8, 0xf7, 0xd0, 0x69, 0xc0, 0xe7, 0x21, 0xf0, 0x0a, 0x81, 0xf0, 0xdf, 0x98,
0x2b, 0x69, 0x5e, 0x5f, 0x5b, 0xc3,
];
verify_x86_stub_ssa(body, 12);
let r = eval_x86_stub(body, 0);
let ecx = 491229808i32.wrapping_mul(-1871677989).wrapping_neg();
let expected = !ecx;
let expected = expected.wrapping_mul(183509479) ^ 1764464863;
assert_eq!(r, expected);
}
#[test]
fn test_confuserex_controlflow_x86_stub3() {
let body: &[u8] = &[
0x58, 0xf7, 0xd0, 0xb9, 0xde, 0x1b, 0xb2, 0x4e, 0xf7, 0xd1, 0xba, 0x0d, 0x29, 0xa7,
0x24, 0xf7, 0xda, 0x31, 0xd1, 0x31, 0xc8, 0x5e, 0x5f, 0x5b, 0xc3,
];
verify_x86_stub_ssa(body, 12);
let r = eval_x86_stub(body, 12345);
let ecx = !1320295390i32 ^ 614934797i32.wrapping_neg();
let expected = !12345i32 ^ ecx;
assert_eq!(r, expected);
}
#[test]
fn test_confuserex_constants_x86_cf_stub4() {
let body: &[u8] = &[
0x58, 0x69, 0xc0, 0x11, 0xde, 0xe5, 0x4a, 0xf7, 0xd8, 0x5e, 0x5f, 0x5b, 0xc3,
];
verify_x86_stub_ssa(body, 7);
let r = eval_x86_stub(body, 7);
assert_eq!(r, 7i32.wrapping_mul(1256578577).wrapping_neg());
let r = eval_x86_stub(body, -1);
assert_eq!(r, (-1i32).wrapping_mul(1256578577).wrapping_neg());
}
#[test]
fn test_confuserex_constants_x86_cf_stub5() {
let body: &[u8] = &[
0x58, 0xf7, 0xd0, 0x69, 0xc0, 0x53, 0x44, 0x4f, 0xfc, 0x69, 0xc0, 0xb5, 0x5f, 0x0b,
0xc6, 0x81, 0xc0, 0x33, 0x7c, 0x49, 0xdf, 0x5e, 0x5f, 0x5b, 0xc3,
];
verify_x86_stub_ssa(body, 9);
let r = eval_x86_stub(body, 0);
let expected = (!0i32)
.wrapping_mul(-61914029)
.wrapping_mul(-972333131)
.wrapping_add(-548832205);
assert_eq!(r, expected);
}
#[test]
fn test_confuserex_identity_stub() {
let body: &[u8] = &[0x58, 0xf7, 0xd8, 0xf7, 0xd8, 0x5e, 0x5f, 0x5b, 0xc3];
verify_x86_stub_ssa(body, 7);
for input in [0, 1, -1, 42, i32::MAX, i32::MIN, 0x12345678] {
assert_eq!(
eval_x86_stub(body, input),
input,
"identity stub failed for input {input}"
);
}
}
#[test]
fn test_confuserex_constants_x86_cf_x86_stub7() {
let body: &[u8] = &[
0x58, 0xf7, 0xd0, 0xf7, 0xd8, 0x69, 0xc0, 0x87, 0xfa, 0x10, 0xb0, 0x69, 0xc0, 0x39,
0x25, 0x7d, 0xee, 0x5e, 0x5f, 0x5b, 0xc3,
];
verify_x86_stub_ssa(body, 9);
let r = eval_x86_stub(body, 99);
let expected = (!99i32)
.wrapping_neg()
.wrapping_mul(-1341064569)
.wrapping_mul(-293788359);
assert_eq!(r, expected);
}
#[test]
fn test_confuserex_constants_x86_cf_x86_stub11() {
let body: &[u8] = &[
0x58, 0xf7, 0xd8, 0x69, 0xc0, 0x4b, 0xe2, 0xf1, 0x77, 0x69, 0xc0, 0x6d, 0xad, 0x6e,
0xc6, 0x5e, 0x5f, 0x5b, 0xc3,
];
verify_x86_stub_ssa(body, 8);
let r = eval_x86_stub(body, 55);
let expected = 55i32
.wrapping_neg()
.wrapping_mul(2012340811)
.wrapping_mul(-965825171);
assert_eq!(r, expected);
}
#[test]
fn test_confuserex_largest_stub() {
let body: &[u8] = &[
0x58, 0xb9, 0x9c, 0xe0, 0x3c, 0x3a, 0x81, 0xc1, 0xbf, 0x9c, 0x8f, 0xac, 0xba, 0x73,
0xa2, 0xad, 0xee, 0x81, 0xea, 0x69, 0xad, 0x28, 0xfb, 0x31, 0xd1, 0xba, 0xc4, 0xcc,
0xb2, 0xd5, 0x69, 0xd2, 0x05, 0x1d, 0xc8, 0x55, 0xbb, 0x11, 0x49, 0x0f, 0x2a, 0x69,
0xdb, 0xf3, 0x9c, 0xce, 0xcc, 0x29, 0xda, 0x31, 0xd1, 0x01, 0xc8, 0xb9, 0x10, 0x9e,
0x73, 0xca, 0x81, 0xe9, 0xd2, 0x03, 0x3e, 0xd2, 0xba, 0xab, 0xc5, 0x17, 0x5d, 0xf7,
0xd2, 0x31, 0xd1, 0x01, 0xc8, 0xb9, 0x39, 0x42, 0x5c, 0xab, 0x69, 0xc9, 0xc0, 0xb6,
0x6e, 0xa0, 0x29, 0xc8, 0xf7, 0xd0, 0x5e, 0x5f, 0x5b, 0xc3,
];
verify_x86_stub_ssa(body, 27);
let r1 = eval_x86_stub(body, 0);
let r2 = eval_x86_stub(body, 0);
assert_eq!(r1, r2);
let r3 = eval_x86_stub(body, 1);
assert_ne!(r1, r3);
}
#[test]
fn test_confuserex_stub_with_pop_ecx_arg() {
let body: &[u8] = &[
0xb8, 0xf4, 0xd9, 0x38, 0x51, 0xf7, 0xd8, 0x59, 0xba, 0xd1, 0x84, 0x10, 0x2c, 0xf7,
0xd2, 0x29, 0xd1, 0xf7, 0xd9, 0x29, 0xc8, 0x81, 0xf0, 0x76, 0x8e, 0x58, 0x13, 0x5e,
0x5f, 0x5b, 0xc3,
];
verify_x86_stub_ssa(body, 13);
let r1 = eval_x86_stub(body, 500);
let r2 = eval_x86_stub(body, 500);
assert_eq!(r1, r2);
}
#[test]
fn test_confuserex_all_stubs_decode_and_translate() {
let all_stubs: &[(&[u8], usize)] = &[
(
&[
0x58, 0xb9, 0x06, 0x13, 0xa4, 0x66, 0xf7, 0xd1, 0x29, 0xc8, 0xf7, 0xd8, 0xf7,
0xd0, 0xf7, 0xd8, 0x5e, 0x5f, 0x5b, 0xc3,
],
11,
),
(
&[
0x58, 0x69, 0xc0, 0x0b, 0x5c, 0x1c, 0xb1, 0x69, 0xc0, 0x27, 0xdc, 0xae, 0x1a,
0xf7, 0xd0, 0x5e, 0x5f, 0x5b, 0xc3,
],
8,
),
(
&[
0xb8, 0x65, 0x11, 0x90, 0x52, 0x81, 0xf0, 0xab, 0x5d, 0xfc, 0xf5, 0xf7, 0xd0,
0xb9, 0x10, 0x3c, 0x13, 0xf3, 0xf7, 0xd1, 0xba, 0x8c, 0xe0, 0xc2, 0x76, 0x81,
0xf2, 0xb7, 0x0a, 0x54, 0x5b, 0x31, 0xd1, 0x31, 0xc8, 0x59, 0x29, 0xc8, 0xf7,
0xd0, 0x69, 0xc0, 0x85, 0x46, 0x7b, 0xd6, 0xf7, 0xd8, 0x5e, 0x5f, 0x5b, 0xc3,
],
18,
),
(
&[
0x58, 0xb9, 0x0b, 0x93, 0xfa, 0x54, 0x69, 0xc9, 0xc2, 0xdb, 0x0b, 0x86, 0xba,
0x2a, 0x4d, 0xb9, 0x08, 0xf7, 0xd2, 0x29, 0xd1, 0xba, 0x60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 0x02, 0x29, 0xc8, 0x81, 0xf0, 0x7a, 0xb5, 0x45, 0x81, 0x5e, 0x5f,
0x5b, 0xc3,
],
17,
),
(
&[
0x58, 0x69, 0xc0, 0xd9, 0x26, 0xed, 0x65, 0xb9, 0xba, 0x97, 0x6e, 0x61, 0xf7,
0xd9, 0xba, 0xed, 0x1a, 0x1a, 0xcd, 0x81, 0xea, 0x38, 0x72, 0x59, 0x1d, 0x31,
0xd1, 0x01, 0xc8, 0xb9, 0x48, 0x84, 0x93, 0xbc, 0x81, 0xf1, 0x4c, 0xab, 0x34,
0xb2, 0x31, 0xc8, 0x69, 0xc0, 0x57, 0xd9, 0xa6, 0xb5, 0x5e, 0x5f, 0x5b, 0xc3,
],
16,
),
];
assert_eq!(all_stubs.len(), 33, "expected 33 total stubs");
for (i, (body, expected_instrs)) in all_stubs.iter().enumerate() {
let instructions = x86_decode_all(body, 32, 0)
.unwrap_or_else(|e| panic!("stub {i}: decode failed: {e}"));
assert_eq!(
instructions.len(),
*expected_instrs,
"stub {i}: instruction count"
);
let cfg = X86Function::new(&instructions, 32, 0);
assert_eq!(cfg.block_count(), 1, "stub {i}: block count");
let translator = X86ToSsaTranslator::new(&cfg);
let ssa = translator
.translate()
.unwrap_or_else(|e| panic!("stub {i}: SSA failed: {e}"));
assert_eq!(ssa.block_count(), 1, "stub {i}: SSA block count");
}
}
}