Pylibafl
This commit is contained in:
parent
171c85fc4f
commit
21f88b58b5
@ -28,4 +28,5 @@ default-members = [
|
||||
]
|
||||
exclude = [
|
||||
"fuzzers",
|
||||
"bindings",
|
||||
]
|
||||
|
16
bindings/pylibafl/Cargo.toml
Normal file
16
bindings/pylibafl/Cargo.toml
Normal file
@ -0,0 +1,16 @@
|
||||
[package]
|
||||
name = "pylibafl"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
pyo3 = { version = "0.14.3", features = ["extension-module"] }
|
||||
libafl_qemu = { path = "../../libafl_qemu", version = "0.6", features = ["python"] }
|
||||
libafl_sugar = { path = "../../libafl_sugar", version = "0.6", features = ["python"] }
|
||||
|
||||
[build-dependencies]
|
||||
pyo3-build-config = { version = "0.14.5" }
|
||||
|
||||
[lib]
|
||||
name = "pylibafl"
|
||||
crate-type = ["cdylib"]
|
17
bindings/pylibafl/src/lib.rs
Normal file
17
bindings/pylibafl/src/lib.rs
Normal file
@ -0,0 +1,17 @@
|
||||
use libafl_sugar;
|
||||
use libafl_qemu;
|
||||
use pyo3::prelude::*;
|
||||
|
||||
#[pymodule]
|
||||
#[pyo3(name = "pylibafl")]
|
||||
pub fn python_module(py: Python, m: &PyModule) -> PyResult<()> {
|
||||
let sugar_module = PyModule::new(py, "sugar")?;
|
||||
libafl_sugar::python_module(py, sugar_module)?;
|
||||
m.add_submodule(sugar_module)?;
|
||||
|
||||
let qemu_module = PyModule::new(py, "qemu")?;
|
||||
libafl_qemu::python_module(py, qemu_module)?;
|
||||
m.add_submodule(qemu_module)?;
|
||||
|
||||
Ok(())
|
||||
}
|
@ -11,7 +11,7 @@ keywords = ["fuzzing", "qemu", "instrumentation"]
|
||||
edition = "2018"
|
||||
|
||||
[features]
|
||||
python = ["pyo3"]
|
||||
python = ["pyo3", "pyo3-build-config"]
|
||||
default = []
|
||||
|
||||
[dependencies]
|
||||
@ -23,11 +23,13 @@ num = "0.4"
|
||||
num_enum = "0.5.1"
|
||||
goblin = "0.4.2"
|
||||
libc = "0.2.97"
|
||||
pyo3 = { version = "0.14.3", features = ["extension-module"], optional = true }
|
||||
#pyo3 = { version = "0.14.3", features = ["extension-module"], optional = true }
|
||||
pyo3 = { version = "0.14.3", optional = true }
|
||||
|
||||
[build-dependencies]
|
||||
cc = { version = "1.0" }
|
||||
which = "4.1"
|
||||
pyo3-build-config = { version = "0.14.5", optional = true }
|
||||
|
||||
[lib]
|
||||
name = "libafl_qemu"
|
||||
|
@ -1,5 +1,8 @@
|
||||
use std::{env, fs::copy, path::Path, process::Command};
|
||||
//use std::fs::read_dir;
|
||||
#[cfg(not(feature = "python"))]
|
||||
use std::fs::copy;
|
||||
#[cfg(feature = "python")]
|
||||
use std::fs::read_dir;
|
||||
use std::{env, path::Path, process::Command};
|
||||
use which::which;
|
||||
|
||||
const QEMU_URL: &str = "https://github.com/AFLplusplus/qemu-libafl-bridge";
|
||||
@ -150,19 +153,91 @@ fn main() {
|
||||
//let _ = remove_file(build_dir.join(&format!("libqemu-{}.so", cpu_target)));
|
||||
}
|
||||
|
||||
copy(
|
||||
build_dir.join(&format!("libqemu-{}.so", cpu_target)),
|
||||
target_dir.join(&format!("libqemu-{}.so", cpu_target)),
|
||||
)
|
||||
.expect("Failed to copy the QEMU shared object");
|
||||
#[cfg(feature = "python")]
|
||||
{
|
||||
let mut objects = vec![];
|
||||
for dir in &[
|
||||
build_dir.join("libcommon.fa.p"),
|
||||
build_dir.join(&format!("libqemu-{}-linux-user.fa.p", cpu_target)),
|
||||
//build_dir.join("libqemuutil.a.p"),
|
||||
//build_dir.join("libqom.fa.p"),
|
||||
//build_dir.join("libhwcore.fa.p"),
|
||||
//build_dir.join("libcapstone.a.p"),
|
||||
] {
|
||||
for path in read_dir(dir).unwrap() {
|
||||
let path = path.unwrap().path();
|
||||
if path.is_file() {
|
||||
if let Some(name) = path.file_name() {
|
||||
if name.to_string_lossy().starts_with("stubs") {
|
||||
continue;
|
||||
} else if let Some(ext) = path.extension() {
|
||||
if ext == "o" {
|
||||
objects.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
println!(
|
||||
"cargo:rustc-link-search=native={}",
|
||||
&target_dir.to_string_lossy().to_string()
|
||||
);
|
||||
println!("cargo:rustc-link-lib=qemu-{}", cpu_target);
|
||||
for obj in &objects {
|
||||
println!("cargo:rustc-cdylib-link-arg={}", obj.display());
|
||||
}
|
||||
|
||||
println!("cargo:rustc-env=LD_LIBRARY_PATH={}", target_dir.display());
|
||||
println!("cargo:rustc-cdylib-link-arg=-Wl,--start-group");
|
||||
|
||||
println!("cargo:rustc-cdylib-link-arg=-Wl,--whole-archive");
|
||||
println!(
|
||||
"cargo:rustc-cdylib-link-arg={}/libhwcore.fa",
|
||||
build_dir.display()
|
||||
);
|
||||
println!(
|
||||
"cargo:rustc-cdylib-link-arg={}/libqom.fa",
|
||||
build_dir.display()
|
||||
);
|
||||
println!("cargo:rustc-cdylib-link-arg=-Wl,--no-whole-archive");
|
||||
println!(
|
||||
"cargo:rustc-cdylib-link-arg={}/libcapstone.a",
|
||||
build_dir.display()
|
||||
);
|
||||
println!(
|
||||
"cargo:rustc-cdylib-link-arg={}/libqemuutil.a",
|
||||
build_dir.display()
|
||||
);
|
||||
println!(
|
||||
"cargo:rustc-cdylib-link-arg={}/libhwcore.fa",
|
||||
build_dir.display()
|
||||
);
|
||||
println!(
|
||||
"cargo:rustc-cdylib-link-arg={}/libqom.fa",
|
||||
build_dir.display()
|
||||
);
|
||||
|
||||
println!("cargo:rustc-cdylib-link-arg=-lrt");
|
||||
println!("cargo:rustc-cdylib-link-arg=-lutil");
|
||||
println!("cargo:rustc-cdylib-link-arg=-lgthread-2.0");
|
||||
println!("cargo:rustc-cdylib-link-arg=-lglib-2.0");
|
||||
println!("cargo:rustc-cdylib-link-arg=-lstdc++");
|
||||
|
||||
println!("cargo:rustc-cdylib-link-arg=-Wl,--end-group");
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "python"))]
|
||||
{
|
||||
copy(
|
||||
build_dir.join(&format!("libqemu-{}.so", cpu_target)),
|
||||
target_dir.join(&format!("libqemu-{}.so", cpu_target)),
|
||||
)
|
||||
.expect("Failed to copy the QEMU shared object");
|
||||
|
||||
println!(
|
||||
"cargo:rustc-link-search=native={}",
|
||||
&target_dir.to_string_lossy().to_string()
|
||||
);
|
||||
println!("cargo:rustc-link-lib=qemu-{}", cpu_target);
|
||||
|
||||
println!("cargo:rustc-env=LD_LIBRARY_PATH={}", target_dir.display());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -33,14 +33,14 @@ pub fn filter_qemu_args() -> Vec<String> {
|
||||
args
|
||||
}
|
||||
|
||||
#[cfg(all(target_od = "linux", feature = "python"))]
|
||||
#[cfg(all(target_os = "linux", feature = "python"))]
|
||||
use pyo3::prelude::*;
|
||||
|
||||
#[cfg(all(target_od = "linux", feature = "python"))]
|
||||
#[cfg(all(target_os = "linux", feature = "python"))]
|
||||
#[pymodule]
|
||||
#[pyo3(name = "libafl_qemu")]
|
||||
#[allow(clippy::items_after_statements)]
|
||||
fn python_module(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||
pub fn python_module(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||
use core::mem::transmute;
|
||||
use pyo3::exceptions::PyValueError;
|
||||
|
||||
|
@ -16,15 +16,15 @@ python = ["pyo3", "libafl_qemu/python", "pyo3-build-config"]
|
||||
default = []
|
||||
|
||||
[build-dependencies]
|
||||
pyo3-build-config = { version = "0.14.2", optional = true }
|
||||
pyo3-build-config = { version = "0.14.5", optional = true }
|
||||
|
||||
[dependencies]
|
||||
libafl = { path = "../libafl", version = "0.6.1" }
|
||||
libafl_targets = { path = "../libafl_targets", version = "0.6.1" }
|
||||
libafl_qemu = { path = "../libafl_qemu", version = "0.6.1" }
|
||||
typed-builder = "0.9.0" # Implement the builder pattern at compiletime
|
||||
pyo3 = { version = "0.14.5", features = ["extension-module"], optional = true }
|
||||
|
||||
#pyo3 = { version = "0.14.3", features = ["extension-module"], optional = true }
|
||||
pyo3 = { version = "0.14.3", optional = true }
|
||||
|
||||
[lib]
|
||||
name = "libafl_sugar"
|
||||
|
@ -17,7 +17,7 @@ use pyo3::prelude::*;
|
||||
#[cfg(feature = "python")]
|
||||
#[pymodule]
|
||||
#[pyo3(name = "libafl_sugar")]
|
||||
fn python_module(py: Python, m: &PyModule) -> PyResult<()> {
|
||||
pub fn python_module(py: Python, m: &PyModule) -> PyResult<()> {
|
||||
inmemory::pybind::register(py, m)?;
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user