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