Recurity.Swf.SwfFile.Verify C# (CSharp) Method

Verify() public method

public Verify ( ) : bool
return bool
        public bool Verify()
        {
            //
            // Make sure that the FileAttributes Tag is the first (if any)
            //
            uint fileAttributesCnt = 0;
            // TODO : Check if TagHandlers not null
            for (int i = 0; i < TagHandlers.Count; i++)
            {
                if (TagHandlers[i].Tag.TagType == TagTypes.FileAttributes)
                {
                    if ((0 != i) && (this.Version < 8))
                    {
                        Log.Warn(this, "TAG FileAttributes not first in file, but at Tag #" + i.ToString());
                    }
                    fileAttributesCnt++;
                }
            }
            if (fileAttributesCnt > 1)
            {
                string msg = "Multiple FileAttributes Tags: " + fileAttributesCnt.ToString();

                if (!SwfFile.Configuration.AllowMultipleFileAttributes)
                {
                    Log.Error(this, msg);
                    return false;
                }
                else
                {
                    Log.Warn(this, msg);
                }
            }
            //
            // If the Swf version is 8 or higher, one FileAttributes Tag is required
            //
            if ((this.Version >= 8) && (fileAttributesCnt < 1))
            {
                if (SwfFile.Configuration.RequireFileAttributes)
                {
                    String s = String.Format("Swf version {0:d} requires FileAttributes Tag, but none was found", this.Version);
                    Log.Error(this, s);
                    return false;
                }
                else
                {
                    String s = String.Format("Swf version {0:d} requires FileAttributes Tag, but none was found - fixing it", this.Version);
                    Log.Warn(this, s);
                    this.FixFileAttributes();
                }
            }

            //
            // validate all Tags
            //
            bool result = true;

            for (int i = 0; i < this.TagCount; i++)
            {
                result = result && this[i].Verify();

                if (!result)
                {
                    //
                    // Terminate verification when it failed one Tag
                    //
                    String s = String.Format("Tag #{0:d} {1} failed verification", i, this[i].Tag.TagTypeName);
                    Log.Info(this, s);
                    break;
                }
            }

            // Fire VerficationCompleted event
            if (null != VerificationCompleted)
            {
                VerificationCompleted();
            }

            return result;
        }

Usage Example

Exemplo n.º 1
0
        /// <summary>
        /// Scans a single file
        /// </summary>
        /// <param name="s1">The input file name</param>
        /// <param name="s2">The output file name</param>
        private static void ScanSingle(string s1, string s2)
        {
            bool read = false;
            bool verified = false;

            try
            {
                FileInfo f = new FileInfo(s2);

                if (!Directory.Exists(f.DirectoryName))
                {
                    Directory.CreateDirectory(f.DirectoryName);
                }
            }
            catch (Exception e)
            {
                throw new DirectoryNotFoundException(e.Message);
            }

            SwfFile file = new SwfFile();

            try
            {
                using (FileStream fs = File.OpenRead(s1))
                {
                    Console.WriteLine(" Reading: " + s1);
                    file.Read(fs);
                    Console.WriteLine(" Reading successfull");
                    read = true;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(" Read error : " + e.Message + Environment.NewLine);
            }

            if (read)
            {
                Console.WriteLine(" Verifiying: " + s1);

                try
                {
                    file.Verify();
                    Console.WriteLine(" Verifiying successfull");
                    verified = true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(" Verifiy error : " + e.Message + Environment.NewLine);

                }
            }

            if (read && verified)
            {
                Console.WriteLine(" Writing: " + s2);

                try
                {
                    using (FileStream fs = File.OpenWrite(s2))
                    {
                        file.Write(fs);
                        Console.WriteLine(" Writing successfull" + Environment.NewLine);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(" Write error : " + e.Message + Environment.NewLine);
                }
            }
        }
All Usage Examples Of Recurity.Swf.SwfFile::Verify