|
| 1 | +param ( |
| 2 | + [Parameter(Mandatory = $true)] |
| 3 | + [string]$libFuzzer, |
| 4 | + [Parameter(Mandatory = $true)] |
| 5 | + [string]$project, |
| 6 | + [Parameter(Mandatory = $true)] |
| 7 | + [string]$corpus, |
| 8 | + [string]$dict = $null, |
| 9 | + [int]$timeout = 10, |
| 10 | + [int]$fork = 0, |
| 11 | + [int]$ignore_crashes = 0, |
| 12 | + [string]$command = "sharpfuzz" |
| 13 | +) |
| 14 | + |
| 15 | +Set-StrictMode -Version Latest |
| 16 | + |
| 17 | +$outputDir = "bin" |
| 18 | + |
| 19 | +if (Test-Path $outputDir) { |
| 20 | + Remove-Item -Recurse -Force $outputDir |
| 21 | +} |
| 22 | + |
| 23 | +dotnet publish $project -c release -o $outputDir |
| 24 | + |
| 25 | +$projectName = (Get-Item $project).BaseName |
| 26 | +$projectDll = "$projectName.dll" |
| 27 | +$project = Join-Path $outputDir $projectDll |
| 28 | + |
| 29 | +$exclusions = @( |
| 30 | + "dnlib.dll", |
| 31 | + "SharpFuzz.dll", |
| 32 | + "SharpFuzz.Common.dll" |
| 33 | +) |
| 34 | + |
| 35 | +Write-Output "Exclusions: $($exclusions -join ', ')" |
| 36 | + |
| 37 | +$allDlls = Get-ChildItem $outputDir -Filter *.dll |
| 38 | +Write-Output "All DLLs: $($allDlls.Name -join ', ')" |
| 39 | + |
| 40 | +$fuzzingTargets = $allDlls ` |
| 41 | +| Where-Object { $_.Name -notin $exclusions } ` |
| 42 | +| Where-Object { $_.Name -notlike "System.*.dll" } |
| 43 | + |
| 44 | +Write-Output "Fuzzing Targets: $($fuzzingTargets.Name -join ', ')" |
| 45 | + |
| 46 | +if (($fuzzingTargets | Measure-Object).Count -eq 0) { |
| 47 | + Write-Error "No fuzzing targets found" |
| 48 | + exit 1 |
| 49 | +} |
| 50 | + |
| 51 | +foreach ($fuzzingTarget in $fuzzingTargets) { |
| 52 | + Write-Output "Instrumenting $fuzzingTarget" |
| 53 | + & $command $fuzzingTarget.FullName |
| 54 | + |
| 55 | + if ($LastExitCode -ne 0) { |
| 56 | + Write-Error "An error occurred while instrumenting $fuzzingTarget" |
| 57 | + exit 1 |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +# Construct the final command string |
| 62 | +$finalCommand = "$libFuzzer --target_path=dotnet --target_arg=$project" |
| 63 | + |
| 64 | +if ($dict) { |
| 65 | + $finalCommand += " -dict=$dict" |
| 66 | +} |
| 67 | + |
| 68 | +# Print the final command |
| 69 | +Write-Output "Final Command: $finalCommand" |
| 70 | + |
| 71 | +# Execute the final command |
| 72 | +Invoke-Expression $finalCommand |
0 commit comments