Skip to content

Commit

Permalink
Add bindiff.vm
Browse files Browse the repository at this point in the history
Closes #969.
  • Loading branch information
vm-packages authored and emtuls committed Apr 2, 2024
1 parent 0a185d0 commit a342301
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 5 deletions.
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
)
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

# 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: $_"
}
}

0 comments on commit a342301

Please sign in to comment.