fix Rust linking

This commit is contained in:
Andrea Fioraldi 2021-07-06 12:12:43 +02:00
parent cb9a2a2b68
commit ecf311310d
6 changed files with 79 additions and 1 deletions

View File

@ -581,6 +581,16 @@ static int parse_args(int argc, char **argv)
r++; r++;
} }
if (!strncmp(r, "libafl", 6)) {
if (optind >= argc) {
(void) fprintf(stderr,
"qemu: missing argument for option '%s'\n", r);
exit(EXIT_FAILURE);
}
optind++;
continue;
}
for (arginfo = arg_table; arginfo->handle_opt != NULL; arginfo++) { for (arginfo = arg_table; arginfo->handle_opt != NULL; arginfo++) {
if (!strcmp(r, arginfo->argv)) { if (!strcmp(r, arginfo->argv)) {
if (arginfo->has_arg) { if (arginfo->has_arg) {

14
qemu_libafl_bridge/.gitignore vendored Normal file
View File

@ -0,0 +1,14 @@
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

View File

@ -1,6 +1,6 @@
[package] [package]
name = "qemu_libafl_bridge" name = "qemu_libafl_bridge"
version = "0.1.0" version = "0.2.0"
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/"
@ -13,3 +13,6 @@ edition = "2018"
[dependencies] [dependencies]
num = "0.4" num = "0.4"
num_enum = "0.5.1" num_enum = "0.5.1"
[build-dependencies]
cc = { version = "1.0" }

View File

@ -0,0 +1,17 @@
use std::{env, path::Path};
fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let out_dir = out_dir.to_string_lossy().to_string();
let src_dir = Path::new("src");
println!("cargo:rerun-if-changed=src/weaks.c");
cc::Build::new()
.file(src_dir.join("weaks.c"))
.compile("weaks");
println!("cargo:rustc-link-search=native={}", &out_dir);
println!("cargo:rerun-if-changed=build.rs");
}

View File

@ -89,4 +89,8 @@ impl QemuEmulator {
pub fn h2g(&self, addr: isize) -> *mut u8 { pub fn h2g(&self, addr: isize) -> *mut u8 {
unsafe { transmute(addr - guest_base) } unsafe { transmute(addr - guest_base) }
} }
pub fn new() -> Self {
Self {}
}
} }

View File

@ -0,0 +1,30 @@
#include <stdlib.h>
#include <stdint.h>
__attribute__((weak)) int libafl_qemu_write_reg(int reg, uint8_t* val) {
(void)reg;
(void)val;
return 0;
}
__attribute__((weak)) int libafl_qemu_read_reg(int reg, uint8_t* val) {
(void)reg;
(void)val;
return 0;
}
__attribute__((weak)) int libafl_qemu_num_regs(void) {
return 0;
}
__attribute__((weak)) int libafl_qemu_set_breakpoint(uint64_t addr) {
(void)addr;
return 0;
}
__attribute__((weak)) int libafl_qemu_remove_breakpoint(uint64_t addr) {
(void)addr;
return 0;
}
__attribute__((weak)) size_t guest_base = 0;