public static void Determine_Parser(System.IO.FileInfo fi, uint level)
        {
            string ext = fi.Extension.ToString();
            if (ext.CompareTo(".txt") == 0)
            {
                try
                {
                    StreamReader textFile = new StreamReader(fi.FullName);
                    string text = textFile.ReadToEnd();
                    textFile.Close();
                   // MessageBox.Show(fi.FullName);
                    int retCode, count = 0;
                    retCode = UnsafeNativeMethod.ScanAnsi(text.ToCharArray(), text.Length, ref count);
                    if (retCode > 0)
                        WriteToLog(fi.Name, fi.FullName, retCode.ToString(), count);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            else if (ext.CompareTo(".rtf") == 0)
            {
                try
                {
                    RichTextBox rtb = new RichTextBox();
                    rtb.Rtf = System.IO.File.ReadAllText(fi.FullName);
                    string text = rtb.Text;
                    //Console.WriteLine(s);
                    int retCode, count = 0;
                    retCode = UnsafeNativeMethod.ScanAnsi(text.ToCharArray(), text.Length, ref count);
                    if (retCode > 0)
                        WriteToLog(fi.Name, fi.FullName, retCode.ToString(), count);
                    //Console.WriteLine("\t" + text);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            else if (ext.CompareTo(".pdf") == 0)
            {
                try
                {
                    String text = PDFParser.Parser.ParsePDFtoString(fi.FullName);
                    int retCode, count = 0;
                    retCode = UnsafeNativeMethod.ScanAnsi(text.ToCharArray(), text.Length, ref count);
                    if (retCode > 0)
                    WriteToLog(fi.Name, fi.FullName, retCode.ToString(), count);
                    //Console.WriteLine("\t" + text);
                }
                catch(Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            else if (ext.CompareTo(".doc") == 0 || ext.CompareTo(".xls") == 0 || ext.CompareTo(".ppt") == 0)
            {
                try
                {
                    TextReader reader = new FilterReader(fi.FullName);
                    String text = "";
                    using (reader) { text = reader.ReadToEnd(); }
                    int retCode, count = 0;
                    retCode = UnsafeNativeMethod.ScanAnsi(text.ToCharArray(), text.Length, ref count);
                    if (retCode > 0)
                        WriteToLog(fi.Name, fi.FullName, retCode.ToString(), count);
                    //Console.WriteLine("\t" + text);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            else if (ext.CompareTo(".docx") == 0)
            {
                try
                {
                    String text = OfficeParser.Parser.docxParser(fi.FullName);
                    if (text != null)
                    {
                        int retCode, count = 0;
                        retCode = UnsafeNativeMethod.ScanAnsi(text.ToCharArray(), text.Length, ref count);
                        if (retCode > 0)
                            WriteToLog(fi.Name, fi.FullName, retCode.ToString(), count);
                    }
                    //Console.WriteLine("\t" + text);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            else if (ext.CompareTo(".xlsx") == 0)
            {
                try
                {
                    String text = OfficeParser.Parser.xlsxParser(fi.FullName);
                    if (text != null)
                    {
                        int retCode, count = 0;
                        retCode = UnsafeNativeMethod.ScanAnsi(text.ToCharArray(), text.Length, ref count);
                        if (retCode > 0)
                            WriteToLog(fi.Name, fi.FullName, retCode.ToString(), count);
                        //Console.WriteLine("\t" + text);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            else if (ext.CompareTo(".pptx") == 0)
            {
                try
                {
                    String text = OfficeParser.Parser.pptxParser(fi.FullName);
                    if (text != null)
                    {
                        int retCode, count = 0;
                        retCode = UnsafeNativeMethod.ScanAnsi(text.ToCharArray(), text.Length, ref count);
                        if (retCode > 0)
                            WriteToLog(fi.Name, fi.FullName, retCode.ToString(), count);
                        //Console.WriteLine("\t" + text);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            else if (ext.CompareTo(".odt") == 0 || ext.CompareTo(".ods") == 0 || ext.CompareTo(".odp") == 0)
            {
                try
                {
                    String text = OfficeParser.Parser.openOfficeParser(fi.FullName);
                    if (text != null)
                    {
                        int retCode, count = 0;
                        retCode = UnsafeNativeMethod.ScanAnsi(text.ToCharArray(), text.Length, ref count);
                        if (retCode > 0)
                            WriteToLog(fi.Name, fi.FullName, retCode.ToString(), count);
                        //Console.WriteLine("\t" + text);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            else if (ext.CompareTo(".xml") == 0)
            {
                try
                {
                    String text = XMLParser.Parser.ParseXMLtoString(fi.FullName);
                    int retCode, count = 0;
                    retCode = UnsafeNativeMethod.ScanAnsi(text.ToCharArray(), text.Length, ref count);
                    if (retCode > 0)
                        WriteToLog(fi.Name, fi.FullName, retCode.ToString(), count);
                    //Console.WriteLine("\t" + text);
                }
                catch(Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            else if (ext.CompareTo(".pst") == 0)
            {

            }
            else if (ext.CompareTo(".zip") == 0 || ext.CompareTo(".7z") == 0 || ext.CompareTo(".xz") == 0 || ext.CompareTo(".bzip2") == 0 ||
                ext.CompareTo(".gzip") == 0 || ext.CompareTo(".tar") == 0 || ext.CompareTo(".wim") == 0 || ext.CompareTo(".arj") == 0 ||
                ext.CompareTo(".cab") == 0 || ext.CompareTo(".chm") == 0 || ext.CompareTo(".cpio") == 0 || ext.CompareTo(".cramfs") == 0 ||
                ext.CompareTo(".deb") == 0 || ext.CompareTo(".fat") == 0 || ext.CompareTo(".hfs") == 0 || ext.CompareTo(".iso") == 0 ||
                ext.CompareTo(".lzh") == 0 || ext.CompareTo(".lzma") == 0 || ext.CompareTo(".mbr") == 0 || ext.CompareTo(".msi") == 0 ||
                ext.CompareTo(".nsis") == 0 || ext.CompareTo(".ntfs") == 0 || ext.CompareTo(".rar") == 0 || ext.CompareTo(".rpm") == 0 ||
                ext.CompareTo(".squashfs") == 0 || ext.CompareTo(".udf") == 0 || ext.CompareTo(".vhd") == 0 || ext.CompareTo(".xar") == 0 ||
                ext.CompareTo(".z") == 0)
            {
                //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(fi.FullName);

                    //Extract the entire file
                    extractor.ExtractArchive(tempFolderPath);
                    extractor.Dispose();

                    //Count how many files in archive
                    int count = Directory.GetFiles(tempFolderPath, "*.*", SearchOption.AllDirectories).Length;

                    // traverse files
                    string[] fileEntries = Directory.GetFiles(tempFolderPath);
                    foreach (string fileName in fileEntries)
                    {
                        //Console.WriteLine("IN ARCHIVE: " + fileName);
                    }

                    //delete the temporary directory we created at the beginning
                    Directory.Delete(tempFolderPath, true);
                }
                catch (Exception e)
                {
                    //get rid of the object because it is unmanaged
                    extractor.Dispose();
                    Console.WriteLine(e.Message);
                }
            }
        }
        /// <summary>
        /// Returns true when the <paramref name="textToFind"/> is found in the
        /// <paramref name="fileName"/>
        /// </summary>
        /// <param name="fileName">The file to inspect</param>
        /// <param name="textToFind">The text to find</param>
        /// <param name="ignoreCase">Set to false to search case sensitive</param>
        /// <returns></returns>
        public bool FileContainsText(string fileName, string textToFind, bool ignoreCase = true)
        {
            using (var reader = new FilterReader(fileName))
            {
                var line = reader.ReadLine();
                if (string.IsNullOrEmpty(line))
                {
                    return(false);
                }

                if (ignoreCase)
                {
                    if (line.IndexOf(textToFind, StringComparison.InvariantCultureIgnoreCase) >= 0)
                    {
                        return(true);
                    }
                }
                else
                {
                    if (line.IndexOf(textToFind, StringComparison.InvariantCulture) >= 0)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #3
0
 /* Performs a image snapshop of the file before it is opened to use as a sample for
  * the A.I image comparison when attempting to detect any copies of the file. This is done
  * by first reading the contents of the actual file, using the NuGet package 'IFilterTextReader',
  * a C# TextReader that gets text from different file formats through the IFilter interface.
  * Using the reader, obtains all the text within the document and removing all new lines and indentations
  * to ensure each document is read the same. Then using a Bitmap, Font and Graphics objects to
  * draw the contents onto a Bitmap image. Finally, the Bitmap image is saved as a PNG to the
  * 'Samples' folder for future analysis if needed.
  *
  * A DISCLAIMER, 'IFilterTextReader' is under the The Code Project Open License (CPOL) 1.02.
  * My usage is in compliance with the license. All credits go to Kees van Spelde.
  * URL Link: https://github.com/Sicos1977/IFilterTextReader
  */
 public void SnapshotFile(String filePath)
 {
     try
     {
         TextReader reader = new FilterReader(filePath);
         using (reader)
         {
             var      text     = Regex.Replace(reader.ReadToEnd(), @"\t|\n|\r", "");
             Bitmap   bitmap   = new Bitmap(1, 1);
             Font     font     = new Font("Arial", 8, FontStyle.Regular, GraphicsUnit.Pixel);
             Graphics graphics = Graphics.FromImage(bitmap);
             int      width    = (int)graphics.MeasureString(text, font).Width;
             int      height   = (int)graphics.MeasureString(text, font).Height;
             bitmap   = new Bitmap(bitmap, new Size(width, height));
             graphics = Graphics.FromImage(bitmap);
             graphics.Clear(Color.White);
             graphics.SmoothingMode     = SmoothingMode.AntiAlias;
             graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
             graphics.DrawString(text, font, new SolidBrush(Color.FromArgb(0, 0, 0)), 0, 0);
             graphics.Flush();
             graphics.Dispose();
             bitmap.Save("C:\\Users\\" + utilities.Username() + "\\AppData\\Roaming\\Data Shield\\Samples\\" + filePath.Split('\\').Last() + ".png");
             bitmap.Dispose();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Example #4
0
        public async Task ProcessAsync(ICrawler crawler, PropertyBag propertyBag)
        {
            if (propertyBag.StatusCode != HttpStatusCode.OK)
            {
                return;
            }

            var extension = MapContentTypeToExtension(propertyBag.ContentType);

            if (extension.IsNullOrEmpty())
            {
                return;
            }

            propertyBag.Title = propertyBag.Step.Uri.PathAndQuery;
            using (var temp = new TempFile())
            {
                temp.FileName += "." + extension;
                using (var fs = new FileStream(temp.FileName, FileMode.Create, FileAccess.Write, FileShare.Read, 0x1000))
                    using (var input = propertyBag.GetResponse())
                    {
                        input.CopyTo(fs);
                    }

                using (var filterReader = new FilterReader(temp.FileName))
                {
                    var content = await filterReader.ReadToEndAsync();

                    propertyBag.Text = content.Trim();
                }
            }
        }
Example #5
0
        public void Process(Crawler crawler, PropertyBag propertyBag)
        {
            if (propertyBag.StatusCode != HttpStatusCode.OK)
            {
                return;
            }

            string extension = MapContentTypeToExtension(propertyBag.ContentType);

            if (extension.IsNullOrEmpty())
            {
                return;
            }

            propertyBag.Title = propertyBag.Step.Uri.PathAndQuery;
            using (TempFile temp = new TempFile())
            {
                temp.FileName += "." + extension;
                File.WriteAllBytes(temp.FileName, propertyBag.Response);
                using (FilterReader filterReader = new FilterReader(temp.FileName))
                {
                    string content = filterReader.ReadToEnd();
                    propertyBag.Text = content.Trim();
                }
            }
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public static string Parse(string filename)
        {
            IFilter filter = null;

            try
            {
                try
                {
                    FileInfo fileInfo = new FileInfo(filename);
                    using (var reader = new FilterReader(filename, fileInfo.Extension, filterReaderTimeout: FilterReaderTimeout.TimeoutWithException, timeout: 60 * 1000))
                    {
                        string text = reader.ReadToEnd();
                    }
                }
                catch (Exception)
                {
                }
                filter = loadIFilter(filename);

                return(ExtractText(filter));
            }
            catch { throw; }
            finally
            {
                if (filter != null)
                {
                    Marshal.ReleaseComObject(filter);
                }
            }
        }
        static public void ProcessImage(Element image)
        {
            bool image_mask  = image.IsImageMask();
            bool interpolate = image.IsImageInterpolate();
            int  width       = image.GetImageWidth();
            int  height      = image.GetImageHeight();
            int  out_data_sz = width * height * 3;

            Console.WriteLine("Image: width=\"{0:d}\" height=\"{1:d}\"", width, height);

            // Matrix2D mtx = image.GetCTM(); // image matrix (page positioning info)

//          ++image_counter;
//          System.Drawing.Bitmap bmp = image.GetBitmap();
//          bmp.Save(output_path + "reader_img_extract_" + image_counter.ToString() + ".png", System.Drawing.Imaging.ImageFormat.Png);
//
            // Alternatively you can use GetImageData to read the raw (decoded) image data
            // image.GetBitsPerComponent();
            // image.GetImageData();	// get raw image data
            // another approach is to use Image2RGB filter that converts every image to
            // RGB format. This could save you time since you don't need to deal with color
            // conversions, image up-sampling, decoding etc.
            // ----------------
            Image2RGB    img_conv = new Image2RGB(image);       // Extract and convert image to RGB 8-bpc format
            FilterReader reader   = new FilterReader(img_conv); //

            byte[] image_data_out = new byte[out_data_sz];      // A buffer used to keep image data.
            reader.Read(image_data_out);                        // image_data_out contains RGB image data.
            // ----------------
            // Note that you don't need to read a whole image at a time. Alternatively
            // you can read a chuck at a time by repeatedly calling reader.Read(buf, buf_sz)
            // until the function returns 0.
        }
Example #8
0
 // Searches the contents of filtered files. Does not care about exceptions.
 public void Search()
 {
     foreach (String dir in Directories)
     {
         var    fileInfo = new FileInfo(dir);
         string fileContents;
         if (fileInfo.Length < MAX_FILE_SIZE)
         {
             if (IsOfficeExtension(fileInfo.Extension))
             {
                 try {
                     var reader = new FilterReader(fileInfo.FullName);
                     fileContents = reader.ReadToEnd();
                     CheckForKeywords(fileContents, fileInfo);
                 } catch (Exception e) { Console.WriteLine("[-] Could not read contents of {0}", fileInfo.FullName); }
             }
             else
             {
                 //normal file
                 try {
                     CheckForKeywords(File.ReadAllText(fileInfo.FullName), fileInfo);
                 } catch (Exception e) { Console.WriteLine("[-] Could not read contents of {0}", fileInfo.FullName); }
             }
         }
         else
         {
             Console.WriteLine("[-] File exceeds 1MB file size {0}", fileInfo.FullName);
         }
     }
 }
Example #9
0
        // Extract searchable text from a file using IFilterTextReader.
        // Extract text from document, then replace multiple white space sequences with a single space.
        // If IFilterTextReader fails (for example, old Office document; or unknown document type), an exception is logged and null is returned.
        // Prefix is optional text to prepend to the result - such as document filename, metadata properties, anything else to include in search text.

        private static String ExtractTextFromFile(ILogger log, String inputFile, String prefix = null)
        {
            String line;
            String cleanedString = prefix;

            try
            {
                FilterReaderOptions options = new FilterReaderOptions()
                {
                };

                using (var reader = new FilterReader(inputFile, string.Empty, options))
                {
                    while ((line = reader.ReadLine()) != null)
                    {
                        line = line.Trim();
                        if (!String.IsNullOrEmpty(line))
                        {
                            line           = System.Text.RegularExpressions.Regex.Replace(line, @"[,]\s+", " ");
                            line           = System.Text.RegularExpressions.Regex.Replace(line, @"[,]", "");
                            line           = System.Text.RegularExpressions.Regex.Replace(line, @"[^a-zA-Z'\d\s:]", " ");
                            line           = System.Text.RegularExpressions.Regex.Replace(line, @"\s+", " ");
                            cleanedString += line + " ";
                        }
                    }
                } // end reader
            }
            catch (Exception ex)
            {
                log.LogError("ExtractTextFromFile: " + ex.Message);
            }

            return(cleanedString);
        }
Example #10
0
        /// <summary>
        /// Returns true when at least one of the given <paramref name="textToFind"/> is found
        /// in the <paramref name="fileName"/>
        /// </summary>
        /// <param name="fileName">The file to inspect</param>
        /// <param name="textToFind">The array with one or more text to find</param>
        /// <param name="ignoreCase">Set to false to search case sensitive</param>
        /// <returns></returns>
        public bool FileContainsTextFromArray(string fileName, string[] textToFind, bool ignoreCase = true)
        {
            using (var reader = new FilterReader(fileName))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    if (ignoreCase)
                    {
                        line = line.ToUpperInvariant();
                    }

                    foreach (var text in textToFind)
                    {
                        var temp = text;
                        if (ignoreCase)
                        {
                            temp = text.ToUpperInvariant();
                        }

                        if (line.Contains(temp))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Example #11
0
        public void Process(Crawler crawler, PropertyBag propertyBag)
        {
            if (propertyBag.StatusCode != HttpStatusCode.OK)
            {
                return;
            }

            string extension = MapContentTypeToExtension(propertyBag.ContentType);

            if (extension.IsNullOrEmpty())
            {
                return;
            }

            propertyBag.Title = propertyBag.Step.Uri.PathAndQuery;
            using (TempFile temp = new TempFile())
            {
                temp.FileName += "." + extension;
                using (FileStream fs = new FileStream(temp.FileName, FileMode.Create, FileAccess.Write, FileShare.Read, 0x1000))
                    using (Stream input = propertyBag.GetResponse())
                    {
                        input.CopyToStream(fs);
                    }

                using (FilterReader filterReader = new FilterReader(temp.FileName))
                {
                    string content = filterReader.ReadToEnd();
                    propertyBag.Text = content.Trim();
                }
            }
        }
Example #12
0
        public static List <string> ExtractDocParagraphs(Stream readStream)
        {
            //write the stream to a temp file
            var tmp      = Path.GetTempFileName();
            var fileName = tmp + ".doc";

            File.Move(tmp, fileName);
            using (var fileStream = File.Create(fileName))
            {
                readStream.Seek(0, SeekOrigin.Begin);
                readStream.CopyTo(fileStream);
                fileStream.Close();
            }

            var results = new List <string>();

            using (var reader = new FilterReader(fileName))
            {
                using (var stringReader = new StringReader(reader.ReadToEnd()))
                {
                    var nextLine = stringReader.ReadLine();
                    while (nextLine != null)
                    {
                        if (!string.IsNullOrWhiteSpace(nextLine))
                        {
                            results.Add(FormatParagraphText(nextLine));
                        }

                        nextLine = stringReader.ReadLine();
                    }
                }
            }
            File.Delete(fileName);
            return(results);
        }
Example #13
0
        public override string Extract(Stream stream)
        {
            //IFilter
            var target = new FilterReader(GetBytesFromStream(stream), ".xls");

            target.Init();
            return(target.ReadToEnd());
        }
Example #14
0
        public static DataForIndex CreateDocumentIndex(FilterReader reader, string fileName)
        {
            var dfi = new DataForIndex();

            dfi.ID            = new Random().Next(int.MaxValue);
            dfi.Label         = "Docs";
            dfi.FileExtension = Path.GetExtension(fileName);
            dfi.FileName      = fileName;
            dfi.Body          = reader.ReadToEnd();
            return(dfi);
        }
Example #15
0
        public override string Extract(Stream stream, TextExtractorContext context)
        {
            try
            {
                //extract text using IFilter
                var target = new FilterReader(GetBytesFromStream(stream), ".pdf");
                target.Init();
                return(target.ReadToEnd());
            }
            catch (OutOfMemoryException ex)
            {
                Logger.WriteWarning(EventId.Indexing.BinaryIsTooLarge,
                                    "Pdf text extract failed with out of memory exception. " + ex,
                                    properties: new Dictionary <string, object> {
                    { "Stream size", stream.Length }
                });

                return(string.Empty);
            }
            catch (Exception ex)
            {
                Logger.WriteWarning(EventId.Indexing.IFilterError, "Pdf IFilter error: " + ex.Message);
            }

            //fallback to the other mechanism in case the pdf IFilter is missing
            var text = new StringBuilder();

            try
            {
                var pdfReader = new PdfReader(stream);
                for (var page = 1; page <= pdfReader.NumberOfPages; page++)
                {
                    // extract text using the old version (4.1.6) of iTextSharp
                    var pageText = ExtractTextFromPdfBytes(pdfReader.GetPageContent(page));
                    if (string.IsNullOrEmpty(pageText))
                    {
                        continue;
                    }

                    text.Append(pageText);
                }
            }
            catch (OutOfMemoryException ex)
            {
                Logger.WriteWarning(EventId.Indexing.BinaryIsTooLarge,
                                    "Pdf text extract failed with out of memory exception. " + ex,
                                    properties: new Dictionary <string, object> {
                    { "Stream size", stream.Length }
                });
            }

            return(text.ToString());
        }
        /// <summary>
        /// Returns an array with all the matches that are found with the give <see cref="regularExpression"/> regular expression
        /// </summary>
        /// <param name="fileName">The file to inspect</param>
        /// <param name="regularExpression">The regular expression to use</param>
        /// <param name="ignoreCase">Set to false to search case sensitive</param>
        /// <returns></returns>
        public string[] GetRegexMatchesFromFile(string fileName, string regularExpression, bool ignoreCase = true)
        {
            var regex  = new Regex(regularExpression, ignoreCase ? RegexOptions.IgnoreCase : RegexOptions.None);
            var result = new List <string>();

            using (var reader = new FilterReader(fileName))
            {
                var text = reader.ReadToEnd();
                result.AddRange(from Match match in regex.Matches(text) select match.ToString());
            }

            return(result.ToArray());
        }
Example #17
0
        protected T ReadFilter <T>(byte[] source) where T : BaseFilter
        {
            var mem = new MemoryStream();

            mem.Write(source, 0, source.Length);
            mem.Seek(0, SeekOrigin.Begin);
            var reader       = new SwfStreamReader(mem);
            var filterReader = new FilterReader();
            var filter       = filterReader.Read(reader);

            Assert.AreEqual(mem.Length, mem.Position, "Should reach end of stream");
            return((T)filter);
        }
Example #18
0
        private void AddDocumentToIndexed(string fileName, FilterReaderTimeout timeoutOption)
        {
            Task t = new Task(() =>
            {
                try
                {
                    var reader = new FilterReader(fileName,
                                                  string.Empty,
                                                  disableEmbeddedContent: false,
                                                  includeProperties: false,
                                                  readIntoMemory: false,
                                                  filterReaderTimeout: timeoutOption,
                                                  timeout: -1);
                    DataForIndex dfi      = Utility.CreateDocumentIndex(reader, fileName);
                    LuceneBussines lucene = new LuceneBussines();
                    lucene.CreateIndex(dfi);
                    IndexDocCount++;
                    LableTextChange(DocumentCountLable, IndexDocCount.ToString());
                }
                catch (Exception ex)
                {
                    try
                    {
                        var reader = new FilterReader(fileName,
                                                      string.Empty,
                                                      disableEmbeddedContent: false,
                                                      includeProperties: false,
                                                      readIntoMemory: true,
                                                      filterReaderTimeout: FilterReaderTimeout.TimeoutWithException,
                                                      timeout: 5000);
                        if (reader == null)
                        {
                            return;
                        }
                        ;
                        DataForIndex dfi = Utility.CreateDocumentIndex(reader, fileName);

                        LuceneBussines lucene = new LuceneBussines();
                        lucene.CreateIndex(dfi);
                        IndexDocCount++;
                        LableTextChange(DocumentCountLable, IndexDocCount.ToString());
                    }
                    catch (Exception)
                    {
                    }
                }
            });

            t.Start();
        }
Example #19
0
        private void btnGetText_Click(object sender, EventArgs e)
        {
            string         dbt_wfile = "";
            OpenFileDialog dlg       = new OpenFileDialog();

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                dbt_wfile = dlg.FileName;
                TextReader reader = new FilterReader(dbt_wfile);
                using (reader)
                {
                    MessageBox.Show(reader.ReadToEnd());
                }
                reader.Close();
            }
        }
Example #20
0
        public override string Extract(System.IO.Stream stream)
        {
            try
            {
                //IFilter
                var target = new FilterReader(GetBytesFromStream(stream), ".doc");
                target.Init();
                return(target.ReadToEnd());
            }
            catch (Exception ex)
            {
                Logger.WriteWarning(EventId.Indexing.IFilterError, "Doc IFilter error: " + ex.Message);
            }

            return(string.Empty);
        }
Example #21
0
        public override string Extract(Stream stream, TextExtractorContext context)
        {
            try
            {
                //IFilter
                var target = new FilterReader(GetBytesFromStream(stream), ".msg");
                target.Init();
                return(target.ReadToEnd());
            }
            catch (Exception ex)
            {
                Logger.WriteWarning(EventId.Indexing.IFilterError, "Msg IFilter error: " + ex.Message);
            }

            return(string.Empty);
        }
Example #22
0
 private void ifilt(bool asEMBED)
 {
     _selected_file = string.Empty;
     if (openFileDialog.ShowDialog() == DialogResult.OK)
     {
         try
         {
             if (asEMBED)
             {
                 _selected_file = this.openFileDialog.FileName;
                 webBrowser.Navigate(_selected_file);
             }
             else
             {
                 try
                 {
                     TextReader reader = new FilterReader(openFileDialog.FileName);
                     using (reader)
                     {
                         string tmp_file = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), DateTime.Now.Ticks.ToString() + ".html");
                         using (StreamWriter sw = new StreamWriter(tmp_file, false, DefaultEncoding))
                         {
                             sw.Write(Regex.Replace(reader.ReadToEnd().Replace(Environment.NewLine, "<br>"), "\n", "<BR>" + Environment.NewLine, RegexOptions.Singleline));
                             sw.Close();
                         }
                         ////object missing = System.Reflection.Missing.Value;
                         ////object tmp = (object)tmp_file;
                         _selected_file = tmp_file;
                         webBrowser.Navigate(tmp_file);
                         ////this.axWebBrowser1.Navigate2(ref tmp, ref missing, ref missing, ref missing, ref missing);
                     }
                 }
                 catch (ArgumentException)
                 {
                     MessageBox.Show("Данный тип файлов не поддерживается");
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Error");
             return;
         }
     }
     SelectFile.Invoke(_selected_file);
     ////EditModeOn();
 }
Example #23
0
        // Searches the contents of filtered files. Does not care about exceptions.
        public void Search()
        {
            foreach (String dir in Directories)
            {
                try {
                    bool usingLegacyPathHandling = false;
                    AppContext.TryGetSwitch("Switch.System.IO.UseLegacyPathHandling", out usingLegacyPathHandling);
                    var dirToCheck = dir;
                    if (!usingLegacyPathHandling)
                    {
                        dirToCheck = ConvertToNTPath(dir);
                    }
                    var fileInfo = new FileInfo(dirToCheck);

                    string fileContents;
                    if (Convert.ToUInt64(fileInfo.Length) < 1024 * this.MAX_FILE_SIZE)
                    {
                        if (IsOfficeExtension(fileInfo.Extension))
                        {
                            try {
                                var reader = new FilterReader(fileInfo.FullName);
                                fileContents = reader.ReadToEnd();
                                CheckForKeywords(fileContents, fileInfo);
                            } catch (Exception e) { Console.WriteLine("[-] Could not read contents of {0}", PrettyPrintNTPath(fileInfo.FullName)); }
                        }
                        else
                        {
                            //normal file
                            try {
                                CheckForKeywords(File.ReadAllText(fileInfo.FullName), fileInfo);
                            } catch (Exception e) {
                                Console.WriteLine("[-] Could not read contents of {0}", PrettyPrintNTPath(fileInfo.FullName));
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("[-] File exceeds max file size {0}", PrettyPrintNTPath(fileInfo.FullName));
                    }
                } catch (PathTooLongException ex) {
                    Console.WriteLine("[-] Path {0} is too long. Skipping.", dir);
                    continue;
                } catch (Exception e) {
                    Console.WriteLine("[-] Some unknown exception {0} occured while processing {1}. Continuing with the next directory.", e.Message, dir);
                }
            }
        }
Example #24
0
        // Searches the contents of filtered files. Does not care about exceptions.
        public void Search()
        {
            foreach (String dir in Directories)
            {
                try {
                    var fileInfo = new FileInfo(ConvertToNTPath(dir));

                    string fileContents;
                    if (Convert.ToUInt64(fileInfo.Length) < 1024 * this.MAX_FILE_SIZE)
                    {
                        if (IsOfficeExtension(fileInfo.Extension))
                        {
                            try {
                                var reader = new FilterReader(fileInfo.FullName);
                                fileContents = reader.ReadToEnd();
                                CheckForKeywords(fileContents, fileInfo);
                            } catch (Exception e) { Console.WriteLine("[-] Could not read contents of {0}", PrettyPrintNTPath(fileInfo.FullName)); }
                        }
                        else
                        {
                            //normal file
                            try {
                                CheckForKeywords(File.ReadAllText(fileInfo.FullName), fileInfo);
                            } catch (Exception e) {
                                Console.WriteLine("[-] Could not read contents of {0}", PrettyPrintNTPath(fileInfo.FullName));
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("[-] File exceeds max file size {0}", PrettyPrintNTPath(fileInfo.FullName));
                    }
                } catch (PathTooLongException ex) {
                    Console.WriteLine("[-] Path {0} is too long. Skipping.", dir);
                    continue;
                } catch (Exception e) {
                    Console.WriteLine("[-] Some unknown exception {0} occured while processing {1}. Continuing with the next directory.", e.Message, dir);
                }
            }
            if (ossflag)
            {
                Console.WriteLine("\n[*] Now Create Zipfile and Upload Zipfile to aliyunOSS");
                Zipfile(Uploadfiles, this.bucketName, this.accessKeyId, this.accessKeySecret, this.endpoint);
            }
        }
        static byte[] FlipImage(Element element)
        {
            Image2RGB    image2rgb   = new Image2RGB(element);
            int          width       = element.GetImageWidth();
            int          height      = element.GetImageHeight();
            int          out_data_sz = width * height * 3;
            int          stride      = width * 3;
            FilterReader reader      = new FilterReader(image2rgb);

            byte[] image_data   = new byte[out_data_sz];
            byte[] flipped_data = new byte[out_data_sz];
            reader.Read(image_data);
            for (int row = 0; row < height; ++row)
            {
                Buffer.BlockCopy(image_data, row * stride, flipped_data, out_data_sz - (stride * (row + 1)), stride);
            }
            return(flipped_data);
        }
Example #26
0
        private List <string> GetTextFromPPT(string path)
        {
            List <string> text = new List <string>();
            string        line;

            if (!File.Exists(path))
            {
                MessageBox.Show("Please give the valid path of the PowerPont file.");
            }
            TextReader reader = new FilterReader(path);

            using (reader)
            {
                line = reader.ReadToEnd();
                text.Add(line);
            }
            return(text);
        }
Example #27
0
        private int ConvertFile(string sourcefile)
        {
            if (!File.Exists(sourcefile))
            {
                return(1);
            }
            try
            {
                TextReader reader = new FilterReader(sourcefile);
                using (reader)
                {
                    //                 char[] buffer = new char[0x5000];
                    //                 reader.Read(buffer, 0, 0x5000);
                    //                 string context = new string(buffer);
                    string context = reader.ReadToEnd();

                    calcWords(context);

                    context = Regex.Replace(context, "\n\r", " ", RegexOptions.IgnoreCase);

                    try
                    {
                        string name = GetFileName(sourcefile);
                        using (StreamWriter writer = new StreamWriter((outpath + @"\" + name + ".txt").Replace(@"\\", @"\"), false, Encoding.Default))
                        {
                            writer.Write(context);
                            writer.Close();
                        }
                        reader.Close();

                        return(0);
                    }
                    catch (Exception exception)
                    {
                        reader.Close();
                        return(3);
                    }
                }
            }
            catch (Exception e)
            {
                return(2);
            }
        }
Example #28
0
        public static int ConvertFile()
        {
            if (!File.Exists(sourcefile))
            {
                return((int)OutStatus.FileLoss);
            }
            try
            {
                TextReader reader = new FilterReader(sourcefile);
                using (reader)
                {
                    //                 char[] buffer = new char[0x5000];
                    //                 reader.Read(buffer, 0, 0x5000);
                    //                 string context = new string(buffer);
                    string context = reader.ReadToEnd();
                    context = Regex.Replace(context, "\n\r", " ", RegexOptions.IgnoreCase);

                    try
                    {
                        string txtfile = (outtxtpath + @"\" + fileid + ".txt").Replace(@"\\", @"\");
                        using (StreamWriter writer = new StreamWriter(txtfile, false, Encoding.Default))
                        {
                            writer.Write(context);
                            writer.Close();
                        }
                        reader.Close();
                        ExecuteRegexTxt(txtfile);
                        return((int)OutStatus.ConvertSuccess);
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine("保存txt文件发生异常" + exception);
                        return((int)OutStatus.TotxtFailed);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("打开文件失败" + e);
                return((int)OutStatus.TotxtFailed);
            }
        }
        public bool TryExtract(string fullPath, Stream stream, string fileName, out ExtractionResult result)
        {
            var builder = new CleanTextBuilder();
            var reader  = new FilterReader(fullPath, fileName);

            if (reader.Filtered)
            {
                builder.Add(reader);

                result = new ExtractionResult()
                {
                    ContentType  = null,
                    PlainContent = builder.ToString()
                };

                return(true);
            }
            result = null;
            return(false);
        }
        /// <summary>
        /// Returns true when the <paramref name="regularExpression"/> is found in the
        /// <paramref name="fileName"/>
        /// </summary>
        /// <param name="fileName">The file to inspect</param>
        /// <param name="regularExpression">The regular expression to use</param>
        /// <param name="ignoreCase">Set to false to search case sensitive</param>
        /// <returns></returns>
        public bool FileContainsRegexMatch(string fileName, string regularExpression, bool ignoreCase = true)
        {
            var regex = new Regex(regularExpression, ignoreCase ? RegexOptions.IgnoreCase : RegexOptions.None);

            using (var reader = new FilterReader(fileName))
            {
                var line = reader.ReadLine();
                if (string.IsNullOrEmpty(line))
                {
                    return(false);
                }

                if (regex.IsMatch(line))
                {
                    return(true);
                }
            }

            return(false);
        }
    public void   WordDocumentRetrieve()
    {
        SqlDataAdapter adp1 = new SqlDataAdapter("Select Max(ID) From FileUpload", sqlCon);
        DataSet        ds1  = new DataSet();

        adp1.Fill(ds1, "FileUpload");
        id = Convert.ToInt32(ds1.Tables["FileUpload"].Rows[0][0].ToString());

        SqlDataAdapter adp = new SqlDataAdapter("Select UpFile1 From FileUpload Where ID=" + id, sqlCon);
        DataSet        ds  = new DataSet();

        adp.Fill(ds, "FileUpload");
        name = ds.Tables["FileUpload"].Rows[0]["UpFile1"].ToString();
        if (name != "")
        {
            string     temp   = null;
            var        a      = new ArrayList();
            TextReader reader = new FilterReader(Server.MapPath("~/Docs/" + name));
            using (reader)
            {
                temp = reader.ReadToEnd();
            }

            if (temp.Length >= 1000)
            {
                SqlCommand Comm = sqlCon.CreateCommand();
                Comm.CommandText = "Update FileUpload SET FileData='" + temp.Substring(0, 999).Trim() + "' Where ID=" + id;
                Comm.Connection  = sqlCon;
                Comm.ExecuteNonQuery();
                sqlCon.Close();
            }
            else
            {
                SqlCommand Comm = sqlCon.CreateCommand();
                Comm.CommandText = "Update FileUpload SET FileData='" + temp + "' Where ID=" + id;
                Comm.Connection  = sqlCon;
                Comm.ExecuteNonQuery();
                sqlCon.Close();
            }
        }
    }
        /// <summary>
        /// Loads the filters.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="allFilters">Collection with all loaded filter instances.</param>
        public void LoadFilters(string path, ICollection allFilters)
        {
            m_loading = true;

            try
            {
                // Deactivate all filters
                foreach (ILogFilter filter in allFilters)
                {
                    RemoveFilter(filter);
                }

                // Load filters
                List<ILogFilter> loadedFilters = null;
                using (FilterReader reader = new FilterReader(path))
                {
                    try
                    {
                        // Read file
                        reader.ProcessHeader();
                        loadedFilters = reader.ReadFilters(allFilters);
                        reader.ProcessEpilogue();

                        // Copy data
                        CombineFilters = reader.CombineFilters;
                        InvertCheck = reader.InvertCheck;
                    }
                    catch (Exception e)
                    {
                        Log.Error("Loading filters", e);
                    }
                }

                // Activate loaded filters
                if (null != loadedFilters)
                {
                    foreach (ILogFilter filter in loadedFilters)
                    {
                        AddFilter(filter);
                    }
                }
            }
            finally
            {
                m_loading = false;
            }
        }
Example #33
0
        /*
         * 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;
        }