expose exec_path to Rust

This commit is contained in:
Andrea Fioraldi 2021-07-06 16:43:28 +02:00
parent 5454307a15
commit 8627b808a0
3 changed files with 10 additions and 1 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "qemu_libafl_bridge" name = "qemu_libafl_bridge"
version = "0.3.0" version = "0.3.1"
authors = ["Andrea Fioraldi <andreafioraldi@gmail.com>"] authors = ["Andrea Fioraldi <andreafioraldi@gmail.com>"]
description = "QEMU and LibAFL bridge lib" description = "QEMU and LibAFL bridge lib"
repository = "https://github.com/AFLplusplus/qemu-libafl-bridge/" repository = "https://github.com/AFLplusplus/qemu-libafl-bridge/"

View File

@ -1,5 +1,6 @@
use core::{convert::Into, mem::transmute, ptr::copy_nonoverlapping}; use core::{convert::Into, mem::transmute, ptr::copy_nonoverlapping};
use num::Num; use num::Num;
use std::{slice::from_raw_parts, str::from_utf8_unchecked};
pub mod amd64; pub mod amd64;
pub mod x86; pub mod x86;
@ -20,6 +21,9 @@ extern "C" {
fn libafl_qemu_remove_breakpoint(addr: u64) -> i32; fn libafl_qemu_remove_breakpoint(addr: u64) -> i32;
fn libafl_qemu_run() -> i32; fn libafl_qemu_run() -> i32;
fn strlen(s: *const u8) -> usize;
static exec_path: *const u8;
static guest_base: isize; static guest_base: isize;
} }
@ -95,6 +99,10 @@ impl QemuEmulator {
unsafe { transmute(addr - guest_base) } unsafe { transmute(addr - guest_base) }
} }
pub fn exec_path(&self) -> &str {
unsafe { from_utf8_unchecked(from_raw_parts(exec_path, strlen(exec_path) + 1)) }
}
pub fn new() -> Self { pub fn new() -> Self {
Self {} Self {}
} }

View File

@ -31,4 +31,5 @@ __attribute__((weak)) int libafl_qemu_run() {
return 0; return 0;
} }
__attribute__((weak)) char* exec_path = NULL;
__attribute__((weak)) size_t guest_base = 0; __attribute__((weak)) size_t guest_base = 0;