Skip to content

Commit e06a018

Browse files
Strip unnecessary John files to reduce package size (#18)
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
1 parent 74553d7 commit e06a018

File tree

7 files changed

+165
-5
lines changed

7 files changed

+165
-5
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ jobs:
9999
shell: pwsh
100100
run: ./PowerShellBuildTools/build.ps1 -Configuration $env:BUILD_CONFIGURATION -Task Build
101101

102+
- name: Check package size
103+
shell: pwsh
104+
run: |
105+
$nupkg = Get-Item out/*.nupkg
106+
$sizeMB = [math]::Round($nupkg.Length / 1MB, 2)
107+
Write-Host "Package size: $sizeMB MB"
108+
if ($sizeMB -gt 250) {
109+
Write-Error "Package size ($sizeMB MB) exceeds PowerShell Gallery limit of 250 MB"
110+
exit 1
111+
}
112+
Write-Host "Package size is within limits" -ForegroundColor Green
113+
102114
- name: Capture PowerShell Module
103115
uses: actions/upload-artifact@v4
104116
with:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313

1414
+ Fixed GHA Workflow CI to build and package module correctly (#2).
1515
+ Included up to date documentation in the module package (#3).
16+
+ Stripped unnecessary files from John the Ripper builds to reduce package size (#4).

docker/Dockerfile.linux

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ COPY ./global.json /PoshJohn/global.json
2525

2626
WORKDIR /PoshJohn/scripts
2727

28-
RUN chmod +x ./build-john-linux.sh && dos2unix ./build-john-linux.sh && ./build-john-linux.sh
28+
RUN chmod +x ./build-john-linux.sh && dos2unix ./build-john-linux.sh && ./build-john-linux.sh 2>&1 | tee ./build-john-linux.log
2929

3030
WORKDIR /PoshJohn/PowerShellBuildTools
3131

scripts/build-john-linux.sh

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ git clone --depth 1 "$JOHN_REPO" "$JOHN_DIR"
4848
cd "$JOHN_SRC_DIR"
4949
echo "Configuring John the Ripper..."
5050
chmod +x ./configure
51-
./configure
51+
./configure --disable-native-tests
5252

5353
echo "Cleaning previous builds..."
5454
make -s clean
@@ -58,3 +58,54 @@ make -sj"$(nproc)"
5858

5959
echo "John the Ripper build complete. Binaries are in $JOHN_RUN_DIR"
6060

61+
# Strip unnecessary files to reduce package size
62+
echo "Stripping unnecessary files..."
63+
cd "$JOHN_RUN_DIR"
64+
65+
# Count before
66+
BEFORE_COUNT=$(find . -type f | wc -l)
67+
if [ "$BEFORE_COUNT" -eq 0 ]; then
68+
echo "Error: No files found in $JOHN_RUN_DIR - build may have failed"
69+
exit 1
70+
fi
71+
BEFORE_SIZE=$(du -sm . | cut -f1)
72+
73+
# Remove files in root directory only (preserve subdirectories like rules/)
74+
find . -maxdepth 1 -type f | while read -r file; do
75+
basename="$(basename "$file")"
76+
keep=false
77+
78+
# Keep specific executables
79+
if [[ "$basename" == "john" || "$basename" == "zip2john" ]]; then
80+
keep=true
81+
# Keep pdf2john.py
82+
elif [[ "$basename" == "pdf2john.py" ]]; then
83+
keep=true
84+
# Keep all .conf files
85+
elif [[ "$basename" == *.conf ]]; then
86+
keep=true
87+
# Keep all .chr files
88+
elif [[ "$basename" == *.chr ]]; then
89+
keep=true
90+
# Keep shared libraries
91+
elif [[ "$basename" == libcrypto* || "$basename" == libssl* || "$basename" == libz* || "$basename" == libgmp* ]]; then
92+
keep=true
93+
fi
94+
95+
if [ "$keep" = false ]; then
96+
rm -f "$file"
97+
fi
98+
done
99+
100+
# Count after
101+
AFTER_COUNT=$(find . -type f | wc -l)
102+
if [ "$AFTER_COUNT" -eq 0 ]; then
103+
echo "Error: All files were removed from $JOHN_RUN_DIR - file removal logic may be incorrect"
104+
exit 1
105+
fi
106+
AFTER_SIZE=$(du -sm . | cut -f1)
107+
SAVED=$((BEFORE_COUNT - AFTER_COUNT))
108+
SIZE_SAVED=$((BEFORE_SIZE - AFTER_SIZE))
109+
110+
echo "Removed $SAVED files (saved ${SIZE_SAVED}MB)"
111+
echo "Kept $AFTER_COUNT essential files (${AFTER_SIZE}MB) in $JOHN_RUN_DIR"

scripts/build-john-macos.sh

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ chmod +x ./configure
7171
HOMEBREW_PREFIX="/opt/homebrew"
7272
GCC_BIN="$HOMEBREW_PREFIX/bin/$(ls $HOMEBREW_PREFIX/bin | grep -E '^gcc-[0-9]+$' | sort -V | tail -n1)"
7373

74-
./configure CC="$GCC_BIN" LDFLAGS="-L$HOMEBREW_PREFIX/lib" CPPFLAGS="-I$HOMEBREW_PREFIX/include"
74+
./configure CC="$GCC_BIN" LDFLAGS="-L$HOMEBREW_PREFIX/lib" CPPFLAGS="-I$HOMEBREW_PREFIX/include" --disable-native-tests
7575

7676
echo "Cleaning previous builds..."
7777
make -s clean
@@ -80,3 +80,55 @@ echo "Building John the Ripper..."
8080
make -sj"$(sysctl -n hw.ncpu)"
8181

8282
echo "John the Ripper build complete. Binaries are in $JOHN_RUN_DIR"
83+
84+
# Strip unnecessary files to reduce package size
85+
echo "Stripping unnecessary files..."
86+
cd "$JOHN_RUN_DIR"
87+
88+
# Count before
89+
BEFORE_COUNT=$(find . -type f | wc -l | tr -d ' ')
90+
if [ "$BEFORE_COUNT" -eq 0 ]; then
91+
echo "Error: No files found in $JOHN_RUN_DIR - build may have failed"
92+
exit 1
93+
fi
94+
BEFORE_SIZE=$(du -sm . | cut -f1)
95+
96+
# Remove files in root directory only (preserve subdirectories like rules/)
97+
find . -maxdepth 1 -type f | while read -r file; do
98+
basename="$(basename "$file")"
99+
keep=false
100+
101+
# Keep specific executables
102+
if [[ "$basename" == "john" || "$basename" == "zip2john" ]]; then
103+
keep=true
104+
# Keep pdf2john.py
105+
elif [[ "$basename" == "pdf2john.py" ]]; then
106+
keep=true
107+
# Keep all .conf files
108+
elif [[ "$basename" == *.conf ]]; then
109+
keep=true
110+
# Keep all .chr files
111+
elif [[ "$basename" == *.chr ]]; then
112+
keep=true
113+
# Keep shared libraries
114+
elif [[ "$basename" == libcrypto* || "$basename" == libssl* || "$basename" == libz* || "$basename" == libgmp* ]]; then
115+
keep=true
116+
fi
117+
118+
if [ "$keep" = false ]; then
119+
rm -f "$file"
120+
fi
121+
done
122+
123+
# Count after
124+
AFTER_COUNT=$(find . -type f | wc -l | tr -d ' ')
125+
if [ "$AFTER_COUNT" -eq 0 ]; then
126+
echo "Error: All files were removed from $JOHN_RUN_DIR - file removal logic may be incorrect"
127+
exit 1
128+
fi
129+
AFTER_SIZE=$(du -sm . | cut -f1)
130+
SAVED=$((BEFORE_COUNT - AFTER_COUNT))
131+
SIZE_SAVED=$((BEFORE_SIZE - AFTER_SIZE))
132+
133+
echo "Removed $SAVED files (saved ${SIZE_SAVED}MB)"
134+
echo "Kept $AFTER_COUNT essential files (${AFTER_SIZE}MB) in $JOHN_RUN_DIR"

scripts/build-john-windows.ps1

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,53 @@ try {
4646
Write-Warning "pdf2john.py not found in cloned repo at $pdf2johnSrc"
4747
}
4848

49+
# Strip unnecessary files to reduce package size
50+
Write-Host "Stripping unnecessary files..." -ForegroundColor Cyan
51+
$files = Get-ChildItem -Path $outputDir -Recurse -File
52+
if (-not $files -or $files.Count -eq 0) {
53+
throw "No files found in $outputDir - download or extraction may have failed"
54+
}
55+
$beforeSize = ($files | Measure-Object -Property Length -Sum).Sum / 1MB
56+
57+
$keepPatterns = @(
58+
'john.exe', 'zip2john.exe', 'pdf2john.py',
59+
'*.conf', '*.chr',
60+
'cygwin1.dll', 'cygcrypto*.dll', 'cygssl*.dll', 'cygz.dll',
61+
'cyggmp*.dll', 'cygcrypt*.dll', 'cyggcc_s*.dll', 'cygbz2*.dll', 'cyggomp*.dll',
62+
'cygOpenCL*.dll'
63+
)
64+
65+
$allFiles = Get-ChildItem -Path $outputDir -File
66+
$filesToRemove = $allFiles | Where-Object {
67+
$file = $_
68+
$keep = $false
69+
foreach ($pattern in $keepPatterns) {
70+
if ($file.Name -like $pattern) {
71+
$keep = $true
72+
break
73+
}
74+
}
75+
-not $keep
76+
}
77+
78+
$removedCount = 0
79+
foreach ($file in $filesToRemove) {
80+
Remove-Item $file.FullName -Force -ErrorAction SilentlyContinue
81+
$removedCount++
82+
}
83+
84+
$filesAfter = Get-ChildItem -Path $outputDir -Recurse -File
85+
if (-not $filesAfter -or $filesAfter.Count -eq 0) {
86+
throw "All files were removed from $outputDir - file removal logic may be incorrect"
87+
}
88+
$afterSize = ($filesAfter | Measure-Object -Property Length -Sum).Sum / 1MB
89+
$saved = $beforeSize - $afterSize
90+
91+
Write-Host "Removed $removedCount files (saved $([math]::Round($saved, 2)) MB)" -ForegroundColor Green
92+
4993
$fileCount = (Get-ChildItem $outputDir -Recurse -File).Count
5094
Write-Host "`nDownload completed successfully!" -ForegroundColor Green
51-
Write-Host "Copied $fileCount files to: $outputDir" -ForegroundColor Green
95+
Write-Host "Kept $fileCount essential files ($([math]::Round($afterSize, 2)) MB) in: $outputDir" -ForegroundColor Green
5296

5397
}
5498
catch {

src/PoshJohn.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<ItemGroup>
1919
<None Include="PoshJohn.psd1" CopyToOutputDirectory="PreserveNewest" />
2020
<None Include="PoshJohn.psm1" CopyToOutputDirectory="PreserveNewest" />
21-
<None Include="../john/**" CopyToOutputDirectory="PreserveNewest" Link="john/%(RecursiveDir)%(Filename)%(Extension)" />
21+
<None Include="../john/**/run/**" CopyToOutputDirectory="PreserveNewest" Link="john/%(RecursiveDir)%(Filename)%(Extension)" />
2222
</ItemGroup>
2323

2424
<Target Name="PreBuildJohnWindows" BeforeTargets="Build" Condition=" '$(OS)' == 'Windows_NT' and !Exists('$(ProjectDir)../john/windows/run') and '$(GITHUB_ACTIONS)' != 'true' ">

0 commit comments

Comments
 (0)