-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild.ps1
More file actions
96 lines (81 loc) · 4.15 KB
/
Copy pathbuild.ps1
File metadata and controls
96 lines (81 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
New-Item -ItemType Directory -Path plugins\osquery -Force
New-Item -ItemType Directory -Path plugins\dosai -Force
New-Item -ItemType Directory -Path plugins\trivy -Force
New-Item -ItemType Directory -Path plugins\trustinspector -Force
New-Item -ItemType Directory -Path plugins\golem -Force
$upxVersion = "5.2.0"
$upxArchive = "upx-$upxVersion-win64.zip"
$upxArchiveSha256 = "b471ebf1b7f20f4a89150264ed9a008a2a5bfd247f3c6d1184a75bb59ca08f5d"
$osqueryVersion = "5.23.1"
$osqueryArchive = "osquery-$osqueryVersion.windows_x86_64.zip"
$osqueryArchiveSha256 = "7bd411050ef6b5aae1b23956aec0dc5ce6e800c5656f0cd463ac70a6e1bdf30b"
$dosaiVersion = "4.0.0"
$dosaiArchive = "Dosai.exe"
$dosaiArchiveSha256 = "8d4ed9585068cf2df6975e75fa981c39ea35a597e6b79572137dfa0dab28d31d"
function Assert-Sha256 {
param(
[Parameter(Mandatory = $true)][string]$Path,
[Parameter(Mandatory = $true)][string]$ExpectedHash
)
$actualHash = (Get-FileHash -Path $Path -Algorithm SHA256).Hash.ToLowerInvariant()
if ($actualHash -ne $ExpectedHash.ToLowerInvariant()) {
Remove-Item $Path -Force -ErrorAction SilentlyContinue
throw "SHA-256 mismatch for $Path. Expected $ExpectedHash but got $actualHash"
}
}
Invoke-WebRequest -Uri "https://github.com/upx/upx/releases/download/v$upxVersion/$upxArchive" -UseBasicParsing -OutFile $upxArchive
Assert-Sha256 -Path $upxArchive -ExpectedHash $upxArchiveSha256
Expand-Archive -Path $upxArchive -DestinationPath . -Force
Invoke-WebRequest -Uri "https://github.com/osquery/osquery/releases/download/$osqueryVersion/$osqueryArchive" -UseBasicParsing -OutFile $osqueryArchive
Assert-Sha256 -Path $osqueryArchive -ExpectedHash $osqueryArchiveSha256
Expand-Archive -Path $osqueryArchive -DestinationPath . -Force
copy "osquery-$osqueryVersion.windows_x86_64\Program Files\osquery\osqueryi.exe" plugins\osquery\osqueryi-windows-amd64.exe
& ".\upx-$upxVersion-win64\upx.exe" -9 --lzma plugins\osquery\osqueryi-windows-amd64.exe
plugins\osquery\osqueryi-windows-amd64.exe --help
Invoke-WebRequest -Uri "https://github.com/owasp-dep-scan/dosai/releases/download/v$dosaiVersion/$dosaiArchive" -UseBasicParsing -OutFile plugins/dosai/dosai-windows-amd64.exe
Assert-Sha256 -Path plugins/dosai/dosai-windows-amd64.exe -ExpectedHash $dosaiArchiveSha256
cd thirdparty\trivy
# Mirror the Makefile's GOPIN: trivy v0.74.0 targets encoding/json/v2 as Go
# 1.26 exposed it under GOEXPERIMENT=jsonv2. Go 1.27 stabilised the package
# with a changed API (json.SkipFunc is gone), so pin the toolchain here too.
$env:GOTOOLCHAIN = "go1.26.5"
$env:GOEXPERIMENT = "jsonv2"
$env:CGO_ENABLED = "0"
go build -ldflags "-s -w" -o build\trivy-windows-amd64.exe
& "..\..\upx-$upxVersion-win64\upx.exe" -9 --lzma build\trivy-windows-amd64.exe
copy build\* ..\..\plugins\trivy\
Remove-Item build -Recurse -Force
cd ..\..
# golem and trustinspector require Go 1.27; drop the trivy-only pins.
Remove-Item Env:GOTOOLCHAIN -ErrorAction SilentlyContinue
Remove-Item Env:GOEXPERIMENT -ErrorAction SilentlyContinue
cd thirdparty\golem
$env:CGO_ENABLED = "0"
go test ./...
go build -trimpath -ldflags "-s -w" -o build\golem-windows-amd64.exe .\cmd\golem
& "..\..\upx-$upxVersion-win64\upx.exe" -9 --lzma build\golem-windows-amd64.exe
copy build\* ..\..\plugins\golem\
Remove-Item build -Recurse -Force
cd ..\..
cd thirdparty\trustinspector
$env:CGO_ENABLED = "0"
go build -ldflags "-s -w" -o build\trustinspector-cdxgen-windows-amd64.exe
& "..\..\upx-$upxVersion-win64\upx.exe" -9 --lzma build\trustinspector-cdxgen-windows-amd64.exe
copy build\* ..\..\plugins\trustinspector\
Remove-Item build -Recurse -Force
cd ..\..
New-Item -ItemType Directory -Path plugins\rusi -Force
cd thirdparty\rusi
cargo build -p rusi-cli --release --locked
copy target\release\rusi.exe ..\..\plugins\rusi\rusi-windows-amd64.exe
cd ..\..
New-Item -ItemType Directory -Path plugins\cdxui -Force
cd thirdparty\cdxui
cargo build --release --locked
copy target\release\cdxui.exe ..\..\plugins\cdxui\cdxui-windows-amd64.exe
cd ..\..
node .\scripts\generate-metadata.js .\plugins
Remove-Item "osquery-$osqueryVersion.windows_x86_64" -Recurse -Force
Remove-Item $osqueryArchive -Recurse -Force
Remove-Item "upx-$upxVersion-win64" -Recurse -Force
Remove-Item $upxArchive -Recurse -Force