Skip to content

Commit

Permalink
Add unzip "infected" to right click menu
Browse files Browse the repository at this point in the history
Add 7z unzip with password "infected" option to the right menu for the
most common extensions.
  • Loading branch information
Ana06 committed Sep 26, 2023
1 parent 1f91b37 commit d3dd71a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 19 deletions.
6 changes: 3 additions & 3 deletions packages/7zip-15-05.vm/7zip-15-05.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>7zip-15-05.vm</id>
<version>15.05</version>
<version>15.05.0.20230926</version>
<authors>Igor Pavlov</authors>
<description>7-Zip file archiver. This version is able to extract NSIS scripts.</description>
<dependencies>
<dependency id="common.vm" />
<dependency id="common.vm" version="0.0.0.20230926" />
</dependencies>
</metadata>
</package>
</package>
13 changes: 10 additions & 3 deletions packages/7zip-15-05.vm/tools/chocolateyinstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ try {
Install-ChocolateyShortcut -shortcutFilePath $shortcut -targetPath $executablePath
VM-Assert-Path $shortcut

$executablePath = Join-Path $toolDir "7z.exe" -Resolve
Install-BinFile -Name $toolName -Path $executablePath
$7zExecutablePath = Join-Path $toolDir "7z.exe" -Resolve
Install-BinFile -Name $toolName -Path $7zExecutablePath

# Add 7z unzip with password "infected" to the right menu for the most common extensions.
# 7z can unzip other file extensions like .docx but these don't likely use the infected password.
$extensions = @(".7z", ".bzip2", ".gzip", ".tar", ".wim", ".xz", ".txz", ".zip", ".rar")
foreach ($extension in $extensions) {
VM-Add-To-Right-Click-Menu $toolName 'unzip "infected"' "`"$7zExecutablePath`" e -pinfected `"%1`"" "$executablePath" -extension $extension
}
} catch {
VM-Write-Log-Exception $_
}
}
7 changes: 6 additions & 1 deletion packages/7zip-15-05.vm/tools/chocolateyuninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ VM-Remove-Tool-Shortcut $toolName $category
Uninstall-BinFile -Name $toolName

# Manually silently uninstall
VM-Uninstall-With-Uninstaller "7-Zip 15.05*" "EXE" "/S"
VM-Uninstall-With-Uninstaller "7-Zip 15.05*" "EXE" "/S"

$extensions = @(".7z", ".bzip2", ".gzip", ".tar", ".wim", ".xz", ".txz", ".zip", ".rar")
foreach ($extension in $extensions) {
VM-Remove-From-Right-Click-Menu $toolName -extension $extension
}
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.20230925</version>
<version>0.0.0.20230926</version>
<description>Common libraries for VM-packages</description>
<authors>Mandiant</authors>
</metadata>
Expand Down
34 changes: 23 additions & 11 deletions packages/common.vm/tools/vm.common/vm.common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -698,14 +698,20 @@ function VM-Add-To-Right-Click-Menu {
[string] $menuIcon,
[Parameter(Mandatory=$false)]
[ValidateSet("file", "directory")]
[string] $type="file"
[string] $type="file",
[Parameter(Mandatory=$false)]
[string] $extension
)
try {
# Determine if file or directory should show item in right-click menu
if ($type -eq "file") {
$key = "*"
if ($extension) {
$key = "SystemFileAssociations\$extension"
} else {
$key = "directory"
# Determine if file or directory should show item in right-click menu
if ($type -eq "file") {
$key = "*"
} else {
$key = "directory"
}
}
$key_path = "HKCR:\$key\shell\$menuKey"

Expand All @@ -716,7 +722,7 @@ function VM-Add-To-Right-Click-Menu {

# Add right-click menu display name
if (-NOT (Test-Path -LiteralPath $key_path)) {
New-Item -Path $key_path | Out-Null
New-Item -Path $key_path -Force | Out-Null
}
Set-ItemProperty -LiteralPath $key_path -Name '(Default)' -Value "$menuLabel" -Type String
if ($menuIcon) {
Expand All @@ -740,14 +746,20 @@ function VM-Remove-From-Right-Click-Menu {
[String] $menuKey, # name of registry key
[Parameter(Mandatory=$true, Position=1)]
[ValidateSet("file", "directory")]
[string] $type="file"
[string] $type="file",
[Parameter(Mandatory=$false)]
[string] $extension
)
try {
# Determine if file or directory should show item in right-click menu
if ($type -eq "file") {
$key = "*"
if ($extension) {
$key = "SystemFileAssociations\$extension"
} else {
$key = "directory"
# Determine if file or directory should show item in right-click menu
if ($type -eq "file") {
$key = "*"
} else {
$key = "directory"
}
}
$key_path = "HKCR:\$key\shell\$menuKey"

Expand Down

0 comments on commit d3dd71a

Please sign in to comment.