Beispiel #1
0
 private void GetUserFromPaths()
 {
     foreach (PathsItem ri in FoundPaths.Items)
     {
         string strUser = PathAnalysis.ExtractUserFromPath(ri.Path);
         FoundUsers.AddUniqueItem(strUser, ri.IsComputerFolder, ri.Path);
     }
 }
Beispiel #2
0
 private void GetUserFromPaths()
 {
     foreach (Diagrams.Path ri in this.foundMetadata.Paths)
     {
         string strUser = PathAnalysis.ExtractUserFromPath(ri.Value);
         this.foundMetadata.Add(new User(strUser, ri.IsComputerFolder, ri.Value));
     }
 }
Beispiel #3
0
        public override FileMetadata AnalyzeFile()
        {
            try
            {
                this.foundMetadata = new FileMetadata();
                if (IsWPD(this.fileStream))
                {
                    long         entryPoint = 0;
                    MetadataType tipo;
                    while ((entryPoint = EntryPointString(this.fileStream, out tipo)) > -1)
                    {
                        this.fileStream.Seek(entryPoint + 2, SeekOrigin.Begin);

                        var aux = ReadBinaryString16(this.fileStream);
                        if (!IsPossibleString(aux))
                        {
                            continue;
                        }
                        if (tipo == MetadataType.Unknown && !PathAnalysis.IsValidPath(aux))
                        {
                            if (aux.ToLower().Contains("jet") || aux.ToLower().Contains("printer") || aux.ToLower().Contains("hp") ||
                                aux.ToLower().Contains("series") || aux.ToLower().Contains("canon") || aux.ToLower().Contains("laser") ||
                                aux.ToLower().Contains("epson") || aux.ToLower().Contains("lj") || aux.ToLower().Contains("lexmark") ||
                                aux.ToLower().Contains("xerox") || aux.ToLower().Contains("sharp"))
                            {
                                this.foundMetadata.Add(new Printer(Functions.FilterPrinter(aux)));
                            }
                            else if (aux.ToLower().Contains("acrobat") || aux.ToLower().Contains("adobe") || aux.ToLower().Contains("creator") ||
                                     aux.ToLower().Contains("writer") || aux.ToLower().Contains("pdf") || aux.ToLower().Contains("converter"))
                            {
                                this.foundMetadata.Add(new Application(Functions.FilterPrinter(Analysis.ApplicationAnalysis.GetApplicationsFromString(aux))));
                            }
                        }
                        else
                        {
                            var strPath = Functions.GetPathFolder(aux);
                            if (!PathAnalysis.IsValidPath(strPath))
                            {
                                continue;
                            }
                            this.foundMetadata.Add(new Diagrams.Path(PathAnalysis.CleanPath(strPath), true));
                            var strUser = PathAnalysis.ExtractUserFromPath(strPath);
                            if (!string.IsNullOrEmpty(strUser))
                            {
                                this.foundMetadata.Add(new User(strUser, true));
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
            }
            return(this.foundMetadata);
        }
Beispiel #4
0
        public override FileMetadata AnalyzeFile()
        {
            XmlTextReader avgReader = null;

            try
            {
                this.foundMetadata = new FileMetadata();
                avgReader          = new XmlTextReader(this.fileStream)
                {
                    XmlResolver = null
                };
                avgReader.Read();

                while (avgReader.Read())
                {
                    // node's value, example: <a>/home/user/file</a>
                    if (CheckPath(avgReader.Value))
                    {
                        var cleanPath = PathAnalysis.CleanPath(avgReader.Value);
                        var user      = PathAnalysis.ExtractUserFromPath(cleanPath);
                        if (user != string.Empty)
                        {
                            this.foundMetadata.Add(new User(user, true));
                        }
                        this.foundMetadata.Add(new Diagrams.Path(cleanPath, true));
                    }

                    while (avgReader.MoveToNextAttribute())
                    {
                        // attribute's value, example: <a atrib="/home/user/file"/>
                        if (!CheckPath(avgReader.Value))
                        {
                            continue;
                        }
                        var cleanPath = PathAnalysis.CleanPath(avgReader.Value);
                        var user      = PathAnalysis.ExtractUserFromPath(cleanPath);
                        if (user != string.Empty)
                        {
                            this.foundMetadata.Add(new User(user, true));
                        }
                        this.foundMetadata.Add(new Diagrams.Path(cleanPath, true));
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("error: " + ex.Message);
            }
            finally
            {
                avgReader?.Close();
            }
            return(this.foundMetadata);
        }
Beispiel #5
0
        public override void analyzeFile()
        {
            XmlTextReader avgReader = null;

            try
            {
                avgReader = new XmlTextReader(this.stm)
                {
                    XmlResolver = null
                };
                avgReader.Read();

                while (avgReader.Read())
                {
                    // node's value, example: <a>/home/user/file</a>
                    if (CheckPath(avgReader.Value))
                    {
                        var cleanPath = PathAnalysis.CleanPath(avgReader.Value);
                        var user      = PathAnalysis.ExtractUserFromPath(cleanPath);
                        if (user != string.Empty)
                        {
                            FoundUsers.AddUniqueItem(user, true);
                        }
                        FoundPaths.AddUniqueItem(cleanPath, true);
                    }

                    while (avgReader.MoveToNextAttribute())
                    {
                        // attribute's value, example: <a atrib="/home/user/file"/>
                        if (!CheckPath(avgReader.Value))
                        {
                            continue;
                        }
                        var cleanPath = PathAnalysis.CleanPath(avgReader.Value);
                        var user      = PathAnalysis.ExtractUserFromPath(cleanPath);
                        if (user != string.Empty)
                        {
                            FoundUsers.AddUniqueItem(user, true);
                        }
                        FoundPaths.AddUniqueItem(cleanPath, true);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("error: " + ex.Message);
            }
            finally
            {
                avgReader?.Close();
            }
        }
Beispiel #6
0
        public override FileMetadata AnalyzeFile()
        {
            try
            {
                this.foundMetadata = new FileMetadata();
                using (StreamReader sr = new StreamReader(this.fileStream))
                {
                    string line = string.Empty;

                    while ((line = sr.ReadLine()) != null)
                    {
                        string[] separatedValues = line.Split(new char[] { '=' });
                        if (separatedValues.Length < 2)
                        {
                            continue;
                        }

                        string key   = separatedValues[0].ToLower();
                        string value = line.Remove(0, key.Length + 1);

                        if (String.IsNullOrWhiteSpace(value))
                        {
                            continue;
                        }

                        if (key.StartsWith("address") ||
                            key.StartsWith("httpbrowseraddress") ||
                            key.StartsWith("tcpbrowseraddress") ||
                            key.StartsWith("sslproxyhost"))
                        {
                            string ipOrHost = value.Split(new char[] { ':' })[0];
                            if (ipOrHost != "*")
                            {
                                this.foundMetadata.Add(new Server(ipOrHost, "ICA file Analysis"));
                            }
                        }
                        else if (key.StartsWith("username"))
                        {
                            this.foundMetadata.Add(new User(value, true));
                        }
                        else if (key.StartsWith("clearpassword") ||
                                 key.StartsWith("password"))
                        {
                            this.foundMetadata.Add(new Password(value, "ICA Clear password"));
                        }
                        else if (key.StartsWith("persistentcachepath") ||
                                 key.StartsWith("workdirectory") ||
                                 key.StartsWith("initialprogram") ||
                                 key.StartsWith("iconpath"))
                        {
                            this.foundMetadata.Add(new Diagrams.Path(value, true));

                            string user = PathAnalysis.ExtractUserFromPath(value);
                            if (user != string.Empty)
                            {
                                this.foundMetadata.Add(new User(user, true));
                            }

                            string softName = ApplicationAnalysis.GetApplicationsFromString(value);
                            if (!string.IsNullOrEmpty(value))
                            {
                                this.foundMetadata.Add(new Application(softName));
                            }
                            else
                            {
                                this.foundMetadata.Add(new Application(value));
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
            }
            return(this.foundMetadata);
        }
Beispiel #7
0
        /// <summary>
        /// Extrae los metadatos del documento
        /// </summary>
        public override FileMetadata AnalyzeFile()
        {
            try
            {
                this.foundMetadata = new FileMetadata();
                using (PdfDocument doc = PdfReader.Open(this.fileStream, PdfDocumentOpenMode.InformationOnly))
                {
                    int imageNumber = 0;
                    //Read embedded images
                    foreach (PdfDictionary item in doc.Internals.GetAllObjects().Where(p => p is PdfDictionary d && d.Stream != null && "/Image".Equals(d.Elements["/Subtype"]?.ToString())))
                    {
                        try
                        {
                            using (MemoryStream msJPG = new MemoryStream(item.Stream.Value))
                            {
                                using (EXIFDocument eDoc = new EXIFDocument(msJPG))
                                {
                                    FileMetadata exifMetadata = eDoc.AnalyzeFile();
                                    //Ignore images which only contain 'Adobe JPEG' makernotes
                                    if (exifMetadata != null && exifMetadata.HasMetadata() && !exifMetadata.Makernotes.All(p => p.Key == "Adobe JPEG"))
                                    {
                                        foundMetadata.EmbeddedImages.Add(imageNumber.ToString(), exifMetadata);
                                        imageNumber++;
                                        this.foundMetadata.AddRange(exifMetadata.Users.ToArray());
                                        this.foundMetadata.AddRange(exifMetadata.Applications.ToArray());
                                    }
                                }
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }

                    ReadXMPMetadata(doc);
                    if (doc.Info.Title != string.Empty)
                    {
                        this.foundMetadata.Title = Functions.ToPlainText(doc.Info.Title);
                        if (Uri.IsWellFormedUriString(doc.Info.Title, UriKind.Absolute))
                        {
                            this.foundMetadata.Add(new Diagrams.Path(PathAnalysis.CleanPath(doc.Info.Title), true));
                        }
                    }

                    if (doc.Info.Subject != string.Empty)
                    {
                        this.foundMetadata.Subject = Functions.ToPlainText(doc.Info.Subject);
                    }
                    if (doc.Info.Author != string.Empty)
                    {
                        this.foundMetadata.Add(new User(Functions.ToPlainText(doc.Info.Author), true));
                    }
                    if (doc.Info.Keywords != string.Empty)
                    {
                        this.foundMetadata.Keywords = Functions.ToPlainText(doc.Info.Keywords);
                    }

                    if (doc.Info.Creator != string.Empty)
                    {
                        string strSoftware = ApplicationAnalysis.GetApplicationsFromString(Functions.ToPlainText(doc.Info.Creator));
                        if (strSoftware.Trim() != string.Empty)
                        {
                            this.foundMetadata.Add(new Application(strSoftware));
                        }
                        //No se ha localizado ninguna aplicación conocida, aun así mostrar la aplicación encontrada
                        else if (!String.IsNullOrWhiteSpace(Functions.ToPlainText(doc.Info.Creator)))
                        {
                            this.foundMetadata.Add(new Application(Functions.ToPlainText(doc.Info.Creator).Trim()));
                        }
                    }

                    if (!String.IsNullOrWhiteSpace(doc.Info.Producer))
                    {
                        string strSoftware = ApplicationAnalysis.GetApplicationsFromString(Functions.ToPlainText(doc.Info.Producer));
                        if (!String.IsNullOrWhiteSpace(strSoftware))
                        {
                            this.foundMetadata.Add(new Application(strSoftware));
                        }
                        //No se ha localizado ninguna aplicación conocida, aun así mostrar la aplicación encontrada
                        else if (!String.IsNullOrWhiteSpace(Functions.ToPlainText(doc.Info.Producer)))
                        {
                            this.foundMetadata.Add(new Application(Functions.ToPlainText(doc.Info.Producer).Trim()));
                        }
                    }

                    try
                    {
                        if (doc.Info.CreationDate != DateTime.MinValue)
                        {
                            this.foundMetadata.Dates.CreationDate = doc.Info.CreationDate;
                        }
                    }
                    catch (InvalidCastException)
                    {
                    }

                    try
                    {
                        if (doc.Info.ModificationDate != DateTime.MinValue)
                        {
                            this.foundMetadata.Dates.ModificationDate = doc.Info.ModificationDate;
                        }
                    }
                    catch (InvalidCastException)
                    {
                    }
                }

                SearchPathsLinksAndEmails(this.fileStream);

                //Find users in paths
                foreach (Diagrams.Path path in this.foundMetadata.Paths)
                {
                    string strUser = PathAnalysis.ExtractUserFromPath(path.Value);
                    this.foundMetadata.Add(new User(strUser, path.IsComputerFolder));
                }

                //Also search software in the title (only pdf). It is added only if the software is known.
                if (!String.IsNullOrEmpty(foundMetadata.Title))
                {
                    string strSoftware = ApplicationAnalysis.GetApplicationsFromString(foundMetadata.Title);
                    if (!String.IsNullOrWhiteSpace(strSoftware))
                    {
                        this.foundMetadata.Add(new Application(strSoftware));
                    }
                }
            }
            catch (PdfReaderException)
            { }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
            finally
            {
                if (foundMetadata == null)
                {
                    this.foundMetadata = new FileMetadata();
                }

                if (fileStream != null)
                {
                    this.fileStream.Dispose();
                }
            }
            return(this.foundMetadata);
        }
 /// <summary>
 /// Extrae los metadatos del documento
 /// </summary>
 public override FileMetadata AnalyzeFile()
 {
     try
     {
         this.foundMetadata = new FileMetadata();
         using (ZipFile zip = ZipFile.Read(this.fileStream))
         {
             string strFile = "meta.xml";
             if (zip.EntryFileNames.Contains(strFile))
             {
                 using (Stream stmXML = new MemoryStream())
                 {
                     zip.Extract(strFile, stmXML);
                     stmXML.Seek(0, SeekOrigin.Begin);
                     AnalizeFileMeta(stmXML);
                 }
             }
             strFile = "settings.xml";
             if (zip.EntryFileNames.Contains(strFile))
             {
                 using (Stream stmXML = new MemoryStream())
                 {
                     zip.Extract(strFile, stmXML);
                     stmXML.Seek(0, SeekOrigin.Begin);
                     analizeFileSettings(stmXML);
                 }
             }
             strFile = "content.xml";
             if (zip.EntryFileNames.Contains(strFile))
             {
                 using (Stream stmXML = new MemoryStream())
                 {
                     zip.Extract(strFile, stmXML);
                     stmXML.Seek(0, SeekOrigin.Begin);
                     AnalizeFileContent(stmXML);
                 }
             }
             strFile = "VersionList.xml";
             if (zip.EntryFileNames.Contains(strFile))
             {
                 using (Stream stmXML = new MemoryStream())
                 {
                     zip.Extract(strFile, stmXML);
                     stmXML.Seek(0, SeekOrigin.Begin);
                     AnalizeFileVersionList(stmXML, zip);
                 }
             }
             //Extrae inforamción EXIF de las imágenes embebidas en el documento
             foreach (string strFileName in zip.EntryFileNames)
             {
                 string strFileNameLo = strFileName.ToLower();
                 //Filtro que obtiene las imagenes *.jpg, *.jpeg dentro de la carpeta "Pictures/"
                 if (strFileNameLo.StartsWith("pictures/") &&
                     (strFileNameLo.EndsWith(".jpg") || strFileNameLo.EndsWith(".jpeg")))
                 {
                     using (Stream stmXML = new MemoryStream())
                     {
                         zip.Extract(strFileName, stmXML);
                         stmXML.Seek(0, SeekOrigin.Begin);
                         using (EXIFDocument eDoc = new EXIFDocument(stmXML, System.IO.Path.GetExtension(strFileNameLo)))
                         {
                             FileMetadata exifMetadata = eDoc.AnalyzeFile();
                             //Añadimos al diccionario la imagen encontrada junto con la información EXIF de la misma
                             this.foundMetadata.EmbeddedImages.Add(System.IO.Path.GetFileName(strFileName), exifMetadata);
                             //Los usuarios de la información EXIF se añaden a los usuarios del documento
                             this.foundMetadata.AddRange(exifMetadata.Users.ToArray());
                             this.foundMetadata.AddRange(exifMetadata.Applications.ToArray());
                         }
                     }
                 }
             }
         }
         //Buscamos usuarios en las rutas del documento
         foreach (Diagrams.Path ri in this.foundMetadata.Paths)
         {
             string strUser = PathAnalysis.ExtractUserFromPath(ri.Value);
             if (!string.IsNullOrEmpty(strUser))
             {
                 this.foundMetadata.Add(new User(strUser, ri.IsComputerFolder, "Path: " + ri.Value));
             }
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(String.Format("Error analyzing OpenOffice document ({0})", e.ToString()));
     }
     return(this.foundMetadata);
 }
Beispiel #9
0
 /// <summary>
 /// Extrae los metadatos del documento
 /// </summary>
 public override void analyzeFile()
 {
     try
     {
         using (ZipFile zip = ZipFile.Read(stm))
         {
             string strFile = "meta.xml";
             if (zip.EntryFileNames.Contains(strFile))
             {
                 using (Stream stmXML = new MemoryStream())
                 {
                     zip.Extract(strFile, stmXML);
                     stmXML.Seek(0, SeekOrigin.Begin);
                     analizeFileMeta(stmXML);
                 }
             }
             strFile = "settings.xml";
             if (zip.EntryFileNames.Contains(strFile))
             {
                 using (Stream stmXML = new MemoryStream())
                 {
                     zip.Extract(strFile, stmXML);
                     stmXML.Seek(0, SeekOrigin.Begin);
                     analizeFileSettings(stmXML);
                 }
             }
             strFile = "content.xml";
             if (zip.EntryFileNames.Contains(strFile))
             {
                 using (Stream stmXML = new MemoryStream())
                 {
                     zip.Extract(strFile, stmXML);
                     stmXML.Seek(0, SeekOrigin.Begin);
                     analizeFileContent(stmXML);
                 }
             }
             strFile = "VersionList.xml";
             if (zip.EntryFileNames.Contains(strFile))
             {
                 using (Stream stmXML = new MemoryStream())
                 {
                     zip.Extract(strFile, stmXML);
                     stmXML.Seek(0, SeekOrigin.Begin);
                     analizeFileVersionList(stmXML, zip);
                 }
             }
             //Extrae inforamción EXIF de las imágenes embebidas en el documento
             foreach (string strFileName in zip.EntryFileNames)
             {
                 string strFileNameLo = strFileName.ToLower();
                 //Filtro que obtiene las imagenes *.jpg, *.jpeg dentro de la carpeta "Pictures/"
                 if (strFileNameLo.StartsWith("pictures/") &&
                     (strFileNameLo.EndsWith(".jpg") || strFileNameLo.EndsWith(".jpeg")))
                 {
                     using (Stream stmXML = new MemoryStream())
                     {
                         zip.Extract(strFileName, stmXML);
                         stmXML.Seek(0, SeekOrigin.Begin);
                         EXIFDocument eDoc = new EXIFDocument(stmXML, Path.GetExtension(strFileNameLo));
                         eDoc.analyzeFile();
                         //Añadimos al diccionario la imagen encontrada junto con la información EXIF de la misma
                         dicPictureEXIF.Add(Path.GetFileName(strFileName), eDoc);
                         //Los usuarios de la información EXIF se añaden a los usuarios del documento
                         foreach (UserItem uiEXIF in eDoc.FoundUsers.Items)
                         {
                             FoundUsers.AddUniqueItem(uiEXIF.Name, false, "EXIF");
                         }
                         //Añadir el software encontrado en la información EXIF al software usado para generar el documento
                         foreach (ApplicationsItem Application in eDoc.FoundMetaData.Applications.Items)
                         {
                             string strApplication = Application.Name;
                             if (!FoundMetaData.Applications.Items.Any(A => A.Name == strApplication.Trim()))
                             {
                                 FoundMetaData.Applications.Items.Add(new ApplicationsItem(strApplication.Trim()));
                             }
                         }
                     }
                 }
             }
         }
         //Buscamos usuarios en las rutas del documento
         foreach (PathsItem ri in FoundPaths.Items)
         {
             string strUser = PathAnalysis.ExtractUserFromPath(ri.Path);
             if (!string.IsNullOrEmpty(strUser))
             {
                 FoundUsers.AddUniqueItem(strUser, ri.IsComputerFolder, "Path: " + ri.Path);
             }
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(String.Format("Error analyzing OpenOffice document ({0})", e.ToString()));
     }
 }
Beispiel #10
0
        public override void analyzeFile()
        {
            try
            {
                StreamReader sr   = new StreamReader(this.stm);
                string       line = string.Empty;

                while ((line = sr.ReadLine()) != null)
                {
                    string parametro = string.Empty;
                    string valor     = string.Empty;

                    try
                    {
                        parametro = line.Split(new char[] { '=' })[0];

                        int entryPoint = parametro.Length + 1;
                        valor = line.Substring(entryPoint, line.Length - entryPoint);
                    }
                    catch
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(valor))
                    {
                        continue;
                    }

                    if (parametro.ToString().ToLower().StartsWith("Address".ToLower()))
                    {
                        string ipOrHost = valor.Split(new char[] { ':' })[0];
                        FoundServers.AddUniqueItem(new ServersItem(ipOrHost, "ICA file Analysis"));
                    }
                    else if (parametro.ToString().ToLower().StartsWith("HttpBrowserAddress".ToLower()))
                    {
                        string ipOrHost = valor.Split(new char[] { ':' })[0];
                        FoundServers.AddUniqueItem(new ServersItem(ipOrHost, "ICA file Analysis"));
                    }
                    else if (parametro.ToString().ToLower().StartsWith("TcpBrowserAddress".ToLower()))
                    {
                        string ipOrHost = valor.Split(new char[] { ':' })[0];
                        FoundServers.AddUniqueItem(new ServersItem(ipOrHost, "ICA file Analysis"));
                    }
                    else if (parametro.ToString().ToLower().StartsWith("Username".ToLower()))
                    {
                        FoundUsers.AddUniqueItem(valor, true);
                    }
                    else if (parametro.ToString().ToLower().StartsWith("ClearPassword".ToLower()))
                    {
                        FoundPasswords.AddUniqueItem(new PasswordsItem(valor, "ICA Clear password"));
                    }
                    else if (parametro.ToString().ToLower().StartsWith("Password".ToLower()))
                    {
                        FoundPasswords.AddUniqueItem(new PasswordsItem(valor, "ICA password"));
                    }
                    else if ((parametro.ToString().ToLower().StartsWith("PersistentCachePath".ToLower())) ||
                             (parametro.ToString().ToLower().StartsWith("WorkDirectory".ToLower())) ||
                             (parametro.ToString().ToLower().StartsWith("InitialProgram".ToLower()))
                             )
                    {
                        FoundPaths.AddUniqueItem(valor, true);

                        string user = PathAnalysis.ExtractUserFromPath(valor);
                        if (user != string.Empty)
                        {
                            FoundUsers.AddUniqueItem(user, true);
                        }

                        string softName = Analysis.ApplicationAnalysis.GetApplicationsFromString(valor);
                        if (!string.IsNullOrEmpty(valor))
                        {
                            FoundMetaData.Applications.AddUniqueItem(new ApplicationsItem(softName));
                        }
                        else
                        {
                            FoundMetaData.Applications.AddUniqueItem(new ApplicationsItem(valor));
                        }
                    }
                    else if (parametro.ToString().ToLower().StartsWith("IconPath".ToLower()))
                    {
                        FoundPaths.AddUniqueItem(valor, true);

                        string user = PathAnalysis.ExtractUserFromPath(valor);
                        if (user != string.Empty)
                        {
                            FoundUsers.AddUniqueItem(user, true);
                        }

                        string softName = Analysis.ApplicationAnalysis.GetApplicationsFromString(valor);
                        if (!string.IsNullOrEmpty(valor))
                        {
                            FoundMetaData.Applications.AddUniqueItem(new ApplicationsItem(softName));
                        }
                        else
                        {
                            FoundMetaData.Applications.AddUniqueItem(new ApplicationsItem(valor));
                        }
                    }
                    else if (parametro.ToString().ToLower().StartsWith("SSLProxyHost".ToLower()))
                    {
                        string ipOrHost = valor.Split(new char[] { ':' })[0];
                        if (ipOrHost != "*")
                        {
                            FoundServers.AddUniqueItem(new ServersItem(ipOrHost, "ICA file Analysis"));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
            }
        }
Beispiel #11
0
        /// <summary>
        /// Extrae los metadatos del documento
        /// </summary>
        public override FileMetadata AnalyzeFile()
        {
            try
            {
                this.foundMetadata = new FileMetadata();
                using (PdfDocument doc = PdfReader.Open(this.fileStream, PdfDocumentOpenMode.InformationOnly))
                {
                    ReadXMPMetadata(doc);
                    if (doc.Info.Title != string.Empty)
                    {
                        this.foundMetadata.Title = Functions.ToPlainText(doc.Info.Title);
                        if (Uri.IsWellFormedUriString(doc.Info.Title, UriKind.Absolute))
                        {
                            this.foundMetadata.Add(new Diagrams.Path(PathAnalysis.CleanPath(doc.Info.Title), true));
                        }
                    }

                    if (doc.Info.Subject != string.Empty)
                    {
                        this.foundMetadata.Subject = Functions.ToPlainText(doc.Info.Subject);
                    }
                    if (doc.Info.Author != string.Empty)
                    {
                        this.foundMetadata.Add(new User(Functions.ToPlainText(doc.Info.Author), true));
                    }
                    if (doc.Info.Keywords != string.Empty)
                    {
                        this.foundMetadata.Keywords = Functions.ToPlainText(doc.Info.Keywords);
                    }

                    if (doc.Info.Creator != string.Empty)
                    {
                        string strSoftware = ApplicationAnalysis.GetApplicationsFromString(Functions.ToPlainText(doc.Info.Creator));
                        if (strSoftware.Trim() != string.Empty)
                        {
                            this.foundMetadata.Add(new Application(strSoftware));
                        }
                        //No se ha localizado ninguna aplicación conocida, aun así mostrar la aplicación encontrada
                        else if (!String.IsNullOrWhiteSpace(Functions.ToPlainText(doc.Info.Creator)))
                        {
                            this.foundMetadata.Add(new Application(Functions.ToPlainText(doc.Info.Creator).Trim()));
                        }
                    }

                    if (!String.IsNullOrWhiteSpace(doc.Info.Producer))
                    {
                        string strSoftware = ApplicationAnalysis.GetApplicationsFromString(Functions.ToPlainText(doc.Info.Producer));
                        if (!String.IsNullOrWhiteSpace(strSoftware))
                        {
                            this.foundMetadata.Add(new Application(strSoftware));
                        }
                        //No se ha localizado ninguna aplicación conocida, aun así mostrar la aplicación encontrada
                        else if (!String.IsNullOrWhiteSpace(Functions.ToPlainText(doc.Info.Producer)))
                        {
                            this.foundMetadata.Add(new Application(Functions.ToPlainText(doc.Info.Producer).Trim()));
                        }
                    }

                    try
                    {
                        if (doc.Info.CreationDate != DateTime.MinValue)
                        {
                            this.foundMetadata.Dates.CreationDate = doc.Info.CreationDate;
                        }
                    }
                    catch (InvalidCastException)
                    {
                    }

                    try
                    {
                        if (doc.Info.ModificationDate != DateTime.MinValue)
                        {
                            this.foundMetadata.Dates.ModificationDate = doc.Info.ModificationDate;
                        }
                    }
                    catch (InvalidCastException)
                    {
                    }
                }

                //Busca path y links binariamente
                this.foundMetadata.AddRange(BinarySearchPaths(this.fileStream).ToArray());
                this.foundMetadata.AddRange(BinarySearchLinks(this.fileStream).ToArray());

                foreach (Diagrams.Path ri in this.foundMetadata.Paths)
                {
                    //Busca usuarios dentro de la ruta
                    string strUser = PathAnalysis.ExtractUserFromPath(ri.Value);
                    this.foundMetadata.Add(new User(strUser, ri.IsComputerFolder));
                }

                //También busca el software en el título solo en los pdf, solo lo añade si es software conocido
                if (!String.IsNullOrEmpty(foundMetadata.Title))
                {
                    string strSoftware = ApplicationAnalysis.GetApplicationsFromString(foundMetadata.Title);
                    if (!String.IsNullOrWhiteSpace(strSoftware))
                    {
                        this.foundMetadata.Add(new Application(strSoftware));
                    }
                }
            }
            catch (PdfReaderException)
            { }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
            finally
            {
                if (foundMetadata == null)
                {
                    this.foundMetadata = new FileMetadata();
                }
            }
            return(this.foundMetadata);
        }
Beispiel #12
0
        /// <summary>
        /// Extrae los metadatos del documento
        /// </summary>
        public override void analyzeFile()
        {
            PdfDocument doc = null;

            try
            {
                doc = PdfReader.Open(stm, PdfDocumentOpenMode.InformationOnly);
                ReadXMPMetadata(doc);
                if (doc.Info.Title != string.Empty)
                {
                    FoundMetaData.Title = Functions.ToPlainText(doc.Info.Title);
                    if (Uri.IsWellFormedUriString(doc.Info.Title, UriKind.Absolute))
                    {
                        FoundPaths.AddUniqueItem(PathAnalysis.CleanPath(doc.Info.Title), true);
                    }
                }
                if (doc.Info.Subject != string.Empty)
                {
                    FoundMetaData.Subject = Functions.ToPlainText(doc.Info.Subject);
                }
                if (doc.Info.Author != string.Empty)
                {
                    FoundUsers.AddUniqueItem(Functions.ToPlainText(doc.Info.Author), true);
                }
                if (doc.Info.Keywords != string.Empty)
                {
                    FoundMetaData.Keywords = Functions.ToPlainText(doc.Info.Keywords);
                }
                if (doc.Info.Creator != string.Empty)
                {
                    string strSoftware = Analysis.ApplicationAnalysis.GetApplicationsFromString(Functions.ToPlainText(doc.Info.Creator));
                    if (strSoftware.Trim() != string.Empty)
                    {
                        if (!FoundMetaData.Applications.Items.Any(A => A.Name == strSoftware))
                        {
                            FoundMetaData.Applications.Items.Add(new ApplicationsItem(strSoftware));
                        }
                    }
                    //No se ha localizado ninguna aplicación conocida, aun así mostrar la aplicación encontrada
                    else
                    {
                        if (Functions.ToPlainText(doc.Info.Creator).Trim() != string.Empty && !FoundMetaData.Applications.Items.Any(A => A.Name == Functions.ToPlainText(doc.Info.Creator).Trim()))
                        {
                            FoundMetaData.Applications.Items.Add(new ApplicationsItem(Functions.ToPlainText(doc.Info.Creator).Trim()));
                        }
                    }
                }
                if (doc.Info.Producer != string.Empty)
                {
                    string strSoftware = Analysis.ApplicationAnalysis.GetApplicationsFromString(Functions.ToPlainText(doc.Info.Producer));
                    if (strSoftware.Trim() != string.Empty)
                    {
                        if (!FoundMetaData.Applications.Items.Any(A => A.Name == strSoftware))
                        {
                            FoundMetaData.Applications.Items.Add(new ApplicationsItem(strSoftware));
                        }
                    }
                    //No se ha localizado ninguna aplicación conocida, aun así mostrar la aplicación encontrada
                    else
                    {
                        if (Functions.ToPlainText(doc.Info.Producer).Trim() != string.Empty && !FoundMetaData.Applications.Items.Any(A => A.Name == Functions.ToPlainText(doc.Info.Producer).Trim()))
                        {
                            FoundMetaData.Applications.Items.Add(new ApplicationsItem(Functions.ToPlainText(doc.Info.Producer).Trim()));
                        }
                    }
                }
                try
                {
                    if (doc.Info.CreationDate != DateTime.MinValue)
                    {
                        FoundDates.CreationDateSpecified = true;
                        FoundDates.CreationDate          = doc.Info.CreationDate;
                    }
                }
                catch (InvalidCastException)
                {
                }

                try
                {
                    if (doc.Info.ModificationDate != DateTime.MinValue)
                    {
                        FoundDates.ModificationDateSpecified = true;
                        FoundDates.ModificationDate          = doc.Info.ModificationDate;
                    }
                }
                catch (InvalidCastException)
                {
                }

                //Busca path y links binariamente
                BinarySearchPaths(stm);
                BinarySearchLinks(stm);

                foreach (PathsItem ri in FoundPaths.Items)
                {
                    //Busca usuarios dentro de la ruta
                    string strUser = PathAnalysis.ExtractUserFromPath(ri.Path);
                    FoundUsers.AddUniqueItem(strUser, ri.IsComputerFolder);
                }
                //También busca el software en el título solo en los pdf, solo lo añade si es software conocido
                if (!String.IsNullOrEmpty(this.FoundMetaData.Title))
                {
                    string strSoftware = Analysis.ApplicationAnalysis.GetApplicationsFromString(this.FoundMetaData.Title);
                    if (strSoftware != string.Empty && !FoundMetaData.Applications.Items.Any(A => A.Name == strSoftware))
                    {
                        FoundMetaData.Applications.Items.Add(new ApplicationsItem(strSoftware));
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
            finally
            {
                if (doc != null)
                {
                    doc.Dispose();
                }
            }
        }
Beispiel #13
0
        /// <summary>
        /// Extrae los metadatos del documento
        /// </summary>
        public override FileMetadata AnalyzeFile()
        {
            try
            {
                this.foundMetadata = new FileMetadata();
                using (PdfDocument doc = PdfReader.Open(this.fileStream, PdfDocumentOpenMode.InformationOnly))
                {
                    ReadXMPMetadata(doc);
                    if (doc.Info.Title != string.Empty)
                    {
                        this.foundMetadata.Title = Functions.ToPlainText(doc.Info.Title);
                        if (Uri.IsWellFormedUriString(doc.Info.Title, UriKind.Absolute))
                        {
                            this.foundMetadata.Add(new Diagrams.Path(PathAnalysis.CleanPath(doc.Info.Title), true));
                        }
                    }

                    if (doc.Info.Subject != string.Empty)
                    {
                        this.foundMetadata.Subject = Functions.ToPlainText(doc.Info.Subject);
                    }
                    if (doc.Info.Author != string.Empty)
                    {
                        this.foundMetadata.Add(new User(Functions.ToPlainText(doc.Info.Author), true));
                    }
                    if (doc.Info.Keywords != string.Empty)
                    {
                        this.foundMetadata.Keywords = Functions.ToPlainText(doc.Info.Keywords);
                    }

                    if (doc.Info.Creator != string.Empty)
                    {
                        string strSoftware = ApplicationAnalysis.GetApplicationsFromString(Functions.ToPlainText(doc.Info.Creator));
                        if (strSoftware.Trim() != string.Empty)
                        {
                            this.foundMetadata.Add(new Application(strSoftware));
                        }
                        //No se ha localizado ninguna aplicación conocida, aun así mostrar la aplicación encontrada
                        else if (!String.IsNullOrWhiteSpace(Functions.ToPlainText(doc.Info.Creator)))
                        {
                            this.foundMetadata.Add(new Application(Functions.ToPlainText(doc.Info.Creator).Trim()));
                        }
                    }

                    if (!String.IsNullOrWhiteSpace(doc.Info.Producer))
                    {
                        string strSoftware = ApplicationAnalysis.GetApplicationsFromString(Functions.ToPlainText(doc.Info.Producer));
                        if (!String.IsNullOrWhiteSpace(strSoftware))
                        {
                            this.foundMetadata.Add(new Application(strSoftware));
                        }
                        //No se ha localizado ninguna aplicación conocida, aun así mostrar la aplicación encontrada
                        else if (!String.IsNullOrWhiteSpace(Functions.ToPlainText(doc.Info.Producer)))
                        {
                            this.foundMetadata.Add(new Application(Functions.ToPlainText(doc.Info.Producer).Trim()));
                        }
                    }

                    try
                    {
                        if (doc.Info.CreationDate != DateTime.MinValue)
                        {
                            this.foundMetadata.Dates.CreationDate = doc.Info.CreationDate;
                        }
                    }
                    catch (InvalidCastException)
                    {
                    }

                    try
                    {
                        if (doc.Info.ModificationDate != DateTime.MinValue)
                        {
                            this.foundMetadata.Dates.ModificationDate = doc.Info.ModificationDate;
                        }
                    }
                    catch (InvalidCastException)
                    {
                    }
                }

                SearchPathsLinksAndEmails(this.fileStream);

                //Find users in paths
                foreach (Diagrams.Path path in this.foundMetadata.Paths)
                {
                    string strUser = PathAnalysis.ExtractUserFromPath(path.Value);
                    this.foundMetadata.Add(new User(strUser, path.IsComputerFolder));
                }

                //Also search software in the title (only pdf). It is added only if the software is known.
                if (!String.IsNullOrEmpty(foundMetadata.Title))
                {
                    string strSoftware = ApplicationAnalysis.GetApplicationsFromString(foundMetadata.Title);
                    if (!String.IsNullOrWhiteSpace(strSoftware))
                    {
                        this.foundMetadata.Add(new Application(strSoftware));
                    }
                }
            }
            catch (PdfReaderException ex)
            { }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
            finally
            {
                if (foundMetadata == null)
                {
                    this.foundMetadata = new FileMetadata();
                }

                if (fileStream != null)
                {
                    this.fileStream.Dispose();
                }
            }
            return(this.foundMetadata);
        }