From fe0667092e460189980f53341f264e475a218063 Mon Sep 17 00:00:00 2001 From: Ana Maria Martinez Gomez Date: Tue, 29 Oct 2024 15:39:41 +0100 Subject: [PATCH] VM-Pip-Install: extend to support list Extend the `VM-Pip-Install` function helper to support a list of Python libraries to install. Use the new feature to simplify the code in `internet_detector`. --- packages/common.vm/common.vm.nuspec | 2 +- packages/common.vm/tools/vm.common/vm.common.psm1 | 10 ++++++---- .../internet_detector.vm/internet_detector.vm.nuspec | 2 +- .../internet_detector.vm/tools/chocolateyinstall.ps1 | 6 ++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/common.vm/common.vm.nuspec b/packages/common.vm/common.vm.nuspec index 6a957f5a..8ce9e321 100755 --- a/packages/common.vm/common.vm.nuspec +++ b/packages/common.vm/common.vm.nuspec @@ -2,7 +2,7 @@ common.vm - 0.0.0.20241002 + 0.0.0.20241029 Common libraries for VM-packages Mandiant diff --git a/packages/common.vm/tools/vm.common/vm.common.psm1 b/packages/common.vm/tools/vm.common/vm.common.psm1 index c6edc13d..f976e6e0 100755 --- a/packages/common.vm/tools/vm.common/vm.common.psm1 +++ b/packages/common.vm/tools/vm.common/vm.common.psm1 @@ -1737,16 +1737,18 @@ function VM-Get-MSIInstallerPathByProductName { } } -# Install Python library with Pip +# Install Python library/ies with Pip function VM-Pip-Install { param ( - [string]$package + [string]$libraries # Comma-separated list of libraries to install, example: "flare-capa", "flare-capa,tabulate" ) # Create output file to log python module installation details $outputFile = VM-New-Install-Log ${Env:VM_COMMON_DIR} - # 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" + ForEach ($library in $libraries.Split(",")) { + # Ignore warning with `-W ignore` to avoid warnings like deprecation to fail the installation + Invoke-Expression "py -3.10 -W ignore -m pip install $library --disable-pip-version-check 2>&1 >> $outputFile" + } } # Install tool using Pip and create shortcut in the Tools directory diff --git a/packages/internet_detector.vm/internet_detector.vm.nuspec b/packages/internet_detector.vm/internet_detector.vm.nuspec index aa7c6ae7..c9bce5e9 100644 --- a/packages/internet_detector.vm/internet_detector.vm.nuspec +++ b/packages/internet_detector.vm/internet_detector.vm.nuspec @@ -6,7 +6,7 @@ Elliot Chernofsky and Ana Martinez Gomez Tool that changes the background and a taskbar icon if it detects internet connectivity - + diff --git a/packages/internet_detector.vm/tools/chocolateyinstall.ps1 b/packages/internet_detector.vm/tools/chocolateyinstall.ps1 index a6467801..a999eb58 100644 --- a/packages/internet_detector.vm/tools/chocolateyinstall.ps1 +++ b/packages/internet_detector.vm/tools/chocolateyinstall.ps1 @@ -11,10 +11,8 @@ New-Item -Path $toolDir -ItemType Directory -Force -ea 0 VM-Assert-Path $toolDir # Install pyinstaller (needed to build the Python executable) and tool dependencies ('pywin32') -$dependencies = @('pyinstaller', 'pywin32') -ForEach ($dependency in $dependencies) { - VM-Pip-Install $dependency -} +$dependencies = "pyinstaller,pywin32" +VM-Pip-Install $dependencies # This wrapper is needed because we can't run PyInstaller as admin, so this forces a usermode context. Start-Process -FilePath 'cmd.exe' -ArgumentList "/c pyinstaller --onefile -w --distpath $toolDir --workpath $packageToolDir --specpath $packageToolDir $packageToolDir\internet_detector.pyw" -Wait