From 211d0a49e99752cd3edea609763ab4e40b12afcc Mon Sep 17 00:00:00 2001 From: dawn-lc Date: Sun, 23 May 2021 00:39:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=9A=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConsoleExpandModule.cs | 82 ++++++++++++++++++++-------------- Main.cs | 22 ++++++--- Program.cs | 2 +- Properties/launchSettings.json | 3 +- 4 files changed, 68 insertions(+), 41 deletions(-) diff --git a/ConsoleExpandModule.cs b/ConsoleExpandModule.cs index 12f7305..dcc7743 100644 --- a/ConsoleExpandModule.cs +++ b/ConsoleExpandModule.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Threading; namespace module.dawnlc.me @@ -11,6 +10,7 @@ namespace module.dawnlc.me class ConsoleExpand : IDisposable { private bool isDisposed = false; + private bool isDisposing = false; private bool RenderCacheLock = false; /// /// Console 高 @@ -52,21 +52,29 @@ public ConsoleExpand() public void OutputCanvas() { - while (true) + while (!isDisposing) { RenderCacheLock = true; - IEnumerable Rendering = RenderCache1.Where(p => p != null); + List Rendering = new List(RenderCache1); foreach (var item in Rendering) { - Console.SetCursorPosition(0, item.Row); - Console.Write(new string(' ', Width)); - Console.SetCursorPosition(item.Col, item.Row); - Console.Write(item.ContentString); + if (item != null) + { + Console.SetCursorPosition(0, item.Row); + Console.Write(new string(' ', Width)); + Console.SetCursorPosition(item.Col, item.Row); + Console.Write(item.ContentString); + } + } - RenderCache1 = RenderCache1.Except(Rendering).ToList(); - RenderCache1 = RenderCache1.Union(RenderCache2).Where(p => p != null).ToList(); + Rendering.Clear(); + RenderCache1.Clear(); + + RenderCache1.AddRange(RenderCache2); RenderCacheLock = false; + RenderCache2.Clear(); + Thread.Sleep(32); } } @@ -75,22 +83,18 @@ public void Print(int Col, int Row, string Content) { try { - if (!string.IsNullOrWhiteSpace(Content)) + if (RenderCacheLock) { - if (RenderCacheLock) - { - RenderCache2.Add(new Content(Row, Col, Content)); - } - else - { - RenderCache1.Add(new Content(Row, Col, Content)); - } + RenderCache2.Add(new Content(Row, Col, Content)); + } + else + { + RenderCache1.Add(new Content(Row, Col, Content)); } - return; } catch (Exception) { - return; + //这里如果报错,肯定是破解速度过快.(跑完了7zip test并返回了结果只花了不到10毫秒) } } public void Close() @@ -108,23 +112,35 @@ void IDisposable.Dispose() } protected virtual void Dispose(bool disposing) { - RenderThread.Abort(); - RenderCacheLock = true; - RenderCache1 = RenderCache1.Union(RenderCache2).ToList(); - RenderCacheLock = false; - foreach (var item in RenderCache1) - { - Console.SetCursorPosition(0, item.Row); - Console.Write(new string(' ', Width)); - Console.SetCursorPosition(item.Col, item.Row); - Console.Write(item.ContentString); - } if (!isDisposed) { if (disposing) { - RenderCache2.Clear(); - RenderCache1.Clear(); + RenderThread.Abort(); + isDisposing = true; + + foreach (var item in RenderCache1) + { + if (item != null) + { + Console.SetCursorPosition(0, item.Row); + Console.Write(new string(' ', Width)); + Console.SetCursorPosition(item.Col, item.Row); + Console.Write(item.ContentString); + } + } + foreach (var item in RenderCache2) + { + if (item != null) + { + Console.SetCursorPosition(0, item.Row); + Console.Write(new string(' ', Width)); + Console.SetCursorPosition(item.Col, item.Row); + Console.Write(item.ContentString); + } + } + + isDisposing = false; } } isDisposed = true; // 标识此对象已释放 diff --git a/Main.cs b/Main.cs index 37b08fd..1c9ed1b 100644 --- a/Main.cs +++ b/Main.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; using System.IO; using module.dawnlc.me; +using System.Threading; namespace ArchivePasswordTestTool { @@ -371,6 +372,7 @@ private void MainProgram() if (ProgramParameter.ArchiveFile.Extension.ToLower().Contains("rar")) { Console.WriteLine("RAR格式压缩包!由于RAR专利问题需要调用完整版7Zip!"); + Console.WriteLine("本程序将会读取注册表中的7Zip安装路径,如果不想程序读取,请直接关闭本程序。"); Console.WriteLine("请确保已安装完整版7zip!(按任意键继续!)"); Console.ReadKey(); if (string.IsNullOrEmpty(ReadRegeditValue("SOFTWARE\\7-Zip", "Path").ToString())) @@ -386,8 +388,7 @@ private void MainProgram() } } - Dictionary> returnData = RunProgram(ProgramParameter.ArchiveDecryptionProgram, new string[] { "t", "\"" + ProgramParameter.ArchiveFile.FullName + "\"", "-p" }); - if (!returnData.TryGetValue("Output", out List Output)) + if (!RunProgram(ProgramParameter.ArchiveDecryptionProgram, new string[] { "t", "\"" + ProgramParameter.ArchiveFile.FullName + "\"", "-p" }).TryGetValue("Output", out List Output)) { Console.WriteLine("压缩包损坏 或 不是支持的压缩包!(按任意键退出)"); Console.ReadKey(); @@ -433,10 +434,15 @@ private void MainProgram() { Parallel.ForEach(Dictionary, new ParallelOptions() { MaxDegreeOfParallelism = ProgramParameter.DecryptArchiveThreadCount }, (i, loopState) => { ConsoleCanvas.Print(0, i.Thread, "[" + i.Thread + "] 密码: [" + i.PassWord + "] 测试中..."); - returnData = RunProgram(ProgramParameter.ArchiveDecryptionProgram, new string[] { "t", "\"" + ProgramParameter.ArchiveFile.FullName + "\"", "-p\"" + i.PassWord + "\"" }); - if (returnData.ContainsKey("Output")) + + /* + Dictionary> returnDataA = new Dictionary> { ["Output"] = new List { "test" } }; + Thread.Sleep(random.Next(2,5)); + */ + + if (RunProgram(ProgramParameter.ArchiveDecryptionProgram, new string[] { "t", "\"" + ProgramParameter.ArchiveFile.FullName + "\"", "-p\"" + i.PassWord + "\"" }).TryGetValue("Output", out List OutputInfo)) { - if (returnData["Output"].Where(p => p != null && p.Contains("Everything is Ok")).Any()) + if (OutputInfo.Where(p => p != null && p.Contains("Everything is Ok")).Any()) { ProgramParameter.EncryptArchivePassword = i.PassWord; loopState.Stop(); @@ -447,9 +453,13 @@ private void MainProgram() ConsoleCanvas.Print(0, i.Thread, "[" + i.Thread + "] 密码: [" + i.PassWord + "] 错误!"); } } - + else + { + ConsoleCanvas.Print(0, i.Thread, "[" + i.Thread + "] 密码: [" + i.PassWord + "] 错误!"); + } }); } + sw.Stop(); Console.SetCursorPosition(0, ProgramParameter.DecryptArchiveThreadCount + 1); if (ProgramParameter.EncryptArchivePassword != null) diff --git a/Program.cs b/Program.cs index f68b861..05dd6d1 100644 --- a/Program.cs +++ b/Program.cs @@ -13,7 +13,7 @@ public class ProgramParameter { public static readonly string AppName = Assembly.GetExecutingAssembly().FullName.Substring(0, Assembly.GetExecutingAssembly().FullName.IndexOf(",")); public static readonly string AppPath = Environment.CurrentDirectory + "\\"; - public static readonly int[] Version = new int[] { 1, 0, 8 }; + public static readonly int[] Version = new int[] { 1, 0, 9 }; public static readonly string VersionType = "Release"; public static readonly string AppHomePage = "https://www.bilibili.com/read/cv6101558"; public static readonly string Developer = "dawn-lc"; diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json index 12c0fd8..ca32c54 100644 --- a/Properties/launchSettings.json +++ b/Properties/launchSettings.json @@ -1,7 +1,8 @@ { "profiles": { "ArchivePasswordTestTool": { - "commandName": "Project" + "commandName": "Project", + "commandLineArgs": "-D \"C:\\Users\\lc990\\Desktop\\字典破解\\工具 - 副本\\PasswordDictionary.txt\" -T 7 -F C:\\Users\\lc990\\Desktop\\字典破解\\空压缩包.7z" } } } \ No newline at end of file