-
-
Notifications
You must be signed in to change notification settings - Fork 372
Windows Support for LibAFL-LibFuzzer #3130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
bacd235
6a10ca6
839e422
7a923b1
d8e2472
34a41f8
68b6478
17399fe
c45a9dc
cb2afd1
ff613eb
8c6210d
f4c1291
6558263
a17baa4
bc2f70b
599dea0
5dc689e
5dd2bfd
a7d70d2
6d47b67
0b7c082
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,16 +4,19 @@ version = "0.15.2" | |
edition = "2024" | ||
publish = false | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[features] | ||
default = ["fork"] | ||
default = [] | ||
## Enables forking mode for the LibAFL launcher (instead of starting new processes) | ||
fork = ["libafl/fork"] | ||
track_hit_feedbacks = [ | ||
"libafl/track_hit_feedbacks", | ||
"libafl_targets/track_hit_feedbacks", | ||
] | ||
tui_monitor = ["libafl/tui_monitor"] | ||
|
||
[target.'cfg(not(windows))'.features] | ||
## Enable the `fork` feature on non-windows platforms | ||
default = ["fork", "tui_monitor"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't think we need tui_monitor on non-win There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have to put in a few libs anyway to get this to work so I'll just revert this part of the changes and make tui_monitor work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't fully get the tui monitor thing - it's just not working on Win yet? |
||
|
||
[profile.release] | ||
lto = true | ||
|
@@ -40,7 +43,6 @@ libafl = { path = "../libafl", default-features = false, features = [ | |
"regex", | ||
"errors_backtrace", | ||
"serdeany_autoreg", | ||
"tui_monitor", | ||
"unicode", | ||
] } | ||
libafl_bolts = { path = "../libafl_bolts", default-features = false, features = [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env pwsh | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe call that guy from a justfile? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, I'll add a justfile for libafl_libfuzzer and libafl_libfuzzer_runtime. |
||
|
||
$ErrorActionPreference = "Stop" | ||
|
||
$SCRIPT_DIR = Split-Path -Parent $MyInvocation.MyCommand.Path | ||
|
||
Set-Location $SCRIPT_DIR | ||
|
||
if ($args.Count -eq 0) { | ||
$profile = "release" | ||
} else { | ||
$profile = $args[0] | ||
} | ||
|
||
try { | ||
$nightly_version = Invoke-Expression "cargo +nightly --version" 2>$null | ||
if (-not $nightly_version) { | ||
Write-Host "You must install a recent Rust nightly to build the libafl_libfuzzer runtime!" -ForegroundColor Red | ||
exit 1 | ||
} | ||
} catch { | ||
Write-Host "You must install a recent Rust nightly to build the libafl_libfuzzer runtime!" -ForegroundColor Red | ||
exit 1 | ||
} | ||
|
||
Write-Host "Building libafl_libfuzzer runtime with profile '$profile'" -ForegroundColor Green | ||
Invoke-Expression "cargo +nightly build --profile $profile" | ||
|
||
# target-libdir is e.g. C:\Users\user\.rustup\toolchain\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib | ||
$RUSTC_BIN = Split-Path -Parent (Invoke-Expression "cargo +nightly rustc -Zunstable-options --print target-libdir") | ||
$RUSTC_BIN = Join-Path $RUSTC_BIN "bin" | ||
$RUST_LLD = Join-Path $RUSTC_BIN "rust-lld.exe" | ||
$RUST_AR = Join-Path $RUSTC_BIN "llvm-ar.exe" | ||
$RUST_NM = Join-Path $RUSTC_BIN "llvm-nm.exe" | ||
|
||
if (-not (Test-Path $RUST_LLD) -or -not (Test-Path $RUST_AR)) { | ||
Write-Host "You must install the llvm-tools component: 'rustup component add llvm-tools'" -ForegroundColor Red | ||
Write-Host "Could not find $RUST_LLD or $RUST_AR" -ForegroundColor Red | ||
exit 1 | ||
} | ||
|
||
$tmpdir = Join-Path $env:TEMP ([System.IO.Path]::GetRandomFileName()) | ||
New-Item -ItemType Directory -Path $tmpdir | Out-Null | ||
|
||
function Cleanup { | ||
if (Test-Path $tmpdir) { | ||
Remove-Item -Recurse -Force $tmpdir | ||
} | ||
} | ||
|
||
try { | ||
$targetPath = Join-Path $SCRIPT_DIR "target\$profile\afl_libfuzzer_runtime.lib" | ||
$outputPath = Join-Path $SCRIPT_DIR "libFuzzer.lib" | ||
|
||
Write-Host "Creating intermediate object file '$tmpdir\libFuzzer.obj from $targetPath'" -ForegroundColor Green | ||
& $RUST_LLD -flavor link /lib /nologo /out:"$tmpdir\libFuzzer.obj" "$targetPath" | ||
|
||
if ($LASTEXITCODE -ne 0) { | ||
throw "Failed to create intermediate object file" | ||
} | ||
|
||
Write-Host "Creating final library '$outputPath'" -ForegroundColor Green | ||
& $RUST_AR crs "$outputPath" "$tmpdir\libFuzzer.obj" | ||
|
||
if ($LASTEXITCODE -ne 0) { | ||
throw "Failed to create final library" | ||
} | ||
|
||
Write-Host "Verifying symbols from '$outputPath'" -ForegroundColor Green | ||
# Symbols that should be present: | ||
# LLVMFuzzerRunDriver | ||
& $RUST_NM "$outputPath" | Select-String "LLVMFuzzerRunDriver" | Out-Null | ||
|
||
if ($LASTEXITCODE -ne 0) { | ||
throw "Failed to verify symbols in final library" | ||
} | ||
|
||
Write-Host "Done! Wrote the runtime to '$outputPath'" -ForegroundColor Green | ||
|
||
} | ||
finally { | ||
Cleanup | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think fork as default is good for perf on non-windows, it's a nop on win
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have it set below that on non-windows to keep things explicit and because tui_monitor needs to be default on non-win anyway, but I can change it if wanted.