Skip to content

Instantly share code, notes, and snippets.

@R0rt1z2
Last active November 21, 2025 10:04
Show Gist options
  • Select an option

  • Save R0rt1z2/f91883518b5d63eedc8412eebb433ce7 to your computer and use it in GitHub Desktop.

Select an option

Save R0rt1z2/f91883518b5d63eedc8412eebb433ce7 to your computer and use it in GitHub Desktop.
Automated Ghidra Installer for Windows
$ProgressPreference = 'SilentlyContinue'
$installPath = "C:\Program Files\Ghidra"
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator')) {
$encodedScript = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($MyInvocation.MyCommand.Definition))
Start-Process powershell -Verb RunAs -ArgumentList "-NoProfile", "-ExecutionPolicy", "Bypass", "-EncodedCommand", $encodedScript -Wait
exit
}
try {
$release = Invoke-RestMethod -Uri 'https://api.github.com/repos/NationalSecurityAgency/ghidra/releases/latest'
$asset = $release.assets | Where-Object { $_.name -like '*.zip' -and $_.name -notlike '*debugSymbols*' } | Select-Object -First 1
if (Test-Path $installPath) {
Write-Host "Removing existing installation..." -ForegroundColor Yellow
Get-Process | Where-Object { $_.Path -like "$installPath*" } | Stop-Process -Force -ErrorAction SilentlyContinue
Remove-Item -Path $installPath -Recurse -Force
}
$tempFile = "$env:TEMP\ghidra.zip"
Write-Host "Downloading Ghidra $($release.tag_name)..." -ForegroundColor Green
Invoke-WebRequest -Uri $asset.browser_download_url -OutFile $tempFile
Write-Host "Extracting Ghidra..." -ForegroundColor Green
Expand-Archive -Path $tempFile -DestinationPath $env:TEMP -Force
$extractedFolder = Get-ChildItem -Path $env:TEMP -Directory | Where-Object { $_.Name -like 'ghidra_*' } | Sort-Object LastWriteTime -Descending | Select-Object -First 1
Move-Item -Path $extractedFolder.FullName -Destination $installPath -Force
Remove-Item -Path $tempFile -Force
$ghidraRun = "$installPath\ghidraRun.bat"
$ghidraIcon = "$installPath\support\ghidra.ico"
if (Test-Path $ghidraRun) {
$shell = New-Object -ComObject WScript.Shell
@(
"$env:USERPROFILE\Desktop\Ghidra.lnk"
"$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Ghidra.lnk"
"$env:APPDATA\Microsoft\Windows\SendTo\Ghidra.lnk"
) | ForEach-Object {
$shortcut = $shell.CreateShortcut($_)
$shortcut.TargetPath = $ghidraRun
$shortcut.IconLocation = $ghidraIcon
$shortcut.Save()
}
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($shell) | Out-Null
}
Write-Host "Ghidra has been installed." -ForegroundColor Green
}
catch {
Write-Host "Installation failed: $_" -ForegroundColor Red
}
Read-Host -Prompt "Press Enter to continue..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment