Beispiel #1
0
        /// <summary>
        /// Get the content-detectable protections associated with a single path
        /// </summary>
        /// <param name="file">Path to the file to scan</param>
        /// <returns>Dictionary of list of strings representing the found protections</returns>
        private Dictionary <string, List <string> > GetInternalProtections(string file)
        {
            // Quick sanity check before continuing
            if (!File.Exists(file))
            {
                return(null);
            }

            // Initialze the protections found
            var protections = new Dictionary <string, List <string> >();

            // Get the extension for certain checks
            string extension = Path.GetExtension(file).ToLower().TrimStart('.');

            // Open the file and begin scanning
            using (FileStream fs = File.OpenRead(file))
            {
                // Get the first 16 bytes for matching
                byte[] magic = new byte[16];
                try
                {
                    fs.Read(magic, 0, 16);
                    fs.Seek(-16, SeekOrigin.Current);
                }
                catch
                {
                    // We don't care what the issue was, we can't read or seek the file
                    return(null);
                }

                #region Non-Archive File Types

                // Executable
                if (ScanAllFiles || new Executable().ShouldScan(magic))
                {
                    var subProtections = new Executable().Scan(this, fs, file);
                    Utilities.AppendToDictionary(protections, subProtections);
                }

                // Text-based files
                if (ScanAllFiles || new Textfile().ShouldScan(magic, extension))
                {
                    var subProtections = new Textfile().Scan(this, fs, file);
                    Utilities.AppendToDictionary(protections, subProtections);
                }

                #endregion

                #region Archive File Types

                // If we're scanning archives, we have a few to try out
                if (ScanArchives)
                {
                    // 7-Zip archive
                    if (new SevenZip().ShouldScan(magic))
                    {
                        var subProtections = new SevenZip().Scan(this, fs, file);
                        Utilities.PrependToKeys(subProtections, file);
                        Utilities.AppendToDictionary(protections, subProtections);
                    }

                    // BFPK archive
                    if (new BFPK().ShouldScan(magic))
                    {
                        var subProtections = new BFPK().Scan(this, fs, file);
                        Utilities.PrependToKeys(subProtections, file);
                        Utilities.AppendToDictionary(protections, subProtections);
                    }

                    // BZip2
                    if (new BZip2().ShouldScan(magic))
                    {
                        var subProtections = new BZip2().Scan(this, fs, file);
                        Utilities.PrependToKeys(subProtections, file);
                        Utilities.AppendToDictionary(protections, subProtections);
                    }

                    // GZIP
                    if (new GZIP().ShouldScan(magic))
                    {
                        var subProtections = new GZIP().Scan(this, fs, file);
                        Utilities.PrependToKeys(subProtections, file);
                        Utilities.AppendToDictionary(protections, subProtections);
                    }

                    // InstallShield Cabinet
                    if (file != null && new InstallShieldCAB().ShouldScan(magic))
                    {
                        var subProtections = new InstallShieldCAB().Scan(this, file);
                        Utilities.PrependToKeys(subProtections, file);
                        Utilities.AppendToDictionary(protections, subProtections);
                    }

                    // Microsoft Cabinet
                    if (file != null && new MicrosoftCAB().ShouldScan(magic))
                    {
                        var subProtections = new MicrosoftCAB().Scan(this, file);
                        Utilities.PrependToKeys(subProtections, file);
                        Utilities.AppendToDictionary(protections, subProtections);
                    }

                    // MSI
                    if (file != null && new MSI().ShouldScan(magic))
                    {
                        var subProtections = new MSI().Scan(this, file);
                        Utilities.PrependToKeys(subProtections, file);
                        Utilities.AppendToDictionary(protections, subProtections);
                    }

                    // MPQ archive
                    if (file != null && new MPQ().ShouldScan(magic))
                    {
                        var subProtections = new MPQ().Scan(this, file);
                        Utilities.PrependToKeys(subProtections, file);
                        Utilities.AppendToDictionary(protections, subProtections);
                    }

                    // PKZIP archive (and derivatives)
                    if (new PKZIP().ShouldScan(magic))
                    {
                        var subProtections = new PKZIP().Scan(this, fs, file);
                        Utilities.PrependToKeys(subProtections, file);
                        Utilities.AppendToDictionary(protections, subProtections);
                    }

                    // RAR archive
                    if (new RAR().ShouldScan(magic))
                    {
                        var subProtections = new RAR().Scan(this, fs, file);
                        Utilities.PrependToKeys(subProtections, file);
                        Utilities.AppendToDictionary(protections, subProtections);
                    }

                    // Tape Archive
                    if (new TapeArchive().ShouldScan(magic))
                    {
                        var subProtections = new TapeArchive().Scan(this, fs, file);
                        Utilities.PrependToKeys(subProtections, file);
                        Utilities.AppendToDictionary(protections, subProtections);
                    }

                    // Valve archive formats
                    if (file != null && new Valve().ShouldScan(magic))
                    {
                        var subProtections = new Valve().Scan(this, file);
                        Utilities.PrependToKeys(subProtections, file);
                        Utilities.AppendToDictionary(protections, subProtections);
                    }

                    // XZ
                    if (new XZ().ShouldScan(magic))
                    {
                        var subProtections = new XZ().Scan(this, fs, file);
                        Utilities.PrependToKeys(subProtections, file);
                        Utilities.AppendToDictionary(protections, subProtections);
                    }
                }

                #endregion
            }

            // Clear out any empty keys
            Utilities.ClearEmptyKeys(protections);

            return(protections);
        }
        }//Encode()

        /// <summary>
        /// Encodes the raw data into binary form representing bars and spaces.
        /// </summary>
        internal Image Encode()
        {
            DateTime dtStartTime = DateTime.Now;

            //make sure there is something to encode
            if (Raw_Data.Trim() == "")
            {
                throw new System.Exception("EENCODE-1: Input data not allowed to be blank.");
            }

            if (this.EncodedType == EncodingType.UNSPECIFIED)
            {
                throw new System.Exception("EENCODE-2: Symbology type not allowed to be unspecified.");
            }

            this.Encoded_Value = "";
            this._Country_Assigning_Manufacturer_Code = "N/A";

            IBarcode ibarcode;

            switch (this.Encoded_Type)
            {
            case EncodingType.UCC12:
            case EncodingType.UPCA:     //Encode_UPCA();
                ibarcode = new UPCA(Raw_Data);
                break;

            case EncodingType.UCC13:
            case EncodingType.EAN13:     //Encode_EAN13();
                ibarcode = new EAN13(Raw_Data);
                break;

            case EncodingType.Interleaved2of5:     //Encode_Interleaved2of5();
                ibarcode = new Interleaved2of5(Raw_Data);
                break;

            case EncodingType.Industrial2of5:
            case EncodingType.Standard2of5:     //Encode_Standard2of5();
                ibarcode = new Standard2of5(Raw_Data);
                break;

            case EncodingType.LOGMARS:
            case EncodingType.CODE39:     //Encode_Code39();
                ibarcode = new Code39(Raw_Data);
                break;

            case EncodingType.CODE39Extended:
                ibarcode = new Code39(Raw_Data, true);
                break;

            case EncodingType.Codabar:     //Encode_Codabar();
                ibarcode = new Codabar(Raw_Data);
                break;

            case EncodingType.PostNet:     //Encode_PostNet();
                ibarcode = new Postnet(Raw_Data);
                break;

            case EncodingType.ISBN:
            case EncodingType.BOOKLAND:     //Encode_ISBN_Bookland();
                ibarcode = new ISBN(Raw_Data);
                break;

            case EncodingType.JAN13:     //Encode_JAN13();
                ibarcode = new JAN13(Raw_Data);
                break;

            case EncodingType.UPC_SUPPLEMENTAL_2DIGIT:     //Encode_UPCSupplemental_2();
                ibarcode = new UPCSupplement2(Raw_Data);
                break;

            case EncodingType.MSI_Mod10:
            case EncodingType.MSI_2Mod10:
            case EncodingType.MSI_Mod11:
            case EncodingType.MSI_Mod11_Mod10:
            case EncodingType.Modified_Plessey:     //Encode_MSI();
                ibarcode = new MSI(Raw_Data, Encoded_Type);
                break;

            case EncodingType.UPC_SUPPLEMENTAL_5DIGIT:     //Encode_UPCSupplemental_5();
                ibarcode = new UPCSupplement5(Raw_Data);
                break;

            case EncodingType.UPCE:     //Encode_UPCE();
                ibarcode = new UPCE(Raw_Data);
                break;

            case EncodingType.EAN8:     //Encode_EAN8();
                ibarcode = new EAN8(Raw_Data);
                break;

            case EncodingType.USD8:
            case EncodingType.CODE11:     //Encode_Code11();
                ibarcode = new Code11(Raw_Data);
                break;

            case EncodingType.CODE128:     //Encode_Code128();
                ibarcode = new Code128(Raw_Data);
                break;

            case EncodingType.CODE128A:
                ibarcode = new Code128(Raw_Data, Code128.TYPES.A);
                break;

            case EncodingType.CODE128B:
                ibarcode = new Code128(Raw_Data, Code128.TYPES.B);
                break;

            case EncodingType.CODE128C:
                ibarcode = new Code128(Raw_Data, Code128.TYPES.C);
                break;

            case EncodingType.ITF14:
                ibarcode = new ITF14(Raw_Data);
                break;

            case EncodingType.CODE93:
                ibarcode = new Code93(Raw_Data);
                break;

            default: throw new System.Exception("EENCODE-2: Unsupported encoding type specified.");
            }//switch

            this.Encoded_Value  = ibarcode.Encoded_Value;
            this.Raw_Data       = ibarcode.RawData;
            this.Formatted_Data = ibarcode.FormattedData;
            this._EncodingTime  = ((TimeSpan)(DateTime.Now - dtStartTime)).TotalMilliseconds;

            _Encoded_Image = (Image)Generate_Image();

            _XML = GetXML();

            return(EncodedImage);
        }//Encode
