public override bool Run() { ICheckPassword check = (ICheckPassword)this.Payload; if (!check.PreRun()) { check.PostRun(); return(false); } try { if (!WordListFile.Exists) { return(false); } int readBlock = Math.Max(1, ReadBlock); int threads = Math.Max(1, Threads); bool save = SaveState; using (StreamReader reader = new StreamReader(WordListFile.FullName)) { string[] toCrack = new string[readBlock]; int index = 0; string line; while ((line = reader.ReadLine()) != null) { // Fill toCrack[index] = line; index++; if (index == readBlock) { // Crack if (Crack(toCrack, 0, index, threads, check, check.AllowMultipleOk)) { index = 0; if (!check.AllowMultipleOk) { break; } } else { index = 0; } if (save) { // Write position } } } if (index != 0) { // Sobras if (Crack(toCrack, 0, index, threads, check, check.AllowMultipleOk)) { index = 0; } if (save) { // End } } } } catch (Exception e) { throw (e); } finally { check.PostRun(); } return(true); }
public override bool Run() { ICheckPassword check = (ICheckPassword)this.Payload; if (!check.PreRun()) { check.PostRun(); return(false); } FileStream stream = null; bool found = false; string tempFile = null; try { if (!WordListFile.Exists) { return(false); } int readBlock = Math.Max(1, ReadBlock); int threads = Math.Max(1, Threads); stream = File.OpenRead(WordListFile.FullName); if (FileHelper.DetectFileFormat(stream, true, true) == FileHelper.EFileFormat.Gzip) { WriteInfo("Decompress gzip wordlist"); WriteInfo("Compressed size", StringHelper.Convert2KbWithBytes(stream.Length), ConsoleColor.Green); stream.Close(); stream.Dispose(); using (FileStream streamR = File.OpenRead(WordListFile.FullName)) using (GZipStream gz = new GZipStream(streamR, CompressionMode.Decompress)) { // decompress tempFile = Path.GetTempFileName(); stream = File.Open(tempFile, FileMode.OpenOrCreate, FileAccess.ReadWrite); gz.CopyTo(stream); stream.Seek(0, SeekOrigin.Begin); } WriteInfo("Decompressed size", StringHelper.Convert2KbWithBytes(stream.Length), ConsoleColor.Green); } using (StreamLineReader reader = new StreamLineReader(stream)) { WriteInfo("Start counting file"); int hay = reader.GetCount(StartAtLine); WriteInfo("Total lines", hay.ToString(), ConsoleColor.Green); StartProgress(Math.Max(0, hay - StartAtLine)); string[] toCrack = new string[readBlock]; int index = 0; string line; while ((line = reader.ReadLine()) != null) { // Fill toCrack[index] = line; index++; if (index == readBlock) { // Crack if (Crack(toCrack, 0, index, threads, check)) { index = 0; found = true; break; } else { index = 0; } if (SaveState) { StartAtLine = reader.CurrentLine; CopyPropertiesToActiveModule("StartAtLine"); } WriteProgress(reader.CurrentLine); } } if (index != 0) { // Sobras if (Crack(toCrack, 0, index, threads, check)) { index = 0; found = true; } if (SaveState) { StartAtLine = reader.CurrentLine; CopyPropertiesToActiveModule("StartAtLine"); } WriteProgress(reader.CurrentLine); } } } catch (Exception e) { throw (e); } finally { if (stream != null) { stream.Close(); stream.Dispose(); } if (tempFile != null) { File.Delete(tempFile); } EndProgress(); check.PostRun(); } return(found); }