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 ZIP support in VM-Install-IDA-Plugin & Add ida.plugin.dereferencing.vm #1020

Merged
merged 2 commits into from
Apr 30, 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
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.20240425</version>
<version>0.0.0.20240429</version>
<description>Common libraries for VM-packages</description>
<authors>Mandiant</authors>
</metadata>
Expand Down
56 changes: 47 additions & 9 deletions packages/common.vm/tools/vm.common/vm.common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,10 @@ function VM-Get-IDA-Plugins-Dir {
return New-Item "$Env:APPDATA\Hex-Rays\IDA Pro\plugins" -ItemType "directory" -Force
}

# Downloads an IDA plugin file to the plugins directory
# Downloads an IDA plugin file or ZIP containing a plugin (and supporting files/directories) to the plugins directory.
# For ZIPs, we check if there is an inner folder (this is the case for GH ZIPs) and if there is a directory called 'plugins'.
# We copy all files in this directory with the exception of the README and the LICENSE file (often present in GH repos).
# The copied files must include $pluginName.
function VM-Install-IDA-Plugin {
[CmdletBinding()]
[OutputType([System.Object[]])]
Expand All @@ -302,17 +305,52 @@ function VM-Install-IDA-Plugin {
[string] $pluginSha256
)
try {
$pluginExtension = [System.IO.Path]::GetExtension($pluginUrl)
$pluginsDir = VM-Get-IDA-Plugins-Dir
$pluginPath = Join-Path $pluginsDir $pluginName
$packageArgs = @{
packageName = ${Env:ChocolateyPackageName}
url = $pluginUrl
checksum = $pluginSha256
checksumType = "sha256"
fileFullPath = $pluginPath
forceDownload = $true

if ($pluginExtension -eq ".zip") {
$tempDownloadDir = Join-Path ${Env:chocolateyPackageFolder} "temp_$([guid]::NewGuid())"
# Download and unzip
$packageArgs = @{
packageName = ${Env:ChocolateyPackageName}
unzipLocation = $tempDownloadDir
url = $pluginUrl
checksum = $pluginSha256
checksumType = 'sha256'
}
Install-ChocolateyZipPackage @packageArgs | Out-Null
VM-Assert-Path $tempDownloadDir

# Check if there is inner folder (for example for ZIPs downloaded from GH)
$childItems = Get-ChildItem $tempDownloadDir -ea 0
if (($childItems).Count -eq 1) {
$subDir = Join-Path $tempDownloadDir $childItems
if (Test-Path $subDir -PathType Container) {
$tempDownloadDir = $subDir
}
}
# Look for the plugins directory
$pluginDir = Get-Item "$tempDownloadDir\plugins" -ea 0
if (!$pluginDir) { $pluginDir = $tempDownloadDir }

# Delete files we don't want to copy
Remove-Item "$pluginDir\README*" -Force -ea 0
Remove-Item "$pluginDir\LICENSE*" -Force -ea 0

Copy-Item "$pluginDir\*" $pluginsDir -Recurse
}
else {
$packageArgs = @{
packageName = ${Env:ChocolateyPackageName}
url = $pluginUrl
checksum = $pluginSha256
checksumType = "sha256"
fileFullPath = $pluginPath
forceDownload = $true
}
Get-ChocolateyWebFile @packageArgs
}
Get-ChocolateyWebFile @packageArgs
VM-Assert-Path $pluginPath
} catch {
VM-Write-Log-Exception $_
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>ida.plugin.dereferencing.vm</id>
<version>0.0.0.20240430</version>
<authors>danigargu</authors>
<description>IDA Pro plugin that implements new registers and stack views.</description>
<dependencies>
<dependency id="common.vm" version="0.0.0.20240429" />
</dependencies>
</metadata>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$ErrorActionPreference = 'Stop'
Import-Module vm.common -Force -DisableNameChecking

$pluginName = 'dereferencing.py'
$pluginUrl = 'https://github.com/danigargu/deREferencing/archive/c5c606a9e70bff48214ce5286a37b15752fd8d1b.zip'
$pluginSha256 = '3ddec5c7569bc53883c5feaeb36d1145e2dde1c67491d14929af05938870dc1e'

VM-Install-IDA-Plugin -pluginName $pluginName -pluginUrl $pluginUrl -pluginSha256 $pluginSha256
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$ErrorActionPreference = 'Continue'
Import-Module vm.common -Force -DisableNameChecking

$pluginName = 'dereferencing.py'
VM-Uninstall-IDA-Plugin -pluginName $pluginName

2 changes: 1 addition & 1 deletion scripts/utils/create_package_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def package_version(dependency_version):
<authors>{authors}</authors>
<description>{description}</description>
<dependencies>
<dependency id="common.vm" version="0.0.0.20240424" />
<dependency id="common.vm" version="0.0.0.20240429" />
</dependencies>
</metadata>
</package>
Expand Down
Loading