Skip to content

Instantly share code, notes, and snippets.

@stackcoder
Created February 2, 2024 16:37
Show Gist options
  • Save stackcoder/082743b28d98aa274b8675a0d0dad8e0 to your computer and use it in GitHub Desktop.
Save stackcoder/082743b28d98aa274b8675a0d0dad8e0 to your computer and use it in GitHub Desktop.
Build WinAFL in Docker Windows Container
FROM mcr.microsoft.com/windows/servercore:ltsc2022
SHELL ["powershell", "-NoProfile", "-Command", "$ErrorActionPreference='Stop'; $ProgressPreference='SilentlyContinue'; $VerbosePreference='Continue'; "]
RUN $hash = 'a6058d7c4c16bfa5bcd6fde051a92de8c68535fd7ebade55fc0ab1c41be3c8d5' \
; Invoke-WebRequest -OutFile 'git_setup.exe' 'https://github.com/git-for-windows/git/releases/download/v2.43.0.windows.1/Git-2.43.0-64-bit.exe' \
; if (Compare-Object $hash $(Get-FileHash 'git_setup.exe').Hash) { Write-Error 'CHECKSUM VERIFICATION FAILED!' -ErrorAction Stop } \
; Start-Process -Wait 'git_setup.exe' -ArgumentList '/verysilent' \
; Remove-Item -Force 'git_setup.exe'
# required for building with TinyInst
RUN $hash = '2437d83db04fb272af8de65eead1a2fc416b9fac3f6af9ce51a627e32b4fe8f8' \
; Invoke-WebRequest -OutFile 'python3_setup.exe' 'https://www.python.org/ftp/python/3.12.1/python-3.12.1-amd64.exe' \
; if (Compare-Object $hash $(Get-FileHash 'python3_setup.exe').Hash) { Write-Error 'CHECKSUM VERIFICATION FAILED!' -ErrorAction Stop } \
; Start-Process -Wait 'python3_setup.exe' -ArgumentList '/quiet', 'InstallAllUsers=1', 'PrependPath=1' \
; Remove-Item -Force 'python3_setup.exe'
# Visual Studio 2022 LTSC 17.8.6
RUN $hash = 'a2e920fe6fc18aba57bb4b1a70865be01888aa21dd8c7f6a9ec7b4aa25c8cfaa' \
; Invoke-WebRequest -OutFile 'vs_buildtools.exe' 'https://download.visualstudio.microsoft.com/download/pr/5bebe58c-9308-4a5b-9696-b6f84e90a32e/a2e920fe6fc18aba57bb4b1a70865be01888aa21dd8c7f6a9ec7b4aa25c8cfaa/vs_BuildTools.exe' \
; if (Compare-Object $hash $(Get-FileHash 'vs_buildtools.exe').Hash) { Write-Error 'CHECKSUM VERIFICATION FAILED!' -ErrorAction Stop } \
; Start-Process -Wait 'vs_buildtools.exe' -ArgumentList '--quiet', '--wait', '--norestart', '--nocache', \
'--add', 'Microsoft.VisualStudio.Workload.VCTools', \
'--add', 'Microsoft.VisualStudio.Component.VC.CMake.Project', \
'--add', 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64', \
'--includeRecommended' \
; Remove-Item -Force 'vs_buildtools.exe'
WORKDIR /app
RUN $hash='c678aca3810346fe691e2cc0f3d56cfe7504572e8ce85cf5839314c94ac34289' \
; Invoke-WebRequest -OutFile 'dynamorio.zip' 'https://github.com/DynamoRIO/dynamorio/releases/download/cronbuild-10.0.19741/DynamoRIO-Windows-10.0.19741.zip' \
; if (Compare-Object $hash $(Get-FileHash 'dynamorio.zip').Hash) { Write-Error 'CHECKSUM VERIFICATION FAILED!' -ErrorAction Stop } \
; Expand-Archive -Path 'dynamorio.zip' -DestinationPath 'dynamorio_zip' \
; Remove-Item -Force 'dynamorio.zip' \
; Rename-Item -Path $(Get-ChildItem -Path 'dynamorio_zip').FullName -NewName 'DynamoRIO' \
; Move-Item 'dynamorio_zip/DynamoRIO' '.' \
; Remove-Item -Recurse -Force 'dynamorio_zip'
RUN $commit = '25d5840799b628c8ef7750cd07ef2e30b299b156' \
; git clone --depth=1 --recurse-submodules --shallow-submodules -c "remote.origin.fetch=+${commit}:refs/remotes/origin/${commit}" 'https://github.com/googleprojectzero/winafl.git' WinAFL
# optional: build litecov.exe
# https://github.com/googleprojectzero/TinyInst/blob/master/.github/workflows/build.yaml
RUN & "\"${ENV:ProgramFiles(x86)}\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\Tools\\Launch-VsDevShell.ps1\"" -SkipAutomaticLocation \
; Set-Location $(New-Item -Path 'WinAFL\\third_party\\TinyInst' -Name 'build32' -Type Directory) \
; cmake -G"\"Visual Studio 17 2022\"" -A Win32 .. \
; cmake --build . --config Release
# https://github.com/googleprojectzero/winafl/blob/master/.github/workflows/build.yml
RUN & "\"${ENV:ProgramFiles(x86)}\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\Tools\\Launch-VsDevShell.ps1\"" -SkipAutomaticLocation \
; Set-Location $(New-Item -Path 'WinAFL' -Name 'build32' -Type Directory) \
; cmake -G"\"Visual Studio 17 2022\"" -A Win32 .. -DDynamoRIO_DIR="\"$(Resolve-Path ..\\..\\DynamoRIO\\cmake)\"" -DINTELPT=1 -DTINYINST=1 -DUSE_DRSYMS=1 \
; cmake --build . --config Release
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment