/// <summary> /// Check if 2 Files are updated for one way synchronisation /// </summary> /// <param name="sfi">source file</param> /// <param name="dfi">destination file</param> /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param> /// <returns>true if the files are not updated</returns> public static bool CompareFiles_OneWay(Delimon.Win32.IO.FileInfo sfi, Delimon.Win32.IO.FileInfo dfi, Func<bool> interruptChecker) { bool d = !dfi.Exists || sfi.LastWriteTime > dfi.LastWriteTime || (sfi.LastWriteTime < dfi.LastWriteTime && !Helper.FilesAreEqual(sfi, dfi, interruptChecker)); return !dfi.Exists || sfi.LastWriteTime > dfi.LastWriteTime || (sfi.LastWriteTime < dfi.LastWriteTime && !Helper.FilesAreEqual(sfi, dfi, interruptChecker)); }
/// <summary> /// Compare Files Byte for Byte /// </summary> /// <param name="first"></param> /// <param name="second"></param> /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param> /// <returns></returns> public static bool FilesAreEqual(Delimon.Win32.IO.FileInfo first, Delimon.Win32.IO.FileInfo second, Func<bool> interruptChecker) { if (first.Length != second.Length) return false; using (FileStream fs1 = first.OpenRead()) using (FileStream fs2 = second.OpenRead()) { for (int i = 0; i < first.Length; i++) { if (fs1.ReadByte() != fs2.ReadByte()) return false; interruptChecker(); } } return true; }
public DelimonFileInfoWrapper(Delimon.Win32.IO.FileInfo instance) { _instance = instance; }
public DelimonDirectoryInfoWrapper(Delimon.Win32.IO.DirectoryInfo instance) : this(new MyRecursionHelpers(new DelimonHelpersWrapper()), instance) { }
/* * Checks the file extension and calls the corresponding parser. * Gets the results returned from the parser and passes it to the engine. * Passes the results to the Database * * fInfo: Incoming FileInfo object to be processed * parentIsArchive: Whether or not the file is in an archive * returns: an int[] with the results from the call to the engine (results[0] = Count, results[1] = RetCode) */ public static int[][] ProcessNonArchive(Delimon.Win32.IO.FileInfo fInfo, bool parentIsArchive) { int[][] results = { new int[5], new int[9] }; string ext = Path.GetExtension(fInfo.FullName); ScanData returnedData; CreditData ccReturnedData; if (ext.CompareTo(".txt") == 0 || ext.CompareTo(".csv") == 0) { try { StreamReader textFile = new StreamReader(fInfo.FullName); string text = textFile.ReadToEnd(); textFile.Close(); if (MainForm.socialSecurityMode) { returnedData = Engine.ScanForSocialSecurity(text); if (returnedData.RetCode > 0) { if (parentIsArchive) { results[0][0] = returnedData.Count; results[0][1]= returnedData.RetCode; results[0][2] = (int)returnedData.Priority; results[0][3]= returnedData.Pattern_D9; results[0][4]= returnedData.Pattern_D3D2D4; } else { //Database entry goes here. //WriteToLogFile("Detected: " + fInfo.FullName + " Priority: " + returnedData.Priority); Database.AddToTableScanned(fInfo.Name, fInfo.FullName, returnedData); try { mainUIForm.lblItemsFound.BeginInvoke(new MainForm.InvokeDelegateFound(mainUIForm.UpdateLblItemsFound), new object[] { numFound++ }); } catch (InvalidOperationException) { } } } } if (MainForm.creditCardMode) { ccReturnedData = Engine.ScanForCreditCard(text); if (ccReturnedData.RetCode > 0) { if (parentIsArchive) { results[1][0] = ccReturnedData.Count; results[1][1] = ccReturnedData.RetCode; results[1][2] = (int)ccReturnedData.Priority; results[1][3] = ccReturnedData.VisaCount; results[1][4] = ccReturnedData.MC_Count; results[1][5] = ccReturnedData.AmexCount; results[1][6] = ccReturnedData.DisCount; results[1][7] = ccReturnedData.DinnCount; results[1][8] = ccReturnedData.JCB_Count; } else { //Database entry goes here. //WriteToLogFile("Detected: " + fInfo.FullName + " Priority: " +ccReturnedData.Priority); Database.AddToTableCreditCard(fInfo.Name, fInfo.FullName, ccReturnedData); try { mainUIForm.lblItemsFound.BeginInvoke(new MainForm.InvokeDelegateFound(mainUIForm.UpdateLblItemsFound), new object[] { numFound++ }); } catch (InvalidOperationException) { } } } } } catch (UnauthorizedAccessException u) { //File is encrypted: Add entry to Uncsannable table with reason: encrypted. Database.AddToTableUnScannable(fInfo.Name, fInfo.FullName, Environment.UserName, u.ToString()); } catch (Exception e) { Database.AddToTableUnScannable(fInfo.Name, fInfo.FullName, Environment.UserName, e.ToString()); } } else if (ext.CompareTo(".rtf") == 0) { try { RichTextBox rtb = new RichTextBox(); rtb.Rtf = System.IO.File.ReadAllText(fInfo.FullName); string text = rtb.Text; if (MainForm.socialSecurityMode) { returnedData = Engine.ScanForSocialSecurity(text); if (returnedData.RetCode > 0) { if (parentIsArchive) { results[0][0] = returnedData.Count; results[0][1] = returnedData.RetCode; results[0][2] = (int)returnedData.Priority; results[0][3] = returnedData.Pattern_D9; results[0][4] = returnedData.Pattern_D3D2D4; } else { //Database entry //WriteToLogFile("Detected: " + fInfo.FullName + " Priority: " + returnedData.Priority); Database.AddToTableScanned(fInfo.Name, fInfo.FullName, returnedData); try { mainUIForm.lblItemsFound.BeginInvoke(new MainForm.InvokeDelegateFound(mainUIForm.UpdateLblItemsFound), new object[] { numFound++ }); } catch (InvalidOperationException) { } } } if (MainForm.creditCardMode) { ccReturnedData = Engine.ScanForCreditCard(text); if (returnedData.RetCode > 0) { if (parentIsArchive) { results[1][0] = ccReturnedData.Count; results[1][1] = ccReturnedData.RetCode; results[1][2] = (int)ccReturnedData.Priority; results[1][3] = ccReturnedData.VisaCount; results[1][4] = ccReturnedData.MC_Count; results[1][5] = ccReturnedData.AmexCount; results[1][6] = ccReturnedData.DisCount; results[1][7] = ccReturnedData.DinnCount; results[1][8] = ccReturnedData.JCB_Count; } else { //Database entry //WriteToLogFile("Detected: " + fInfo.FullName + " Priority: " + returnedData.Priority); Database.AddToTableCreditCard(fInfo.Name, fInfo.FullName, ccReturnedData); try { mainUIForm.lblItemsFound.BeginInvoke(new MainForm.InvokeDelegateFound(mainUIForm.UpdateLblItemsFound), new object[] { numFound++ }); } catch (InvalidOperationException) { } } } } } } catch (UnauthorizedAccessException u) { //File is encrypted: Add entry to Uncsannable table with reason: encrypted. Database.AddToTableUnScannable(fInfo.Name, fInfo.FullName, Environment.UserName, u.ToString()); } catch (Exception e) { //Console.WriteLine(e.Message); Database.AddToTableUnScannable(fInfo.Name, fInfo.FullName, Environment.UserName, e.ToString()); } } else if (ext.CompareTo(".pdf") == 0) { try { string text = PDFParser.Parser.ParsePDFtoString(fInfo.FullName); if (MainForm.socialSecurityMode) { returnedData = Engine.ScanForSocialSecurity(text); if (returnedData.RetCode > 0) { if (parentIsArchive) { results[0][0] = returnedData.Count; results[0][1] = returnedData.RetCode; results[0][2] = (int)returnedData.Priority; results[0][3] = returnedData.Pattern_D9; results[0][4] = returnedData.Pattern_D3D2D4; } else { //Database entry //WriteToLog(fi.Name, fi.FullName, retCode.ToString(), count); Database.AddToTableScanned(fInfo.Name, fInfo.FullName, returnedData); } } if (MainForm.creditCardMode) { ccReturnedData = Engine.ScanForCreditCard(text); if (returnedData.RetCode > 0) { if (parentIsArchive) { results[1][0] = ccReturnedData.Count; results[1][1] = ccReturnedData.RetCode; results[1][2] = (int)ccReturnedData.Priority; results[1][3] = ccReturnedData.VisaCount; results[1][4] = ccReturnedData.MC_Count; results[1][5] = ccReturnedData.AmexCount; results[1][6] = ccReturnedData.DisCount; results[1][7] = ccReturnedData.DinnCount; results[1][8] = ccReturnedData.JCB_Count; } else { //Database entry //WriteToLog(fi.Name, fi.FullName, retCode.ToString(), count); Database.AddToTableScanned(fInfo.Name, fInfo.FullName, returnedData); try { mainUIForm.lblItemsFound.BeginInvoke(new MainForm.InvokeDelegateFound(mainUIForm.UpdateLblItemsFound), new object[] { numFound++ }); } catch (InvalidOperationException) { } } } } } } catch (UnauthorizedAccessException u) { //File is encrypted: Add entry to Uncsannable table with reason: encrypted. Database.AddToTableUnScannable(fInfo.Name, fInfo.FullName, Environment.UserName, u.ToString()); } catch (Exception e) { //Console.WriteLine(e.Message); Database.AddToTableUnScannable(fInfo.Name, fInfo.FullName, Environment.UserName, e.ToString()); } } else if (ext.CompareTo(".doc") == 0 || ext.CompareTo(".xls") == 0 || ext.CompareTo(".ppt") == 0) { try { TextReader reader = new FilterReader(fInfo.FullName); String text = ""; using (reader) { text = reader.ReadToEnd(); } if (MainForm.socialSecurityMode) { returnedData = Engine.ScanForSocialSecurity(text); if (returnedData.RetCode > 0) { if (parentIsArchive) { results[0][0] = returnedData.Count; results[0][1] = returnedData.RetCode; results[0][2] = (int)returnedData.Priority; results[0][3] = returnedData.Pattern_D9; results[0][4] = returnedData.Pattern_D3D2D4; } else { //Database entry //WriteToLogFile("Detected: " + fInfo.FullName + " Priority: " + returnedData.Priority); Database.AddToTableScanned(fInfo.Name, fInfo.FullName, returnedData); try { mainUIForm.lblItemsFound.BeginInvoke(new MainForm.InvokeDelegateFound(mainUIForm.UpdateLblItemsFound), new object[] { numFound++ }); } catch (InvalidOperationException) { } } } } if (MainForm.creditCardMode) { ccReturnedData = Engine.ScanForCreditCard(text); if (ccReturnedData.RetCode > 0) { if (parentIsArchive) { results[1][0] = ccReturnedData.Count; results[1][1] = ccReturnedData.RetCode; results[1][2] = (int)ccReturnedData.Priority; results[1][3] = ccReturnedData.VisaCount; results[1][4] = ccReturnedData.MC_Count; results[1][5] = ccReturnedData.AmexCount; results[1][6] = ccReturnedData.DisCount; results[1][7] = ccReturnedData.DinnCount; results[1][8] = ccReturnedData.JCB_Count; } else { //Database entry Database.AddToTableCreditCard(fInfo.Name, fInfo.FullName, ccReturnedData); try { mainUIForm.lblItemsFound.BeginInvoke(new MainForm.InvokeDelegateFound(mainUIForm.UpdateLblItemsFound), new object[] { numFound++ }); } catch (InvalidOperationException) { } } } } } catch (UnauthorizedAccessException u) { //File is encrypted: Add entry to Uncsannable table with reason: encrypted. Database.AddToTableUnScannable(fInfo.Name, fInfo.FullName, Environment.UserName, u.ToString()); } catch (Exception e) { //Console.WriteLine(e.Message); Database.AddToTableUnScannable(fInfo.Name, fInfo.FullName, Environment.UserName, e.ToString()); } } else if (ext.CompareTo(".docx") == 0 || ext.CompareTo(".xlsx") == 0 || ext.CompareTo(".pptx") == 0 || ext.CompareTo(".odt") == 0 || ext.CompareTo(".ods") == 0 || ext.CompareTo(".odp") == 0) { try { String text = OfficeParser.Parser.Parse(fInfo.FullName, ext); if (text != null) { if (MainForm.socialSecurityMode) { returnedData = Engine.ScanForSocialSecurity(text); if (returnedData.RetCode > 0) { if (parentIsArchive) { results[0][0] = returnedData.Count; results[0][1] = returnedData.RetCode; results[0][2] = (int)returnedData.Priority; results[0][3] = returnedData.Pattern_D9; results[0][4] = returnedData.Pattern_D3D2D4; } else { //Database entry //WriteToLogFile("Detected: " + fInfo.FullName + " Priority: " + returnedData.Priority); Database.AddToTableScanned(fInfo.Name, fInfo.FullName, returnedData); try { mainUIForm.lblItemsFound.BeginInvoke(new MainForm.InvokeDelegateFound(mainUIForm.UpdateLblItemsFound), new object[] { numFound++ }); } catch (InvalidOperationException) { } } } } if (MainForm.creditCardMode) { ccReturnedData = Engine.ScanForCreditCard(text); if (ccReturnedData.RetCode > 0) { if (parentIsArchive) { results[1][0] = ccReturnedData.Count; results[1][1] = ccReturnedData.RetCode; results[1][2] = (int)ccReturnedData.Priority; results[1][3] = ccReturnedData.VisaCount; results[1][4] = ccReturnedData.MC_Count; results[1][5] = ccReturnedData.AmexCount; results[1][6] = ccReturnedData.DisCount; results[1][7] = ccReturnedData.DinnCount; results[1][8] = ccReturnedData.JCB_Count; } else { //Database entry Database.AddToTableCreditCard(fInfo.Name, fInfo.FullName, ccReturnedData); try { mainUIForm.lblItemsFound.BeginInvoke(new MainForm.InvokeDelegateFound(mainUIForm.UpdateLblItemsFound), new object[] { numFound++ }); } catch (InvalidOperationException) { } } } } } } catch (UnauthorizedAccessException u) { //File is encrypted: Add entry to Uncsannable table with reason: encrypted. Database.AddToTableUnScannable(fInfo.Name, fInfo.FullName, Environment.UserName, u.ToString()); } catch (Exception e) { //Console.WriteLine(e.Message); Database.AddToTableUnScannable(fInfo.Name, fInfo.FullName, Environment.UserName, e.ToString()); } } else if (ext.CompareTo(".xml") == 0) { if(fInfo.Name.Equals("iTunes Music Library.xml")) return results; try { String text = XMLParser.Parser.ParseXMLtoString(fInfo.FullName); if (String.IsNullOrEmpty(text)) { //Log to Unscannable table. } if (MainForm.socialSecurityMode) { returnedData = Engine.ScanForSocialSecurity(text); if (returnedData.RetCode > 0) { if (parentIsArchive) { results[0][0] = returnedData.Count; results[0][1] = returnedData.RetCode; results[0][2] = (int)returnedData.Priority; results[0][3] = returnedData.Pattern_D9; results[0][4] = returnedData.Pattern_D3D2D4; } else { //Database entry //WriteToLogFile("Detected: " + fInfo.FullName + " Priority: " + returnedData.Priority); Database.AddToTableScanned(fInfo.Name, fInfo.FullName, returnedData); try { mainUIForm.lblItemsFound.BeginInvoke(new MainForm.InvokeDelegateFound(mainUIForm.UpdateLblItemsFound), new object[] { numFound++ }); } catch (InvalidOperationException) { } } } } if (MainForm.creditCardMode) { ccReturnedData = Engine.ScanForCreditCard(text); if (ccReturnedData.RetCode > 0) { if (parentIsArchive) { results[1][0] = ccReturnedData.Count; results[1][1] = ccReturnedData.RetCode; results[1][2] = (int)ccReturnedData.Priority; results[1][3] = ccReturnedData.VisaCount; results[1][4] = ccReturnedData.MC_Count; results[1][5] = ccReturnedData.AmexCount; results[1][6] = ccReturnedData.DisCount; results[1][7] = ccReturnedData.DinnCount; results[1][8] = ccReturnedData.JCB_Count; } else { //Database entry Database.AddToTableCreditCard(fInfo.Name, fInfo.FullName, ccReturnedData); try { mainUIForm.lblItemsFound.BeginInvoke(new MainForm.InvokeDelegateFound(mainUIForm.UpdateLblItemsFound), new object[] { numFound++ }); } catch (InvalidOperationException) { } } } } } catch (UnauthorizedAccessException u) { //File is encrypted: Add entry to Uncsannable table with reason: encrypted. Database.AddToTableUnScannable(fInfo.Name, fInfo.FullName, Environment.UserName, u.ToString()); } catch (Exception e) { //Console.WriteLine(e.Message); Database.AddToTableUnScannable(fInfo.Name, fInfo.FullName, Environment.UserName, e.ToString()); } } else if (ext.CompareTo(".pst") == 0) { try { com.pff.PSTFile pstFile = new com.pff.PSTFile(fInfo.FullName); String text = pstFile.processFolder(pstFile.getRootFolder()); com.pff.PSTFolder folder = pstFile.getRootFolder(); processFolder(folder); // Process the main folder, once we hit an email we will scan that email /* if (MainForm.socialSecurityMode) { returnedData = Engine.ScanForSocialSecurity(text); if (returnedData.RetCode > 0) { if (parentIsArchive) { results[0][0] = returnedData.Count; results[0][1] = returnedData.RetCode; results[0][2] = (int)returnedData.Priority; results[0][3] = returnedData.Pattern_D9; results[0][4] = returnedData.Pattern_D3D2D4; } //Database entry //WriteToLogFile("Detected: " + fInfo.FullName + " Priority: " + returnedData.Priority); Database.AddToTableScanned(fInfo.Name, fInfo.FullName, returnedData); try { mainUIForm.lblItemsFound.BeginInvoke(new MainForm.InvokeDelegateFound(mainUIForm.UpdateLblItemsFound), new object[] { numFound++ }); } catch (InvalidOperationException) { } } } if (MainForm.creditCardMode) { ccReturnedData = Engine.ScanForCreditCard(text); if (ccReturnedData.RetCode > 0) { if (parentIsArchive) { results[1][0] = ccReturnedData.Count; results[1][1] = ccReturnedData.RetCode; results[1][2] = (int)ccReturnedData.Priority; results[1][3] = ccReturnedData.VisaCount; results[1][4] = ccReturnedData.MC_Count; results[1][5] = ccReturnedData.AmexCount; results[1][6] = ccReturnedData.DisCount; results[1][7] = ccReturnedData.DinnCount; results[1][8] = ccReturnedData.JCB_Count; } //Database entry Database.AddToTableCreditCard(fInfo.Name, fInfo.FullName, ccReturnedData); try { mainUIForm.lblItemsFound.BeginInvoke(new MainForm.InvokeDelegateFound(mainUIForm.UpdateLblItemsFound), new object[] { numFound++ }); } catch (InvalidOperationException) { } } } */ } catch (UnauthorizedAccessException u) { //File is encrypted: Add entry to Uncsannable table with reason: encrypted. Database.AddToTableUnScannable(fInfo.Name, fInfo.FullName, Environment.UserName, u.ToString()); } catch (Exception e) { //Console.WriteLine(e.Message); Database.AddToTableUnScannable(fInfo.Name, fInfo.FullName, Environment.UserName, e.ToString()); } } return results; }
/* * Determines if a file is an archive or not. If it's an archive it is extracted to the System temp forlder for processing. * If it is not an archive it is passed to ProcessNonArchive. * * fInfo: Incoming FileInfo object to be processed * returns: void */ public static void ProcessFile(Delimon.Win32.IO.FileInfo fInfo) { string extention = Path.GetExtension(fInfo.FullName); if (extention == null) extention = ""; if (IsArchive(extention)) { //extract code SevenZipExtractor extractor = null; try { //path to the systems temporary folder String tempFolderPath = Path.GetTempPath(); tempFolderPath += "temp_dir\\"; //create a directory to dump everything into inside the temp folder Directory.CreateDirectory(tempFolderPath); //set the path of the 7z.dll (it needs to be in the debug folder) SevenZipExtractor.SetLibraryPath("7z.dll"); extractor = new SevenZipExtractor(fInfo.FullName); //Extract the entire file extractor.ExtractArchive(tempFolderPath); extractor.Dispose(); bool arcs = true; while (arcs) { arcs = false; // traverse files string[] fileEntries = Directory.GetFiles(tempFolderPath, "*.*", SearchOption.AllDirectories); foreach (string fileName in fileEntries) { //Console.WriteLine("IN ARCHIVE: " + fileName); FileInfo archive = new FileInfo(fileName); if (IsArchive(archive.Extension.ToString())) { arcs = true; extractor = new SevenZipExtractor(fileName); extractor.ExtractArchive(tempFolderPath); File.Delete(fileName); } } } int[][] totals = {new int[5], new int[9]}; //totals[0] count; totals[1] results; string[] fileEntries2 = Directory.GetFiles(tempFolderPath, "*.*", SearchOption.AllDirectories); foreach (string fileName in fileEntries2) { int[][] results = ProcessNonArchive(new Delimon.Win32.IO.FileInfo(fileName), true); if (MainForm.socialSecurityMode) { totals[0][0] += results[0][0]; if (results[0][1] > totals[0][1]) totals[0][1] = results[0][1]; } if (MainForm.creditCardMode) { totals[1][0] += results[1][0]; if (results[1][1] > totals[1][1]) totals[1][1] = results[1][1]; } } //Count how many files in archive //int count = Directory.GetFiles(tempFolderPath, "*.*", SearchOption.AllDirectories).Length; //delete the temporary directory we created at the beginning Directory.Delete(tempFolderPath, true); if (totals[0][1] > 0) { //WriteToLogFile("Detected: " + fInfo.FullName + " Priority: " + (ScanData.Code)totals[1]); if (MainForm.socialSecurityMode) { ScanData returnedData = new ScanData(totals[0][0], totals[0][1], totals[0][3], totals[0][4]); Database.AddToTableScanned(fInfo.Name, fInfo.FullName, returnedData); try { mainUIForm.lblItemsFound.BeginInvoke(new MainForm.InvokeDelegateFound(mainUIForm.UpdateLblItemsFound), new object[] { numFound++ }); } catch (InvalidOperationException) { } } if (MainForm.creditCardMode) { CreditData ccReturnedData = new CreditData(totals[1][0], totals[1][1], totals[1][3], totals[1][4], totals[1][5], totals[1][6], totals[1][7], totals[1][8]); Database.AddToTableCreditCard(fInfo.Name, fInfo.FullName, ccReturnedData); try { mainUIForm.lblItemsFound.BeginInvoke(new MainForm.InvokeDelegateFound(mainUIForm.UpdateLblItemsFound), new object[] { numFound++ }); } catch (InvalidOperationException) { } } } } catch (Exception e) { //get rid of the object because it is unmanaged extractor.Dispose(); Console.WriteLine(e.Message); } } else { int[][] ignore = ProcessNonArchive(fInfo, false); } }