Beispiel #3
0
 public override char CalcCheckChar(char[] acText, int cc)
 {
     return(MSI.MsiCheckCharModulo11(acText, cc));
 }
Beispiel #4
0
 internal HttpListener(X509Certificate certificate, IMonoTlsProvider tlsProvider, MSI.MonoTlsSettings tlsSettings)
     : this()
 {
     this.certificate = certificate;
     this.tlsProvider = tlsProvider;
     this.tlsSettings = tlsSettings;
 }
Beispiel #5
0
 internal IMonoSslStream CreateSslStream(Stream innerStream, bool ownsStream, MSI.MonoRemoteCertificateValidationCallback callback)
 {
     lock (registry)
     {
         if (tlsProvider == null)
             tlsProvider = MonoTlsProviderFactory.GetProviderInternal();
         if (tlsSettings == null)
             tlsSettings = MSI.MonoTlsSettings.CopyDefaultSettings();
         if (tlsSettings.RemoteCertificateValidationCallback == null)
             tlsSettings.RemoteCertificateValidationCallback = callback;
         return tlsProvider.CreateSslStream(innerStream, ownsStream, tlsSettings);
     }
 }
Beispiel #6
0
 public override char Calc2ndCheckChar(char[] acText, int cc)
 {
     return(MSI.MsiCheckCharModulo1010Second(acText, cc));
 }
