VS2010的VB.NET版本zip压缩包文件密码恢复代码QZQ

Imports SharpCompress.Archives
Imports SharpCompress.Archives.Zip
Imports SharpCompress.Common
Imports System.IO
Imports System.Threading

Module Module1

Sub Main()
    ' 设置 zip 文件的路径
    Dim zipPath As String = "C:\Users\Administrator\Desktop\20 - 副本\2.zip"

    ' 读取密码字典文件
    Dim passwordDictPath As String = "C:\Users\Administrator\Desktop\20 - 副本\mm.txt"
    Dim passwords() As String = File.ReadAllLines(passwordDictPath)

    ' 定义一个布尔变量来标识解压是否成功
    Dim isExtractSuccessful As Boolean = False

    For Each password As String In passwords
        Try
            Using archive As ZipArchive = ZipArchive.Open(zipPath, New SharpCompress.Readers.ReaderOptions() With {.Password = password})
                Console.WriteLine("正在尝试密码:" & password)
                Thread.Sleep(10) ' 延时 1 秒,可根据需要调整时长
                For Each entry As ZipArchiveEntry In archive.Entries
                    If Not entry.IsDirectory Then
                        Dim extractedFilePath As String = Path.Combine("C:\Users\Administrator\Desktop\1\新建文件夹\", entry.Key)
                        Dim directoryPath As String = Path.GetDirectoryName(extractedFilePath)
                        If Not Directory.Exists(directoryPath) Then
                            Directory.CreateDirectory(directoryPath)
                        End If

                        Using outputStream As FileStream = File.Create(extractedFilePath)
                            Using inputStream As Stream = entry.OpenEntryStream()
                                Dim buffer(4096) As Byte
                                Dim read As Integer
                                While (InlineAssignHelper(read, inputStream.Read(buffer, 0, buffer.Length))) > 0
                                    outputStream.Write(buffer, 0, read)
                                End While
                            End Using
                        End Using
                    End If
                Next
                isExtractSuccessful = True
                Console.WriteLine("文件解压缩成功,密码正确,密码为:" & password)
                Exit For ' 找到密码后退出循环
            End Using
        Catch ex As Exception
            ' 忽略错误,继续尝试下一个密码
        End Try
    Next

    If Not isExtractSuccessful Then
        Console.WriteLine("所有密码尝试完毕,未找到正确密码。")
    End If

    Console.ReadLine()
End Sub

Private Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
    target = value
    Return value
End Function

End Module

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

易软科技(河源)有限公司

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值