use dotscope::prelude::*;
fn main() -> Result<()> {
println!("=== Example 1: Simple Linear Code ===");
let code = [0x00, 0x2A]; let blocks = decode_blocks(&code, 0, 0x1000, None)?;
println!("Number of basic blocks: {}", blocks.len());
println!(
"Instructions in first block: {}",
blocks[0].instructions.len()
);
for (i, instruction) in blocks[0].instructions.iter().enumerate() {
println!(
" {}: {} (RVA: 0x{:X})",
i, instruction.mnemonic, instruction.rva
);
}
println!("\n=== Example 2: Conditional Branch ===");
let code = [
0x00, 0x2C, 0x02, 0x2A, 0x2A, ];
let blocks = decode_blocks(&code, 0, 0x2000, None)?;
println!("Number of basic blocks: {}", blocks.len());
for (i, block) in blocks.iter().enumerate() {
println!(
"Block {}: {} instructions, RVA: 0x{:X}",
i,
block.instructions.len(),
block.rva
);
for instruction in &block.instructions {
println!(" {} (RVA: 0x{:X})", instruction.mnemonic, instruction.rva);
}
}
println!("\n=== Example 3: With Size Limit ===");
let code = [
0x00, 0x2A, 0x00, 0x2A, ];
let blocks = decode_blocks(&code, 0, 0x3000, Some(2))?;
println!("Number of basic blocks: {}", blocks.len());
println!("Instructions in block: {}", blocks[0].instructions.len());
for instruction in &blocks[0].instructions {
println!(" {} (RVA: 0x{:X})", instruction.mnemonic, instruction.rva);
}
println!("\n✅ All examples completed successfully!");
Ok(())
}