Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤖 Add bindiff.vm #970

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/bindiff.vm/bindiff.vm.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>bindiff.vm</id>
<version>8.0.0.20240402</version>
<authors>Zynamics</authors>
<description>A comparison tool for binary files that assists in quickly finding differences and similarities in disassembled code</description>
<dependencies>
<dependency id="common.vm" />
<dependency id="vcredist140.vm" />
</dependencies>
</metadata>
</package>
13 changes: 13 additions & 0 deletions packages/bindiff.vm/tools/chocolateyinstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$ErrorActionPreference = 'Stop'
Import-Module vm.common -Force -DisableNameChecking

$toolName = 'BinDiff'
$category = 'File Information'

$exeUrl = 'https://github.com/google/bindiff/releases/download/v8/bindiff8.msi'
$exeSha256 = '688831e490bef8a20c9917048b693bad591f346b3b96489fc79ad8d20d7cb15f'

$toolDir = Join-Path ${Env:ProgramFiles} $toolName
$executablePath = Join-Path $toolDir "bin\bindiff_ui.cmd"

VM-Install-With-Installer -toolName $toolName -category $category -fileType "MSI" -silentArgs '/qn /norestart' -executablePath $executablePath -url $exeUrl -sha256 $exeSha256 -consoleApp $false
7 changes: 7 additions & 0 deletions packages/bindiff.vm/tools/chocolateyuninstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$ErrorActionPreference = 'Continue'
Import-Module vm.common -Force -DisableNameChecking

$toolName = 'BinDiff'
$category = 'File Information'

VM-Uninstall-With-Uninstaller -toolName $toolName -category $category -fileType "MSI" -silentArgs '/qn /norestart'
2 changes: 1 addition & 1 deletion packages/common.vm/common.vm.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>common.vm</id>
<version>0.0.0.20240321</version>
<version>0.0.0.20240402</version>
<description>Common libraries for VM-packages</description>
<authors>Mandiant</authors>
</metadata>
Expand Down
75 changes: 71 additions & 4 deletions packages/common.vm/tools/vm.common/vm.common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,9 @@ function VM-Install-With-Installer {
[Parameter(Mandatory=$false)]
[bool] $consoleApp=$false,
[Parameter(Mandatory=$false)]
[string] $arguments = ""
[string] $arguments = "",
[Parameter(Mandatory=$false)]
[string] $iconLocation
emtuls marked this conversation as resolved.
Show resolved Hide resolved
)
try {
$toolDir = Join-Path ${Env:RAW_TOOLS_DIR} $toolName
Expand Down Expand Up @@ -621,7 +623,27 @@ function VM-Install-With-Installer {
Install-ChocolateyInstallPackage @packageArgs
VM-Assert-Path $executablePath

VM-Install-Shortcut -toolName $toolName -category $category -executablePath $executablePath -consoleApp $consoleApp -arguments $arguments
# if no icon path provided, set the shortcut icon to be the executable's icon. For MSI files, attempt to get executable icon from the installer first.
if (-Not $iconLocation) {
if ($fileType -eq 'MSI') {
$iconPath = VM-Get-MSIInstallerPathByProductName $toolName
if ($iconPath) {
$files = Get-ChildItem -Path $iconPath -Filter "*.ico"
if ($files.Count -gt 0) {
$iconLocation = Join-Path $iconPath $files[0]
}
}
# If no icon found from MSI installation, fallback to using executablePath for iconLocation
if (-Not $iconLocation) {
$iconLocation = $executablePath
}
}
} else {
# Not an MSI file, use executablePath for iconLocation
$iconLocation = $executablePath
}

VM-Install-Shortcut -toolName $toolName -category $category -executablePath $executablePath -consoleApp $consoleApp -arguments $arguments -iconLocation $iconLocation
Install-BinFile -Name $toolName -Path $executablePath
} catch {
VM-Write-Log-Exception $_
Expand All @@ -633,7 +655,9 @@ function VM-Uninstall-With-Uninstaller {
Param
(
[Parameter(Mandatory=$true, Position=0)]
[string] $softwareName,
[string] $toolName,
[Parameter(Mandatory=$true, Position=1)]
[string] $category,
[Parameter(Mandatory=$true, Position=1)]
[ValidateSet("EXE", "MSI")]
[string] $fileType,
Expand All @@ -652,9 +676,16 @@ function VM-Uninstall-With-Uninstaller {
[Parameter(Mandatory=$false)]
[array] $validExitCodes= @(0, 3010, 1605, 1614, 1641)
)
# Remove tool shortcut
VM-Remove-Tool-Shortcut $toolName $category

# Remove tool files
$toolDir = Join-Path ${Env:RAW_TOOLS_DIR} $toolName
Remove-Item $toolDir -Recurse -Force -ea 0 | Out-Null
emtuls marked this conversation as resolved.
Show resolved Hide resolved

# Attempt to find and execute the uninstaller, may need to use wildcards
# See: https://docs.chocolatey.org/en-us/create/functions/get-uninstallregistrykey
[array]$key = Get-UninstallRegistryKey -SoftwareName $softwareName
[array]$key = Get-UninstallRegistryKey -SoftwareName $toolName
if ($key.Count -eq 1) {
$packageArgs = @{
packageName = ${Env:ChocolateyPackageName}
Expand Down Expand Up @@ -1457,3 +1488,39 @@ function VM-Add-To-Path {
[System.Environment]::SetEnvironmentVariable("Path", $newPath, [System.EnvironmentVariableTarget]::Machine)
}
}

# Useful for getting icons for tools installed from an MSI file
function VM-Get-MSIInstallerPathByProductName {
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[string]$ProductName # Name of the installed program
)

try {
# Get a list of all installed MSI products
$installedProducts = Get-CimInstance -Class Win32_Product | Where-Object { $_.Name -like $ProductName }

if (-not $installedProducts) {
VM-Write-Log "WARN" "No product found with name like '$ProductName'"
return
}

foreach ($product in $installedProducts) {
# Retrieve the GUID of the installer
$productCode = $product.IdentifyingNumber

# Construct the likely path to the installer cache
$installerPath = Join-Path -Path 'C:\Windows\Installer' -ChildPath $productCode

# Check if the constructed path exists
if (Test-Path -Path $installerPath) {
return $installerPath
} else {
VM-Write-Log "WARN" "Installer cache folder not found for product '$ProductName'"
}
}
} catch {
VM-Write-Log-Exception $_ "An error occurred: $_"
}
}
Loading