Example #1
0
 private void GetPrinters(OleDocument doc)
 {
     using (Stream WordDocument = doc.OpenStream("WordDocument"))
     {
         if (WordDocument == null)
         {
             return;
         }
         BinaryReader br = new BinaryReader(WordDocument);
         WordDocument.Seek(0xB, SeekOrigin.Begin);
         Byte tipo = br.ReadByte();
         WordDocument.Seek(0x172, SeekOrigin.Begin);
         UInt32 dir = br.ReadUInt32();
         UInt32 tam = br.ReadUInt32();
         if (tam > 0)
         {
             Stream table           = doc.OpenStream((tipo & 2) == 2 ? "1Table" : "0Table");
             Byte[] DriverImpresora = new Byte[tam];
             table.Seek(dir, SeekOrigin.Begin);
             table.Read(DriverImpresora, 0, (int)tam);
             FoundPrinters.AddUniqueItem(Functions.FilterPrinter(Encoding.Default.GetString(DriverImpresora).Replace("\0", "")));
             table.Close();
         }
     }
 }
Example #2
0
 void Handler_OnFoundPrinter(LinkOS.Plugin.Abstractions.IDiscoveryHandler handler, LinkOS.Plugin.Abstractions.IDiscoveredPrinter discoveredPrinter)
 {
     if (!FoundPrinters.Any(x => x.IpAddress.Equals(discoveredPrinter.Address, StringComparison.OrdinalIgnoreCase)))
     {
         FoundPrinters.Add(new FoundPrinter {
             IpAddress = discoveredPrinter.Address
         });
     }
 }
