Skip to content

Commit

Permalink
Output issues
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jeanluc162 committed May 2, 2020
1 parent dd8a48b commit 612e044
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The programm will either tell you the password or inform you that no password ha

# How it works

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.
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.
2. The program creates one copy of the ZIP-File for each thread in a temporary folder.
3. The program starts the amount of Threads it wants to use.
4. The program stops when a password is found or all combinations have been tried.
Expand Down
35 changes: 27 additions & 8 deletions ZipCrackNetCore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ namespace ZipCrackNetCore
{
internal class Program
{
private static ConcurrentQueue<String> Passwords = new ConcurrentQueue<string>();
private static ConcurrentQueue<String> UnsuccessfullTries;
private static ConcurrentQueue<String> Passwords = new ConcurrentQueue<String>();
private static CancellationTokenSource CancellationToken = new CancellationTokenSource();
private static String TempPath = "";
private static Int32 ThreadCount = (Int32)(Environment.ProcessorCount * 1.3);
private static Int32 ThreadCount = Environment.ProcessorCount;
private static Int32 MinLength = 0;
private static Int32 MaxLength = 0;
private static String ZipPath = "";
private static Boolean OutputTries = false;

/// <summary>
/// Main Function
Expand Down Expand Up @@ -85,7 +85,11 @@ static void Main(string[] args)
}
try
{
if (args[4].Trim().ToLower() == "output") OutputTries = true;
if (args[4].Trim().ToLower() == "output")
{
UnsuccessfullTries = new ConcurrentQueue<String>();
new Thread(() => OutputUnsuccessfullTries()).Start();
}
}
catch { }

Expand Down Expand Up @@ -155,6 +159,21 @@ private static void GeneratorThread(Int32 MinLength, Int32 MaxLength, String Cha
}
}
}
private static void OutputUnsuccessfullTries()
{
String LastTry;
while (!CancellationToken.Token.IsCancellationRequested)
{
if(UnsuccessfullTries.TryDequeue(out LastTry))
{
Console.WriteLine(LastTry);
}
else
{
Thread.Sleep(5);
}
}
}
private static void PasswordThread(String Filename)
{
using (ZipFile TestZip = ZipFile.Read(Filename))
Expand All @@ -168,24 +187,24 @@ private static void PasswordThread(String Filename)
String PasswordToTry;
if(Passwords.TryDequeue(out PasswordToTry))
{
if(OutputTries) Console.WriteLine(PasswordToTry);
UnsuccessfullTries?.Enqueue(PasswordToTry);
using (MemoryStream tmpms = new MemoryStream())
{
try
{
ToTestAgainst.ExtractWithPassword(tmpms, PasswordToTry);
Console.WriteLine("Found Password: " + PasswordToTry);
CancellationToken.Cancel();
Thread.Sleep(10);
Passwords.Clear();
UnsuccessfullTries?.Clear();
Console.WriteLine("Found Password: " + PasswordToTry);
Environment.Exit(0);
}
catch { }
}
}
else
{
Thread.Sleep(2);
Thread.Sleep(10);
}
}
}
Expand Down

0 comments on commit 612e044

Please sign in to comment.