1use std::env;
2use std::path::Path;
3
4use reoxide::driver::*;
5
6const PROGRAM: &[u8] = &[
7 0x55, 0x48, 0x89, 0xe5, 0x53, 0x48, 0x83, 0xec, 0x18, 0x89, 0x7d, 0xec, 0x83, 0x7d, 0xec, 0x00,
8 0x74, 0x06, 0x83, 0x7d, 0xec, 0x01, 0x75, 0x07, 0xb8, 0x01, 0x00, 0x00, 0x00, 0xeb, 0x1e, 0x8b,
9 0x45, 0xec, 0x83, 0xe8, 0x01, 0x89, 0xc7, 0xe8, 0xfb, 0xfe, 0xff, 0xff, 0x89, 0xc3, 0x8b, 0x45,
10 0xec, 0x83, 0xe8, 0x02, 0x89, 0xc7, 0xe8, 0xec, 0xfe, 0xff, 0xff, 0x01, 0xd8, 0x48, 0x8b, 0x5d,
11 0xf8, 0xc9, 0xc3,
12];
13
14fn main() -> Result<(), DecompError> {
15 let ghidra_dir = env::var("GHIDRA_INSTALL_DIR").expect(
16 "Please provide an environment variable \
17 GHIDRA_INSTALL_DIR with the path to the Ghidra root directory. \
18 This is needed to find the SLEIGH specification files",
19 );
20
21 initialize_decompiler(Path::new(&ghidra_dir), true)?;
22 let mut ctx = RawFileContext::from_bytes("x86:LE:64:default", &PROGRAM)?;
23
24 let addr = 0x0;
25 ctx.define_function(addr, "fib")?;
26 let decomp = ctx.decompile_function(addr)?;
27 println!("{}", decomp);
28
29 Ok(())
30}