Example #3
0
        public override void analyzeFile()
        {
            try
            {
                if (IsWPD(stm))
                {
                    long         entryPoint = 0;
                    MetadataType tipo;
                    while ((entryPoint = EntryPointString(stm, out tipo)) > -1)
                    {
                        stm.Seek(entryPoint + 2, SeekOrigin.Begin);

                        var aux = ReadBinaryString16(stm);
                        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"))
                            {
                                FoundPrinters.AddUniqueItem(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"))
                            {
                                FoundMetaData.Applications.Items.Add(new ApplicationsItem(Functions.FilterPrinter(Analysis.ApplicationAnalysis.GetApplicationsFromString(aux))));
                            }
                        }
                        else
                        {
                            var strPath = Functions.GetPathFolder(aux);
                            if (!PathAnalysis.IsValidPath(strPath))
                            {
                                continue;
                            }
                            FoundPaths.AddUniqueItem(PathAnalysis.CleanPath(strPath), true);
                            var strUser = PathAnalysis.ExtractUserFromPath(strPath);
                            if (!string.IsNullOrEmpty(strUser))
                            {
                                FoundUsers.AddUniqueItem(strUser, true);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
            }
        }
Example #4
0
        public LinkOsVm()
        {
            this.Title = "Link-OS";

            _handler = LinkOS.Plugin.DiscoveryHandlerFactory.Current.GetInstance();

            _foundPrinters = new ObservableCollection <FoundPrinter>();

            LoadPrinters =
                new Command(
                    async _ => {
                try {
                    FoundPrinters.Clear();
                    SearchingForPrinters     = true;
                    CurrentStatus            = "Searching For Printers...";
                    _handler.OnFoundPrinter += Handler_OnFoundPrinter;
                    await Task.Run(() => LinkOS.Plugin.NetworkDiscoverer.Current.FindPrinters(_handler));
                } catch (Exception ex) {
                    System.Diagnostics.Debug.WriteLine(ex);
                } finally {
                    _handler.OnFoundPrinter += Handler_OnFoundPrinter;
                    SearchingForPrinters     = false;
                    CurrentStatus            = "Finished Searching...";
                }
            },
                    _ => !SearchingForPrinters);

            PrintSample =
                new Command(
                    _ => {
                var selectedPrinters = FoundPrinters.Where(x => x.Selected).ToList();

                foreach (var printer in selectedPrinters)
                {
                    var conn = LinkOS.Plugin.ConnectionBuilder.Current.Build(printer.IpAddress);
                    try {
                        conn.Open();
                        conn.Write(Encoding.UTF8.GetBytes(SampleZpl));
                    } catch (Exception ex) {
                        CurrentStatus = ex.Message;
                    }
                    finally {
                        conn.Close();
                    }
                }
            });
        }
Example #5
0
 /// <summary>
 /// Extract metadata.
 /// </summary>
 public override void analyzeFile()
 {
     try
     {
         using (StreamReader sr = new StreamReader(stm))
         {
             String sRead = sr.ReadToEnd();
             foreach (Match m in Regex.Matches(sRead, @"@([a-z]:|\\)\\(([a-z0-9\s\-_\$&()ñÇ/n/r]+)\\)*[a-z0-9\s,;.\-_\$%&()=ñ{}Ç/n/r+@]+", RegexOptions.IgnoreCase))
             {
                 String path = m.Value.Trim();
                 path = path.Substring(1);
                 FoundPaths.AddUniqueItem(PathAnalysis.CleanPath(path), true);
             }
             foreach (Match m in Regex.Matches(sRead, @"winspool\0([a-z]:|\\)\\(([a-z0-9\s\-_\$&()ñÇ/n/r]+)\\)*[a-z0-9\s,;.\-_\$%&()=ñ{}Ç/n/r+@]+", RegexOptions.IgnoreCase))
             {
                 String printer = m.Value.Trim();
                 printer = printer.Substring(9);
                 FoundPrinters.AddUniqueItem(Functions.FilterPrinter(printer));
             }
             foreach (Match m in Regex.Matches(sRead, @"<x:xmpmeta[^\0]*</x:xmpmeta>", RegexOptions.IgnoreCase))
             {
                 String xmp = m.Value.Trim();
                 ReadXMPMetadata(xmp);
             }
             foreach (Match m in Regex.Matches(sRead, @"<rdf:RDF[^\0]*</rdf:RDF>", RegexOptions.IgnoreCase))
             {
                 String xmp = m.Value.Trim();
                 ReadXMPMetadata(xmp);
             }
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.ToString());
     }
     finally
     {
         this.stm.Close();
         this.stm = null;
     }
 }
Example #6
0
 public override void analyzeFile()
 {
     try
     {
         using (Package pZip = Package.Open(stm))
         {
             Uri uriFile = new Uri("/docProps/core.xml", UriKind.Relative);
             if (pZip.PartExists(uriFile))
             {
                 PackagePart pDocument = pZip.GetPart(uriFile);
                 using (Stream stmDoc = pDocument.GetStream(FileMode.Open, FileAccess.Read))
                 {
                     analizeFileCore(stmDoc);
                 }
             }
             uriFile = new Uri("/docProps/app.xml", UriKind.Relative);
             if (pZip.PartExists(uriFile))
             {
                 PackagePart pDocument = pZip.GetPart(uriFile);
                 using (Stream stmDoc = pDocument.GetStream(FileMode.Open, FileAccess.Read))
                 {
                     analizeFileApp(stmDoc);
                 }
             }
             //Control de versiones
             if (strExtlo == ".docx")
             {
                 uriFile = new Uri("/word/document.xml", UriKind.Relative);
                 if (pZip.PartExists(uriFile))
                 {
                     PackagePart pDocument = pZip.GetPart(uriFile);
                     using (Stream stmDoc = pDocument.GetStream(FileMode.Open, FileAccess.Read))
                     {
                         analizeFileDocument(stmDoc);
                     }
                 }
                 //Consulta el fichero settings para recuperar el idioma del documento
                 if (FoundMetaData.Language == string.Empty)
                 {
                     uriFile = new Uri("/word/settings.xml", UriKind.Relative);
                     if (pZip.PartExists(uriFile))
                     {
                         PackagePart pDocument = pZip.GetPart(uriFile);
                         using (Stream stmDoc = pDocument.GetStream(FileMode.Open, FileAccess.Read))
                         {
                             analizeFileSettings(stmDoc);
                         }
                     }
                 }
                 //Consulta el fichero document.xml.rels para obtener los links del documento
                 uriFile = new Uri("/word/_rels/document.xml.rels", UriKind.Relative);
                 if (pZip.PartExists(uriFile))
                 {
                     PackagePart pDocument = pZip.GetPart(uriFile);
                     using (Stream stmDoc = pDocument.GetStream(FileMode.Open, FileAccess.Read))
                     {
                         analizeLinks(stmDoc);
                     }
                 }
             }
             //Obtiene el nombre de las impresoras y los links de los documentos xlsx
             else if (strExtlo == ".xlsx")
             {
                 List <Uri> lstFiles = new List <Uri>();
                 foreach (PackagePart pp in pZip.GetParts())
                 {
                     if (pp.Uri.ToString().StartsWith("/xl/printerSettings/printerSettings"))
                     {
                         PackagePart pDocument = pZip.GetPart(pp.Uri);
                         if (pDocument != null)
                         {
                             char[] name = new char[32];
                             using (StreamReader sr = new StreamReader(pDocument.GetStream(FileMode.Open, FileAccess.Read), Encoding.Unicode))
                             {
                                 sr.Read(name, 0, 32);
                             }
                             FoundPrinters.AddUniqueItem(Functions.FilterPrinter((new string(name).Replace("\0", ""))));
                         }
                     }
                     if (pp.Uri.ToString().StartsWith("/xl/worksheets/_rels/"))
                     {
                         PackagePart pDocument = pZip.GetPart(pp.Uri);
                         using (Stream stmDoc = pDocument.GetStream(FileMode.Open, FileAccess.Read))
                         {
                             analizeLinks(stmDoc);
                         }
                     }
                 }
             }
             else if (strExtlo == ".pptx")
             {
                 List <Uri> lstFiles = new List <Uri>();
                 foreach (PackagePart pp in pZip.GetParts())
                 {
                     if (pp.Uri.ToString().StartsWith("/ppt/slides/_rels/"))
                     {
                         PackagePart pDocument = pZip.GetPart(pp.Uri);
                         using (Stream stmDoc = pDocument.GetStream(FileMode.Open, FileAccess.Read))
                         {
                             analizeLinks(stmDoc);
                         }
                     }
                 }
             }
             //Extraer información EXIF de cada imagen
             foreach (PackagePart pp in pZip.GetParts())
             {
                 string strFileName   = pp.Uri.ToString();
                 string strFileNameLo = strFileName.ToLower();
                 //Filtro que se queda con todas las imagenes *.jpg y *.jpeg de las 3 posibles carpetas
                 if ((strFileNameLo.StartsWith("/word/media/") ||
                      strFileNameLo.StartsWith("/ppt/media/") ||
                      strFileNameLo.StartsWith("/xl/media/")) &&
                     (strFileNameLo.EndsWith(".jpg") ||
                      strFileNameLo.EndsWith(".jpeg")))
                 {
                     EXIFDocument eDoc = new EXIFDocument(pp.GetStream(FileMode.Open, FileAccess.Read), Path.GetExtension(strFileNameLo));
                     eDoc.analyzeFile();
                     dicPictureEXIF.Add(Path.GetFileName(strFileName), eDoc);
                     //Copiamos los metadatos sobre usuarios y Applications de la imagen al documento
                     foreach (UserItem uiEXIF in eDoc.FoundUsers.Items)
                     {
                         FoundUsers.AddUniqueItem(uiEXIF.Name, false, uiEXIF.Notes);
                     }
                     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()));
                         }
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e.ToString());
     }
 }
Example #7
0
        private void analizeFileSettings(Stream stm)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.XmlResolver = null;
                doc.Load(stm);
                XmlNodeList xnl = doc.GetElementsByTagName("config:config-item");
                if (xnl != null)
                {
                    foreach (XmlNode xn in xnl)
                    {
                        if (xn.Attributes.GetNamedItem("config:name").Value == "PrinterName")
                        {
                            if (xn.HasChildNodes)
                            {
                                FoundPrinters.AddUniqueItem(Functions.FilterPrinter(xn.FirstChild.Value));
                            }
                            else if (xn.Attributes.GetNamedItem("config:name").Value == "CurrentDatabaseDataSource")
                            {
                                if (xn.HasChildNodes)
                                {
                                    FoundMetaData.DataBase = xn.FirstChild.Value;
                                }
                            }

                            /* else if (xn.Attributes.GetNamedItem("config:name").Value == "PrintFaxName")
                             * {
                             *   if (xn.HasChildNodes)
                             *       escritor("Fax: " + xn.FirstChild.Value, objeto);
                             * }
                             * else if (xn.Attributes.GetNamedItem("config:name").Value == "CurrentDatabaseCommandType")
                             * {
                             *   if (!resumen)
                             *       if (xn.HasChildNodes && xn.FirstChild.Value != "0")
                             *           escritor("Current Database Command Type: " + xn.FirstChild.Value, objeto);
                             * }
                             * else if (xn.Attributes.GetNamedItem("config:name").Value == "CurrentDatabaseCommand")
                             * {
                             *   if (!resumen)
                             *       if (xn.HasChildNodes)
                             *           escritor("Current Database Command: " + xn.FirstChild.Value, objeto);
                             * }*/
                            //Solo aparecen en ficheros ODP y ODG file:///
                            else if (xn.Attributes.GetNamedItem("config:name").Value == "ColorTableURL")
                            {
                                if (xn.HasChildNodes)
                                {
                                    if (PathAnalysis.CleanPath(xn.FirstChild.Value) != "$(user)/config/")
                                    {
                                        FoundPaths.AddUniqueItem(PathAnalysis.CleanPath(xn.FirstChild.Value), true);
                                    }
                                }
                            }
                            else if (xn.Attributes.GetNamedItem("config:name").Value == "BitmapTableURL")
                            {
                                if (xn.HasChildNodes)
                                {
                                    if (PathAnalysis.CleanPath(xn.FirstChild.Value) != "$(user)/config/")
                                    {
                                        FoundPaths.AddUniqueItem(PathAnalysis.CleanPath(xn.FirstChild.Value), true);
                                    }
                                }
                            }
                            else if (xn.Attributes.GetNamedItem("config:name").Value == "DashTableURL")
                            {
                                if (xn.HasChildNodes)
                                {
                                    if (PathAnalysis.CleanPath(xn.FirstChild.Value) != "$(user)/config/")
                                    {
                                        FoundPaths.AddUniqueItem(PathAnalysis.CleanPath(xn.FirstChild.Value), true);
                                    }
                                }
                            }
                            else if (xn.Attributes.GetNamedItem("config:name").Value == "GradientTableURL")
                            {
                                if (xn.HasChildNodes)
                                {
                                    if (PathAnalysis.CleanPath(xn.FirstChild.Value) != "$(user)/config/")
                                    {
                                        FoundPaths.AddUniqueItem(PathAnalysis.CleanPath(xn.FirstChild.Value), true);
                                    }
                                }
                            }
                            else if (xn.Attributes.GetNamedItem("config:name").Value == "HatchTableURL")
                            {
                                if (xn.HasChildNodes)
                                {
                                    if (PathAnalysis.CleanPath(xn.FirstChild.Value) != "$(user)/config/")
                                    {
                                        FoundPaths.AddUniqueItem(PathAnalysis.CleanPath(xn.FirstChild.Value), true);
                                    }
                                }
                            }
                            else if (xn.Attributes.GetNamedItem("config:name").Value == "LineEndTableURL")
                            {
                                if (xn.HasChildNodes)
                                {
                                    if (PathAnalysis.CleanPath(xn.FirstChild.Value) != "$(user)/config/")
                                    {
                                        FoundPaths.AddUniqueItem(PathAnalysis.CleanPath(xn.FirstChild.Value), true);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(String.Format("Error reading file settings.xml ({0}).", e.ToString()));
            }
        }
Example #8
0
        private void GetPrintersInXls(OleDocument doc)
        {
            using (Stream Workbook = doc.OpenStream("Workbook"))
            {
                if (Workbook == null)
                {
                    return;
                }
                BinaryReader br = new BinaryReader(Workbook);
                Workbook.Seek(0, SeekOrigin.Begin);
                while (Workbook.Position <= Workbook.Length - 2)
                {
                    try
                    {
                        Int16 Tipo = br.ReadInt16();
                        Int16 Len  = br.ReadInt16();
                        if (Len < 0)
                        {
                            break;
                        }
                        if (Tipo == 0x4D)
                        {
                            long PosOri = Workbook.Position;
                            if (br.ReadInt16() == 0)
                            {
                                String PrinterName = Encoding.Unicode.GetString(br.ReadBytes(32 * 2)).Replace('\0', ' ');
                                br.ReadInt16();
                                br.ReadInt16();
                                Int16 StructSize = br.ReadInt16();
                                Int16 DriverSize = br.ReadInt16();

                                if (DriverSize != 0)
                                {
                                    Workbook.Seek(StructSize - (8 + 64), SeekOrigin.Current);
                                    Byte[] Driver          = br.ReadBytes(DriverSize);
                                    String ImpresoraDriver = Functions.ExtractPrinterFromBytes(Driver);
                                    if (!string.IsNullOrEmpty(ImpresoraDriver.Trim()))
                                    {
                                        FoundPrinters.AddUniqueItem(Functions.FilterPrinter(ImpresoraDriver.Replace("\0", "")));
                                    }
                                    else
                                    {
                                        FoundPrinters.AddUniqueItem(Functions.FilterPrinter(PrinterName.Replace("\0", "")));
                                    }
                                }
                                else
                                {
                                    FoundPrinters.AddUniqueItem(Functions.FilterPrinter(PrinterName.Replace("\0", "")));
                                }
                            }
                            Workbook.Position = PosOri;
                        }
                        Workbook.Seek(Len, SeekOrigin.Current);
                    }
                    catch
                    {
                        break;
                    }
                }
            }
        }