Skip to content

Instantly share code, notes, and snippets.

@Amgelo563
Last active February 20, 2026 14:54
Show Gist options
  • Select an option

  • Save Amgelo563/5f3f5b014904e85dfa0d929e8bd354e7 to your computer and use it in GitHub Desktop.

Select an option

Save Amgelo563/5f3f5b014904e85dfa0d929e8bd354e7 to your computer and use it in GitHub Desktop.
Powershell script to search in a folder of JARs for a given string inside those jars, also searches in nested jars (shaded)

SearchJars

Powershell script to search in a folder of JARs for a given string inside those jars. Also searches in nested jars (shaded).

Example usage:

.\SearchJars.ps1 -FolderPath "E:\.minecraft\mods" -SearchString "Search me!"

I initially did this to quickly search for unknown strings in Minecraft mods, though it can be used for anything else.

Warning

This is not a decompiler. It'll merely search for hardcoded strings, not actual code. It'll probably also match string constants that can be built at compile time (e.g. concatenated string literals) but I haven't tested that and have no guarantees of it.

param (
[Parameter(Mandatory = $true)]
[string]$FolderPath,
[Parameter(Mandatory = $true)]
[string]$SearchString
)
Add-Type -AssemblyName System.IO.Compression.FileSystem
$matchedPaths = [System.Collections.Generic.List[string]]::new()
function Search-Jar {
param (
[System.IO.Stream]$Stream,
[string]$JarPath,
[string]$SearchString
)
try {
$zip = New-Object System.IO.Compression.ZipArchive($Stream, [System.IO.Compression.ZipArchiveMode]::Read)
foreach ($entry in $zip.Entries) {
if ([string]::IsNullOrWhiteSpace($entry.Name)) {
continue
}
$entryFullPath = "$JarPath -> $($entry.FullName)"
if ($entry.FullName -imatch '\.jar$') {
Write-Output "Searching nested JAR: $entryFullPath"
try {
$nestedStream = $entry.Open()
$memStream = New-Object System.IO.MemoryStream
$nestedStream.CopyTo($memStream)
$nestedStream.Close()
$memStream.Position = 0
Search-Jar -Stream $memStream -JarPath $entryFullPath -SearchString $SearchString
$memStream.Dispose()
}
catch {
Write-Warning "Failed to process nested JAR: $entryFullPath"
}
continue
}
# Search all other entries as text
try {
$entryStream = $entry.Open()
$reader = New-Object System.IO.StreamReader($entryStream)
$content = $reader.ReadToEnd()
if ($content -imatch [regex]::Escape($SearchString)) {
Write-Host "Match found: $entryFullPath" -ForegroundColor Green
$matchedPaths.Add($entryFullPath)
}
$reader.Close()
$entryStream.Close()
}
catch {
continue
}
}
$zip.Dispose()
}
catch {
Write-Warning "Failed to read ZIP/JAR stream at: $JarPath"
}
}
$jarFiles = Get-ChildItem -Path $FolderPath -Filter *.jar -File
foreach ($jar in $jarFiles) {
Write-Output "Searching JAR: $($jar.Name)"
try {
$fileStream = [System.IO.File]::OpenRead($jar.FullName)
Search-Jar -Stream $fileStream -JarPath $jar.Name -SearchString $SearchString
$fileStream.Dispose()
}
catch {
Write-Warning "Failed to open JAR: $($jar.FullName)"
}
}
Write-Output ""
if ($matchedPaths.Count -eq 0) {
Write-Output "No matches found in any scanned JAR."
} else {
Write-Output "Found $($matchedPaths.Count) match(es):"
foreach ($path in $matchedPaths) {
Write-Host " $path" -ForegroundColor Green
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment