MegaBites-AI/Windows-powershell
0372
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3 4<#51. libfuzzer-dotnet-windows.exe can be installed from https://github.com/Metalnem/libfuzzer-dotnet/releases6 72. sharpfuzz can be installed with dotnet-tool:8 > dotnet tool install --global SharpFuzz.CommandLine --version 2.2.09 10Usage: sharpfuzz [path-to-assembly] [prefix ...]11 12path-to-assembly:13 The path to an assembly .dll file to instrument.14 15prefix:16 The class or the namespace to instrument.17 If not present, all types in the assembly will be instrumented.18 At least one prefix is required when instrumenting System.Private.CoreLib.19 20Examples:21 sharpfuzz Newtonsoft.Json.dll22 sharpfuzz System.Private.CoreLib.dll System.Number23 sharpfuzz System.Private.CoreLib.dll System.DateTimeFormat System.DateTimeParse24#>25 26param (27 [string]$libFuzzer = "$PSScriptRoot\libfuzzer-dotnet-windows.exe",28 [string]$project = "$PSScriptRoot\FuzzingApp\powershell-fuzz-tests.csproj",29 [string]$corpus = "$PSScriptRoot\inputs",30 [string]$command = "sharpfuzz.exe"31)32 33Set-StrictMode -Version Latest34 35$outputDir = "$PSScriptRoot\out"36 37if (Test-Path $outputDir) {38 Remove-Item -Recurse -Force $outputDir39}40 41Write-Host "dotnet publish $project -c Debug -o $outputDir"42dotnet publish $project -c Debug -o $outputDir43Write-Host "build completed"44 45$projectName = (Get-Item $project).BaseName46$projectDll = "$projectName.dll"47$project = Join-Path $outputDir $projectDll48$smaDllPath = Join-Path $outputDir "System.Management.Automation.dll"49 50## Instrument the specific class within the test assembly.51Write-Host "instrumenting: $project"52## !NOTE! If you instrument the class that defines "Main", it will fail.53& $command $project "FuzzTests.Target"54Write-Host "done instrumenting $project"55 56## Instrument any other assemblies that need to be tested.57Write-Host "instrumenting: $smaDllPath"58& $command $smaDllPath "System.Management.Automation.Remoting.RemoteSessionHyperVSocketClient"59Write-Host "done instrumenting: $smaDllPath"60 61$outputPath = Join-Path $outputDir "output.txt"62 63Write-Host "launching fuzzer on $project"64Write-Host "$libFuzzer --target_path=dotnet --target_arg=$project $corpus"65& $libFuzzer --target_path=dotnet --target_arg=$project $corpus -max_len=1024 2>&1 | Tee-Object -FilePath $outputPath66 