通过 dependency walker (depends.exe)查看 7z.dll 发现有如下的导出函数
CreateObject
GetHandlerProperty2
GetHandlerProperty
GetMethodProperty
GetNumberOfFormats
GetNumberOfMethods
SetLargePageMode
或者
"C:\Users\geyee\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\bin\x86_amd64\dumpbin.exe" /exports "C:\Program Files (x86)\筑龙软件\某XXX平台标书查看工具\7z.dll"
Microsoft (R) COFF/PE Dumper Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file C:\Program Files (x86)\筑龙软件\某XXX平台标书查看工具\7z.dll
File Type: DLL
Section contains the following exports for 7z.dll
00000000 characteristics
4DAC88C7 time date stamp Tue Apr 19 02:53:59 20110.00 version1 ordinal base7 number of functions7 number of namesordinal hint RVA name1 0 00008905 CreateObject3 1 00008888 GetHandlerProperty2 2 00008793 GetHandlerProperty24 3 0006CB80 GetMethodProperty5 4 0000889E GetNumberOfFormats6 5 0006CCC0 GetNumberOfMethods7 6 0000896B SetLargePageMode
Summary
C000 .data17000 .rdata9000 .reloc18000 .rsrc1000 .sxdataA9000 .text
不实现 Com 接口,而利用 dll 的 PowerShell 脚本有
# 加载必要的程序集
Add-Type -Path "C:\Program Files (x86)\筑龙软件\某XX电子交易平台标书查看工具\SevenZipSharp.dll"# 设置7z.dll路径
[SevenZip.SevenZipBase]::SetLibraryPath("C:\Program Files (x86)\筑龙软件\某XX电子交易平台标书查看工具\7z.dll")# 解压文件
function Expand-7Zip {param([Parameter(Mandatory = $true)][string]$ArchivePath,[Parameter(Mandatory = $true)][string]$OutputDirectory,[SecureString]$Password = $null)try {if (-not (Test-Path -LiteralPath $OutputDirectory)) {New-Item -ItemType Directory -Force -Path $OutputDirectory | out-null}if ($Password) {$plainPassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password))$extractor = New-Object SevenZip.SevenZipExtractor($ArchivePath, $plainPassword)}else {$extractor = New-Object SevenZip.SevenZipExtractor($ArchivePath)}$extractor.ExtractArchive($OutputDirectory)Write-Host "解压成功: $ArchivePath -> $OutputDirectory" -ForegroundColor Greenreturn $true}catch {Write-Error "解压失败: $($_.Exception.Message)"return $false}finally {if ($null -ne $extractor) { $extractor.Dispose() }}}
示例:解压无密码的压缩包
$archive = "C:\path\to\your\archive.7z"
$output = "C:\path\to\output\folder"
Expand-7Zip -ArchivePath $archive -OutputDirectory $output
示例:解压有密码的压缩包
$archive = "C:\path\to\your\protected_archive.7z"
$output = "C:\path\to\output\folder"
$password = Read-Host "请输入压缩包密码" -AsSecureString
Expand-7Zip -ArchivePath $archive -OutputDirectory $output -Password $password
比如 expand-7Zip "D:\mysoftware\temp_test_extract\test.7z" D:\extracted -Password $(read-host "pass" -AsSecureString)
如果降低安全需求的话,可以将 [SecureString]$Password 替换成 [String]$Password,并修改
if ($Password) {
$plainPassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto(
[Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password)
)
$extractor = New-Object SevenZip.SevenZipExtractor($ArchivePath, $plainPassword)
}
为
if ($Password) {
$extractor = New-Object SevenZip.SevenZipExtractor($ArchivePath, $Password)
}