Skip to content

Commit

Permalink
Merge pull request #1083 from Ana06/pip
Browse files Browse the repository at this point in the history
Add autoit-ripper.vm & helper functions to install tools with Pip
  • Loading branch information
Ana06 authored Jun 7, 2024
2 parents 5e29150 + 3409978 commit a6b9dca
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 19 deletions.
13 changes: 13 additions & 0 deletions packages/autoit-ripper.vm/autoit-ripper.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>autoit-ripper.vm</id>
<version>0.0.0.20240607</version>
<authors>Michał Praszmo</authors>
<description>Extracts compiled AutoIt scripts from PE executables.</description>
<dependencies>
<dependency id="common.vm" version="0.0.0.20240607" />
<dependency id="python3.vm" />
</dependencies>
</metadata>
</package>
7 changes: 7 additions & 0 deletions packages/autoit-ripper.vm/tools/chocolateyinstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$ErrorActionPreference = 'Stop'
Import-Module vm.common -Force -DisableNameChecking

$toolName = 'autoit-ripper'
$category = 'Packers'

VM-Install-With-Pip -toolName $toolName -category $category
7 changes: 7 additions & 0 deletions packages/autoit-ripper.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 = 'autoit-ripper'
$category = 'Packers'

VM-Uninstall-With-Pip -toolName $toolName -category $category
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.20240531</version>
<version>0.0.0.20240607</version>
<description>Common libraries for VM-packages</description>
<authors>Mandiant</authors>
</metadata>
Expand Down
47 changes: 46 additions & 1 deletion packages/common.vm/tools/vm.common/vm.common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1735,12 +1735,57 @@ function VM-Get-MSIInstallerPathByProductName {
}
}

# Install Python library with Pip
function VM-Pip-Install {
param (
[string]$package
)
# Create output file to log python module installation details
$outputFile = VM-New-Install-Log ${Env:VM_COMMON_DIR}

Invoke-Expression "py -3.10 -m pip install $package --disable-pip-version-check 2>&1 >> $outputFile"
# Ignore warning with `-W ignore` to avoid warnings like deprecation to fail the installation
Invoke-Expression "py -3.10 -W ignore -m pip install $package --disable-pip-version-check 2>&1 >> $outputFile"
}

# Install tool using Pip and create shortcut in the Tools directory
function VM-Install-With-Pip {
[CmdletBinding()]
[OutputType([System.Object[]])]
Param
(
[Parameter(Mandatory=$true)]
[string] $toolName, # Example: magika
[Parameter(Mandatory=$true)]
[string] $category,
[Parameter(Mandatory=$false)]
[string] $arguments = "--help"
)
try {
VM-Pip-Install $toolName
$executablePath = "$(where.exe $toolName)"

VM-Install-Shortcut $toolName $category $executablePath -consoleApp $true -arguments $arguments
} catch {
VM-Write-Log-Exception $_
}
}

# Uninstall Python library with Pip
function VM-Pip-Uninstall {
param (
[string]$package
)
Invoke-Expression "py -3.10 -m pip uninstall $package -y --disable-pip-version-check 2>&1"
}

# Uninstall tool using Pip and remove shortcut in the Tools directory
function VM-Uninstall-With-Pip {
param (
[Parameter(Mandatory=$true)]
[string] $toolName, # Example: magika
[Parameter(Mandatory=$true)]
[string] $category
)
VM-Pip-Uninstall $toolName
VM-Remove-Tool-Shortcut $toolName $category
}
4 changes: 2 additions & 2 deletions packages/magika.vm/magika.vm.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>magika.vm</id>
<version>0.5.1</version>
<version>0.0.0.20240607</version>
<authors>Yanick Fratantonio, Luca Invernizzi, Marina Zhang, Giancarlo Metitieri, Thomas Kurt, Francois Galilee, Alexandre Petit-Bianco, Loua Farah, Ange Albertini, Elie Bursztein</authors>
<description>Magika is an AI powered file type detection tool that uses deep learning to provide accurate detection.</description>
<dependencies>
<dependency id="common.vm" />
<dependency id="common.vm" version="0.0.0.20240607" />
<dependency id="python3.vm" />
</dependencies>
</metadata>
Expand Down
15 changes: 3 additions & 12 deletions packages/magika.vm/tools/chocolateyinstall.ps1
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
$ErrorActionPreference = 'Stop'
Import-Module vm.common -Force -DisableNameChecking

try {
$toolName = 'magika'
$category = 'File Information'
$toolName = 'magika'
$category = 'File Information'

VM-Pip-Install $toolName

$executablePath = "$(where.exe $toolName)"
$arguments = "--help"

VM-Install-Shortcut $toolName $category $executablePath -consoleApp $true -arguments $arguments -iconLocation $iconLocation
} catch {
VM-Write-Log-Exception $_
}
VM-Install-With-Pip -toolName $toolName -category $category
4 changes: 1 addition & 3 deletions packages/magika.vm/tools/chocolateyuninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ Import-Module vm.common -Force -DisableNameChecking
$toolName = 'magika'
$category = 'File Information'

Invoke-Expression "py -3.10 -m pip uninstall $toolName -y"

VM-Uninstall $toolName $category
VM-Uninstall-With-Pip -toolName $toolName -category $category

0 comments on commit a6b9dca

Please sign in to comment.