diff --git a/fuzzers/qemu_systemmode/README.md b/fuzzers/qemu_systemmode/README.md index db7321e014..14098dc09c 100644 --- a/fuzzers/qemu_systemmode/README.md +++ b/fuzzers/qemu_systemmode/README.md @@ -21,6 +21,6 @@ Create on and then run the fuzzer: # create an image qemu-img create -f qcow2 dummy.qcow2 32M # run the fuzzer -KERNEL=./example/example.elf target/release/qemu_launcher -icount shift=auto,align=off,sleep=off -machine mps2-an385 -monitor null -kernel ./example/example.elf -serial null -nographic -snapshot -drive if=none,format=qcow2,file=dummy.qcow2 -S +KERNEL=./example/example.elf target/release/qemu_systemmode -icount shift=auto,align=off,sleep=off -machine mps2-an385 -monitor null -kernel ./example/example.elf -serial null -nographic -snapshot -drive if=none,format=qcow2,file=dummy.qcow2 -S ``` Currently the ``KERNEL`` variable is needed because the fuzzer does not parse QEMUs arguments to find the binary. \ No newline at end of file diff --git a/fuzzers/qemu_systemmode/src/fuzzer.rs b/fuzzers/qemu_systemmode/src/fuzzer.rs index 65e98fc776..d7bf9f5910 100644 --- a/fuzzers/qemu_systemmode/src/fuzzer.rs +++ b/fuzzers/qemu_systemmode/src/fuzzer.rs @@ -36,20 +36,20 @@ use libafl_qemu::{ edges::QemuEdgeCoverageHelper, elf::EasyElf, emu::Emulator, + GuestAddr, //snapshot::QemuSnapshotHelper, QemuExecutor, QemuHooks, Regs, }; -fn virt2phys(vaddr: u32, tab: &EasyElf) -> u32 { +/// Read ELF program headers to resolve physical load addresses. +fn virt2phys(vaddr: GuestAddr, tab: &EasyElf) -> GuestAddr { let ret; for i in &tab.goblin().program_headers { - if i.vm_range() - .contains(&vaddr.try_into().expect("Can not cast u64 to usize")) - { - ret = vaddr - TryInto::::try_into(i.p_vaddr).unwrap() - + TryInto::::try_into(i.p_paddr).unwrap(); + if i.vm_range().contains(&vaddr.try_into().unwrap()) { + ret = vaddr - TryInto::::try_into(i.p_vaddr).unwrap() + + TryInto::::try_into(i.p_paddr).unwrap(); return ret - (ret % 2); } } @@ -113,7 +113,7 @@ pub fn fuzz() { // len = MAX_INPUT_SIZE; } - emu.write_mem(input_addr, buf); + emu.write_phys_mem(input_addr, buf); emu.run();