Skip to content

Commit 612e044

Browse files
committed
Output issues
Solved an issue where the output continues for a while after a password has been found by queueing all tries into a FIFO-List and using a seperate thread to Dequeue and output them to the console. Should also improve performance.
1 parent dd8a48b commit 612e044

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The programm will either tell you the password or inform you that no password ha
1919

2020
# How it works
2121

22-
1. The program figures out how many Threads to use. By default, the amount is equal to the amount of logical cores available times 1.5 plus one additional Thread for creating the combinations.
22+
1. The program figures out how many Threads to use. By default, the amount is equal to the amount of logical cores available plus one additional Thread for creating the combinations and (optional) one for outputing the tried passwords to the console.
2323
2. The program creates one copy of the ZIP-File for each thread in a temporary folder.
2424
3. The program starts the amount of Threads it wants to use.
2525
4. The program stops when a password is found or all combinations have been tried.

ZipCrackNetCore/Program.cs

+27-8
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ namespace ZipCrackNetCore
1010
{
1111
internal class Program
1212
{
13-
private static ConcurrentQueue<String> Passwords = new ConcurrentQueue<string>();
13+
private static ConcurrentQueue<String> UnsuccessfullTries;
14+
private static ConcurrentQueue<String> Passwords = new ConcurrentQueue<String>();
1415
private static CancellationTokenSource CancellationToken = new CancellationTokenSource();
1516
private static String TempPath = "";
16-
private static Int32 ThreadCount = (Int32)(Environment.ProcessorCount * 1.3);
17+
private static Int32 ThreadCount = Environment.ProcessorCount;
1718
private static Int32 MinLength = 0;
1819
private static Int32 MaxLength = 0;
1920
private static String ZipPath = "";
20-
private static Boolean OutputTries = false;
2121

2222
/// <summary>
2323
/// Main Function
@@ -85,7 +85,11 @@ static void Main(string[] args)
8585
}
8686
try
8787
{
88-
if (args[4].Trim().ToLower() == "output") OutputTries = true;
88+
if (args[4].Trim().ToLower() == "output")
89+
{
90+
UnsuccessfullTries = new ConcurrentQueue<String>();
91+
new Thread(() => OutputUnsuccessfullTries()).Start();
92+
}
8993
}
9094
catch { }
9195

@@ -155,6 +159,21 @@ private static void GeneratorThread(Int32 MinLength, Int32 MaxLength, String Cha
155159
}
156160
}
157161
}
162+
private static void OutputUnsuccessfullTries()
163+
{
164+
String LastTry;
165+
while (!CancellationToken.Token.IsCancellationRequested)
166+
{
167+
if(UnsuccessfullTries.TryDequeue(out LastTry))
168+
{
169+
Console.WriteLine(LastTry);
170+
}
171+
else
172+
{
173+
Thread.Sleep(5);
174+
}
175+
}
176+
}
158177
private static void PasswordThread(String Filename)
159178
{
160179
using (ZipFile TestZip = ZipFile.Read(Filename))
@@ -168,24 +187,24 @@ private static void PasswordThread(String Filename)
168187
String PasswordToTry;
169188
if(Passwords.TryDequeue(out PasswordToTry))
170189
{
171-
if(OutputTries) Console.WriteLine(PasswordToTry);
190+
UnsuccessfullTries?.Enqueue(PasswordToTry);
172191
using (MemoryStream tmpms = new MemoryStream())
173192
{
174193
try
175194
{
176195
ToTestAgainst.ExtractWithPassword(tmpms, PasswordToTry);
177-
Console.WriteLine("Found Password: " + PasswordToTry);
178196
CancellationToken.Cancel();
179-
Thread.Sleep(10);
180197
Passwords.Clear();
198+
UnsuccessfullTries?.Clear();
199+
Console.WriteLine("Found Password: " + PasswordToTry);
181200
Environment.Exit(0);
182201
}
183202
catch { }
184203
}
185204
}
186205
else
187206
{
188-
Thread.Sleep(2);
207+
Thread.Sleep(10);
189208
}
190209
}
191210
}

0 commit comments

Comments
 (0)