Beispiel #7
0
        private void btnImprimirCodigoBarras_Click(object sender, System.EventArgs e)
        {
            CodigoBarras codigoBarras;
            switch (cboCodigoBarras.SelectedIndex)
            {
                case 0: codigoBarras = new EAN8(); break;
                case 1: codigoBarras = new EAN13();break;
                case 2: codigoBarras = new CODABAR();break;
                case 3: codigoBarras = new CODE39();break;
                case 4: codigoBarras = new CODE93();break;
                case 5: codigoBarras = new CODE128();break;
                case 6: codigoBarras = new ISBN();break;
                case 7: codigoBarras = new ITF();break;
                case 8: codigoBarras = new MSI();break;
                case 9: codigoBarras = new PDF417();break;
                case 10: codigoBarras = new PLESSEY();break;
                case 11: codigoBarras = new UPCA();break;
                case 12: codigoBarras = new UPCE();break;
                default: codigoBarras = new EAN13();break;
            }

            codigoBarras.Codigo = txtCodigoBarras.Text;

            // fonte
            if (rbtFonteNormal.Checked)
            {
                codigoBarras.Fonte = CodigoBarras.FonteLegenda.Normal;
            }
            else
            {
                codigoBarras.Fonte = CodigoBarras.FonteLegenda.Condensada;
            }

            // largura das barras
            if (rbtFina.Checked)
            {
                codigoBarras.Largura = CodigoBarras.LarguraBarra.Fina;
            }
            else if(rbtMedia.Checked)
            {
                codigoBarras.Largura = CodigoBarras.LarguraBarra.Media;
            }
            else
            {
                codigoBarras.Largura = CodigoBarras.LarguraBarra.Grossa;
            }

            // posicao legenda
            if (rbtCaracteresAbaixoCodigo.Checked)
            {
                codigoBarras.Posicao = CodigoBarras.PosicaoLegenda.Abaixo;
            }
            else if(rbtCaracteresAcimaCodigo.Checked)
            {
                codigoBarras.Posicao = CodigoBarras.PosicaoLegenda.Acima;
            }
            else if(rbtCaracteresAcimaAbaixoCodigo.Checked)
            {
                codigoBarras.Posicao = CodigoBarras.PosicaoLegenda.AcimaAbaixo;
            }
            else
            {
                codigoBarras.Posicao = CodigoBarras.PosicaoLegenda.Nenhuma;
            }

            try
            {
                miniPrinter.Imprimir(codigoBarras);
            }
            catch (BematechException erro)
            {
                MessageBox.Show(erro.Message, "TestMiniPrinter", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #8
0
        private static string GetSymbology(string Data, Enums.Type EncodingType)
        {
            ISymbology SymbologyUsing = null;

            switch (EncodingType)
            {
            case Enums.Type.UCC12:
            case Enums.Type.UPCA:
                SymbologyUsing = new UPCA(Data);
                break;

            case Enums.Type.UCC13:
            case Enums.Type.EAN13:
                SymbologyUsing = new EAN13(Data);
                break;

            case Enums.Type.Interleaved2of5:
                SymbologyUsing = new Interleaved2of5(Data);
                break;

            case Enums.Type.Industrial2of5:
            case Enums.Type.Standard2of5:
                SymbologyUsing = new Standard2of5(Data);
                break;

            case Enums.Type.LOGMARS:
            case Enums.Type.CODE39:
                SymbologyUsing = new Code39(Data);
                break;

            case Enums.Type.CODE39Extended:
                SymbologyUsing = new Code39(Data);
                break;

            case Enums.Type.Codabar:
                SymbologyUsing = new Codabar(Data);
                break;

            case Enums.Type.PostNet:
                SymbologyUsing = new Postnet(Data);
                break;

            case Enums.Type.ISBN:
            case Enums.Type.BOOKLAND:
                SymbologyUsing = new ISBN(Data);
                break;

            case Enums.Type.JAN13:
                SymbologyUsing = new JAN13(Data);
                break;

            case Enums.Type.UPC_SUPPLEMENTAL_2DIGIT:
                SymbologyUsing = new UPCSupplement2(Data);
                break;

            case Enums.Type.MSI_Mod10:
            case Enums.Type.MSI_2Mod10:
            case Enums.Type.MSI_Mod11:
            case Enums.Type.MSI_Mod11_Mod10:
            case Enums.Type.Modified_Plessey:
                SymbologyUsing = new MSI(Data);
                break;

            case Enums.Type.UPC_SUPPLEMENTAL_5DIGIT:
                SymbologyUsing = new UPCSupplement5(Data);
                break;

            case Enums.Type.UPCE:
                SymbologyUsing = new UPCE(Data);
                break;

            case Enums.Type.EAN8:
                SymbologyUsing = new EAN8(Data);
                break;

            case Enums.Type.USD8:
            case Enums.Type.CODE11:
                SymbologyUsing = new Code11(Data);
                break;

            case Enums.Type.CODE128:
                SymbologyUsing = new Code128(Data);
                break;

            case Enums.Type.CODE128A:
                SymbologyUsing = new Code128A(Data);
                break;

            case Enums.Type.CODE128B:
                SymbologyUsing = new Code128B(Data);
                break;

            case Enums.Type.CODE128C:
                SymbologyUsing = new Code128C(Data);
                break;

            case Enums.Type.ITF14:
                SymbologyUsing = new ITF14(Data);
                break;

            case Enums.Type.CODE93:
                SymbologyUsing = new Code93(Data);
                break;

            case Enums.Type.TELEPEN:
                SymbologyUsing = new Telepen(Data);
                break;
            }
            return(SymbologyUsing.Encode());
        }