Skip to content

Commit ed12d56

Browse files
tokatokaCopilot
andauthored
libafl_nyx: Build qemu/packer in target directory (#3534)
* build libafl_nyx in target * Update crates/libafl_nyx/build_nyx_support.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update crates/libafl_nyx/build_nyx_support.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update crates/libafl_nyx/build.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix fuzzer * fix * tmate debug * fix packer path * fmt * why didn't ci run???? * tmate again.. * AI is dumbgit add crates/libafl_nyx/! * disable tmate --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent fb5c7e9 commit ed12d56

File tree

5 files changed

+32
-13
lines changed

5 files changed

+32
-13
lines changed

crates/libafl_nyx/build.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
use std::process::Command;
2-
1+
use std::{env, path::PathBuf, process::Command};
32
fn main() {
43
if cfg!(target_os = "linux") && cfg!(target_arch = "x86_64") && !cfg!(doc) {
4+
// Use CARGO_TARGET_DIR if available, otherwise fall back to OUT_DIR's parent directories
5+
let target_dir = if let Ok(target_dir) = env::var("CARGO_TARGET_DIR") {
6+
PathBuf::from(target_dir)
7+
} else {
8+
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
9+
out_dir
10+
.ancestors()
11+
.nth(3)
12+
.map(std::path::Path::to_path_buf)
13+
.expect("Failed to determine target directory from OUT_DIR")
14+
};
515
println!("cargo:rerun-if-changed=build.rs");
6-
// let output = Command::new("./build_nyx_support.sh").output().expect("can't run ./build_nyx_support.sh");
716
let status = Command::new("./build_nyx_support.sh")
17+
.arg(target_dir)
818
.status()
919
.expect("can't run ./build_nyx_support.sh");
1020
if status.success() {

crates/libafl_nyx/build_nyx_support.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
#!/bin/bash
22

3+
if [ -z "$1" ]; then
4+
echo "Usage: $0 <target-directory>"
5+
exit 1
6+
fi
7+
38
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
49

10+
TARGET_DIR="$1"
11+
mkdir -p "$TARGET_DIR"
12+
cd "$TARGET_DIR" || exit 1
13+
514
echo "================================================="
615
echo " Nyx build script"
716
echo "================================================="
@@ -44,8 +53,8 @@ echo "[*] Checking QEMU-Nyx ..."
4453
if [ ! -f "QEMU-Nyx/x86_64-softmmu/qemu-system-x86_64" ]; then
4554
cd QEMU-Nyx/ || return
4655
# We need to copy our custom `Makefile.libxdc` after `git submodule update`, otherwise we get a git error.
47-
sed -i "s,git submodule update libxdc$,git submodule update libxdc \&\& cp ../Makefile.libxdc ./libxdc/Makefile || exit 1," compile_qemu_nyx.sh
48-
./compile_qemu_nyx.sh lto || exit 1
56+
sed -i "s,git submodule update libxdc$,git submodule update libxdc \&\& cp $SCRIPT_DIR/Makefile.libxdc ./libxdc/Makefile || exit 1," compile_qemu_nyx.sh
57+
./compile_qemu_nyx.sh lto
4958
cd ..
5059
fi
5160

crates/ll_mp/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,10 @@ fn msg_offset_from_env(env_name: &str) -> Result<Option<u64>, Error> {
511511
/// Will set `SO_REUSEPORT` on unix.
512512
#[cfg(feature = "std")]
513513
fn tcp_bind(port: u16) -> Result<TcpListener, Error> {
514-
let listener = TcpListener::bind((_LLMP_BIND_ADDR, port))
515-
.map_err(|err| { let err_msg = format!("Failed to bind to port {port}: {err}");
516-
Error::os_error(err, err_msg)
517-
})?;
514+
let listener = TcpListener::bind((_LLMP_BIND_ADDR, port)).map_err(|err| {
515+
let err_msg = format!("Failed to bind to port {port}: {err}");
516+
Error::os_error(err, err_msg)
517+
})?;
518518

519519
#[cfg(unix)]
520520
#[cfg(not(any(target_os = "solaris", target_os = "illumos")))]

fuzzers/full_system/nyx_libxml2_parallel/setup_libxml2.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ cd ./libxml2/ || exit
2626
./autogen.sh --enable-shared=no || exit
2727
make -j || exit
2828
cd - || exit
29-
python3 "../../../crates/libafl_nyx/packer/packer/nyx_packer.py" \
29+
python3 "./target/debug/packer/packer/nyx_packer.py" \
3030
./libxml2/xmllint \
3131
/tmp/nyx_libxml2 \
3232
afl \
@@ -36,4 +36,4 @@ python3 "../../../crates/libafl_nyx/packer/packer/nyx_packer.py" \
3636
--fast_reload_mode \
3737
--purge || exit
3838

39-
python3 ../../../crates/libafl_nyx/packer/packer/nyx_config_gen.py /tmp/nyx_libxml2/ Kernel || exit
39+
python3 ./target/debug/packer/packer/nyx_config_gen.py /tmp/nyx_libxml2/ Kernel || exit

fuzzers/full_system/nyx_libxml2_standalone/setup_libxml2.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ cd ./libxml2/ || exit
2626
./autogen.sh --enable-shared=no || exit
2727
make -j || exit
2828
cd - || exit
29-
python3 "../../../crates/libafl_nyx/packer/packer/nyx_packer.py" \
29+
python3 "./target/debug/packer/packer/nyx_packer.py" \
3030
./libxml2/xmllint \
3131
/tmp/nyx_libxml2 \
3232
afl \
@@ -36,4 +36,4 @@ python3 "../../../crates/libafl_nyx/packer/packer/nyx_packer.py" \
3636
--fast_reload_mode \
3737
--purge || exit
3838

39-
python3 ../../../crates/libafl_nyx/packer/packer/nyx_config_gen.py /tmp/nyx_libxml2/ Kernel || exit
39+
python3 ./target/debug/packer/packer/nyx_config_gen.py /tmp/nyx_libxml2/ Kernel || exit

0 commit comments

Comments
 (0)