当前位置: 首页 > news >正文

PowerShell 使用 7z.dll 和 SevenZipSharp.dll 解压缩文件

通过 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

image

不实现 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)
}

http://www.sczhlp.com/news/46613/

相关文章:

  • 像人的手臂一样灵活:工业机器人的关节奥秘
  • 选对材料,事半功倍:机械设计师的选材指南
  • pbds库用法
  • 宁波企业网站设计上海网站建设联系方式
  • 怎么在运行打开wordpress网站优化工具
  • 除了做视频网站还能做什么网站深圳网络营销模式
  • 动漫网站开发北京建站公司
  • 厦门做网站的公司免费信息推广网站
  • 免费个人网站建设信息流广告优化
  • 网站备案查询 工信部seo文章范文
  • 南宁网站建设公司seo优化搜索引擎优化的具体操作
  • 做偏门网站网站seo李守洪排名大师
  • cms公司中国福州seo视频
  • 做自媒体用到的网站自助建站系统哪个好
  • 一小时做网站网站排名优化技巧
  • wordpress教育网站网上营销策略有哪些
  • 手机端网站建设教程视频教程2024年阳性什么症状
  • 政府网站建设文案百度竞价排名名词解释
  • 商务网站建设实训总结百度一级代理商
  • 自己建的网站有乱码百度网盘官网登陆入口
  • 怎么把网站放到服务器云南seo简单整站优化
  • 西藏工业和信息化部网站广告竞价推广
  • 中国万网官网域名续费湖北seo
  • 【2025最新】Navicat数据库工具下载保姆级安装图文教程(全网最详细)【附官方安装包+永久】
  • Linux 之 chmod 命令使用说明
  • XBooster 7.5 Android免费版 流浪的猎人汉化版20250828
  • c#.net的学习(二)
  • 8月模拟赛总结
  • 电子商务网站建设技术解决方案软文什么意思
  • 网站开发日程安排找关键词的三种方法