-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
133 lines (112 loc) · 5.68 KB
/
Copy pathbuild.ps1
File metadata and controls
133 lines (112 loc) · 5.68 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
$ErrorActionPreference = "Stop"
Write-Host "==================================================" -ForegroundColor Cyan
Write-Host " Building Burp Suite Screenshot PoC Extension " -ForegroundColor Green
Write-Host "==================================================" -ForegroundColor Cyan
# 1. Detect the newest installed JDK.
# The previous list named jdk-25.0.4.1, "latest" and jdk-17, none of which exist on a
# normal machine, so the build silently fell back to whatever javac was on PATH. Scan
# the install root and pick the highest version instead of guessing at names.
$javaHome = $env:JAVA_HOME
if ($javaHome -and -not (Test-Path "$javaHome\bin\javac.exe")) { $javaHome = $null }
if (-not $javaHome) {
$candidates = Get-ChildItem -Path "C:\Program Files\Java" -Directory -ErrorAction SilentlyContinue |
Where-Object { Test-Path "$($_.FullName)\bin\javac.exe" } |
Sort-Object {
$v = $_.Name -replace '^[^0-9]*', ''
try { [version]($v -replace '[^0-9.].*$', '') } catch { [version]'0.0' }
} -Descending
if ($candidates) { $javaHome = $candidates[0].FullName }
}
if ($javaHome) {
$javac = "$javaHome\bin\javac.exe"
$jar = "$javaHome\bin\jar.exe"
$java = "$javaHome\bin\java.exe"
} else {
Write-Host "[!] No JDK found under C:\Program Files\Java; falling back to PATH." -ForegroundColor Yellow
$javac = "javac"; $jar = "jar"; $java = "java"
}
Write-Host "[+] Using compiler: $javac"
& $javac -version
# 2. Fetch the Montoya API jar when it is not already there.
# It is deliberately not committed. The jar is covered by the Burp Suite Professional
# licence, which grants no right to redistribute it, so it is pulled from Maven Central
# on the first build instead. It is compile-only and never enters the extension JAR.
$montoya = "lib\montoya-api-2023.12.1.jar"
if (-not (Test-Path $montoya)) {
Write-Host "[+] $montoya is missing. Downloading from Maven Central..."
New-Item -ItemType Directory -Force -Path "lib" | Out-Null
$montoyaUrl = "https://repo1.maven.org/maven2/net/portswigger/burp/extensions/montoya-api/2023.12.1/montoya-api-2023.12.1.jar"
try {
Invoke-WebRequest -Uri $montoyaUrl -OutFile $montoya -UseBasicParsing
} catch {
if (Test-Path $montoya) { Remove-Item -Force $montoya }
Write-Host "[-] Download failed: $($_.Exception.Message)" -ForegroundColor Red
Write-Host " Fetch it by hand from $montoyaUrl" -ForegroundColor Yellow
Write-Host " and save it as $montoya." -ForegroundColor Yellow
exit 1
}
}
# 3. Prepare directories
$buildDir = "build"
$classesDir = "$buildDir\classes"
$libsDir = "$buildDir\libs"
if (Test-Path $classesDir) { Remove-Item -Recurse -Force $classesDir }
New-Item -ItemType Directory -Force -Path $classesDir | Out-Null
New-Item -ItemType Directory -Force -Path $libsDir | Out-Null
# 4. Extract bundled libraries (Gson) into the classes directory for a fat JAR
Write-Host "[+] Unpacking dependencies for Fat JAR..."
Push-Location $classesDir
& $jar -xf "..\..\lib\gson-2.10.1.jar"
if (Test-Path "META-INF\MANIFEST.MF") { Remove-Item -Force "META-INF\MANIFEST.MF" }
Pop-Location
# 5. Find all java source files
$sources = Get-ChildItem -Recurse -Filter "*.java" -Path "src\main\java" |
Select-Object -ExpandProperty FullName
$sourcesFile = "$buildDir\sources.txt"
$sources | Out-File -FilePath $sourcesFile -Encoding ascii
# 6. Compile with --release 17 for the widest Burp compatibility
Write-Host "[+] Compiling Java source files..."
$classpath = "lib\montoya-api-2023.12.1.jar;lib\gson-2.10.1.jar"
& $javac --release 17 -encoding UTF-8 -Xlint:-options -cp $classpath -d $classesDir "@$sourcesFile"
if ($LASTEXITCODE -ne 0) {
Write-Host "[-] Compilation failed!" -ForegroundColor Red
exit 1
}
# 7. Package the JAR
$outputJar = "$libsDir\burp-screenshot-poc.jar"
Write-Host "[+] Packaging into $outputJar..."
& $jar -cf $outputJar -C $classesDir .
if ($LASTEXITCODE -ne 0) {
Write-Host "[-] Failed to package JAR." -ForegroundColor Red
exit 1
}
# 8. Run the verification tests.
# -ea is not optional: every check in the suite is an assert, and the JVM skips them
# silently without it, so a green run would prove nothing.
Write-Host "[+] Running verification tests..."
$testOut = "$buildDir\test-classes"
if (Test-Path $testOut) { Remove-Item -Recurse -Force $testOut }
New-Item -ItemType Directory -Force -Path $testOut | Out-Null
& $javac --release 17 -encoding UTF-8 -Xlint:-options `
-cp "$outputJar;lib\montoya-api-2023.12.1.jar" `
-d $testOut src\test\java\burp\screenshot\ScreenshotVerificationTest.java
if ($LASTEXITCODE -ne 0) {
Write-Host "[-] Test compilation failed!" -ForegroundColor Red
exit 1
}
# Every argument is quoted: PowerShell 5.1 splits an unquoted -Dproperty=value at the dot
# and hands java "-Djava" plus a main class of ".awt.headless=true".
$testClasspath = "$testOut;$outputJar;lib\montoya-api-2023.12.1.jar"
& $java "-ea" "-Djava.awt.headless=true" "-cp" $testClasspath `
"burp.screenshot.ScreenshotVerificationTest"
if ($LASTEXITCODE -ne 0) {
Write-Host "[-] Verification tests failed!" -ForegroundColor Red
exit 1
}
$size = (Get-Item $outputJar).Length / 1KB
Write-Host "==================================================" -ForegroundColor Green
Write-Host " [SUCCESS] Built and verified" -ForegroundColor Green
Write-Host " Output: $outputJar ($([Math]::Round($size, 1)) KB)" -ForegroundColor Cyan
Write-Host " Captures: build\test_styled_dark.png, build\test_styled_light.png" -ForegroundColor Cyan
Write-Host " Wrap captures: build\test_wrap_on.png, build\test_wrap_off.png" -ForegroundColor Cyan
Write-Host "==================================================" -ForegroundColor Green