Пример #1
0
        private static void LoadGlobalStringsNode(FileDefPattern pattern, XPathNodeIterator globalStrings)
        {
            while (globalStrings.MoveNext())
            {
                if (globalStrings.Current != null)
                {
                    string     innerText  = globalStrings.Current.Value.Trim();
                    ByteString byteString = new ByteString {
                        Data = new byte[innerText.Length]
                    };

                    for (int j = 0; j <= innerText.Length - 1; j++)
                    {
                        byteString.Data[j] = innerText[j] > 255 ? Convert.ToByte(0) : Convert.ToByte(innerText[j]);
                        if (byteString.Data[j] == 39)
                        {
                            byteString.Data[j] = 0;
                        }
                    }

                    Ba2Upper(ref byteString.Data);
                    pattern.GlobalStrings.Add(byteString);
                }
            }
        }
Пример #2
0
        private static void LoadFrontBlockNode(FileDefPattern pattern, XPathNodeIterator patterns)
        {
            while (patterns.MoveNext())
            {
                if (patterns.Current != null)
                {
                    SomePattern somePattern = new SomePattern {
                        Pos = int.Parse(patterns.Current.SelectSingleNode("Pos")?.Value.Trim() ?? "0")
                    };
                    string innerText = patterns.Current.SelectSingleNode("Bytes")?.Value.Trim();
                    if (innerText != null)
                    {
                        somePattern.Len     = innerText.Length / 2;
                        somePattern.Pattern = new byte[somePattern.Len + 1];
                        for (int i = 1; i <= somePattern.Len; i++)
                        {
                            somePattern.Pattern[i - 1] = (byte)Math.Round((double)int.Parse(innerText.Substring((i - 1) * 2, 2), NumberStyles.HexNumber));
                        }
                    }

                    pattern.FrontBlockSize = somePattern.Pos + somePattern.Len;
                    somePattern.XM         = false;
                    somePattern.Points     = 1;
                    if (somePattern.Pos == 0)
                    {
                        somePattern.Points = 1000;
                    }

                    pattern.Patterns.Add(somePattern);
                }
            }
        }
Пример #3
0
        private static void LoadFrontBlockNode(FileDefPattern pattern, XmlNodeList list)
        {
            foreach (XmlNode node in list)
            {
                SomePattern somePattern = new SomePattern {
                    Pos = int.Parse(node.SelectSingleNode("Pos")?.InnerText.Trim() ?? "0")
                };
                string innerText = node.SelectSingleNode("Bytes")?.InnerText.Trim();
                if (innerText != null)
                {
                    somePattern.Len     = innerText.Length / 2;
                    somePattern.Pattern = new byte[somePattern.Len + 1];
                    for (int i = 1; i <= somePattern.Len; i++)
                    {
                        somePattern.Pattern[i - 1] = (byte)Math.Round((double)int.Parse(innerText.Substring((i - 1) * 2, 2), NumberStyles.HexNumber));
                    }
                }

                pattern.FrontBlockSize = somePattern.Pos + somePattern.Len;
                somePattern.XM         = false;
                somePattern.Points     = 1;
                if (somePattern.Pos == 0)
                {
                    somePattern.Points = 1000;
                }

                pattern.Patterns.Add(somePattern);
            }
        }
Пример #4
0
        private static void LoadGlobalStringsNode(FileDefPattern pattern, XmlNodeList list)
        {
            foreach (XmlNode node in list)
            {
                string     innerText  = node.InnerText.Trim();
                ByteString byteString = new ByteString {
                    Data = new byte[innerText.Length]
                };

                for (int j = 0; j <= innerText.Length - 1; j++)
                {
                    byteString.Data[j] = innerText[j] > 255 ? Convert.ToByte(0) : Convert.ToByte(innerText[j]);
                    if (byteString.Data[j] == 39)
                    {
                        byteString.Data[j] = 0;
                    }
                }

                Ba2Upper(ref byteString.Data);
                pattern.GlobalStrings.Add(byteString);
            }
        }
Пример #5
0
        public static TrIdEngineConfig LoadDefinitionByXml(string xml, int maxFrontSize)
        {
            TrIdEngineConfig trIdEngineConf = null;

            if (xml != null)
            {
                trIdEngineConf = new TrIdEngineConfig();
                FileDefPattern fileDefPat = new FileDefPattern {
                    ExtraInfo = new ExtraInfo()
                };

                XPathDocument  xPathDocument = new XPathDocument(new StringReader(xml));
                XPathNavigator nav           = xPathDocument.CreateNavigator();

                fileDefPat.FileExt                = nav.SelectSingleNode("//Info/Ext")?.Value;
                fileDefPat.FileType               = nav.SelectSingleNode("//Info/FileType")?.Value;
                fileDefPat.ExtraInfo.FileType     = fileDefPat.FileType;
                fileDefPat.ExtraInfo.FileExt      = fileDefPat.FileExt;
                fileDefPat.ExtraInfo.AuthorName   = nav.SelectSingleNode("//Info/User")?.Value;
                fileDefPat.ExtraInfo.AuthorEMail  = nav.SelectSingleNode("//Info/E-Mail")?.Value;
                fileDefPat.ExtraInfo.AuthorHome   = nav.SelectSingleNode("//Info/Home")?.Value;
                fileDefPat.ExtraInfo.Remark       = nav.SelectSingleNode("//ExtraInfo/Rem")?.Value;
                fileDefPat.ExtraInfo.RelURL       = nav.SelectSingleNode("//ExtraInfo/RefURL")?.Value;
                fileDefPat.ExtraInfo.FilesScanned = (int)Math.Round(double.Parse(nav.SelectSingleNode("//General/FileNum")?.Value ?? "0"));
                LoadFrontBlockNode(fileDefPat, nav.Select("//FrontBlock/Pattern"));
                LoadGlobalStringsNode(fileDefPat, nav.Select("//GlobalStrings/String"));

                /*
                 * XmlDocument xmlDocument = new XmlDocument();
                 * xmlDocument.LoadXml(xml);
                 * fileDefPat.FileType = xmlDocument.SelectSingleNode("//Info/FileType")?.InnerText;
                 * XmlNode xmlNode = xmlDocument.SelectSingleNode("//Info/Ext");
                 * if (xmlNode != null)
                 * {
                 *  fileDefPat.FileExt = xmlNode.InnerText;
                 * }
                 *
                 * fileDefPat.ExtraInfo.FileType = fileDefPat.FileType;
                 * fileDefPat.ExtraInfo.FileExt = fileDefPat.FileExt;
                 *
                 * xmlNode = xmlDocument.SelectSingleNode("//Info/User");
                 * if (xmlNode != null)
                 * {
                 *  fileDefPat.ExtraInfo.AuthorName = xmlNode.InnerText;
                 * }
                 *
                 * xmlNode = xmlDocument.SelectSingleNode("//Info/E-Mail");
                 * if (xmlNode != null)
                 * {
                 *  fileDefPat.ExtraInfo.AuthorEMail = xmlNode.InnerText;
                 * }
                 *
                 * xmlNode = xmlDocument.SelectSingleNode("//Info/Home");
                 * if (xmlNode != null)
                 * {
                 *  fileDefPat.ExtraInfo.AuthorHome = xmlNode.InnerText;
                 * }
                 *
                 * xmlNode = xmlDocument.SelectSingleNode("//ExtraInfo/Rem");
                 * if (xmlNode != null)
                 * {
                 *  fileDefPat.ExtraInfo.Remark = xmlNode.InnerText;
                 * }
                 *
                 * xmlNode = xmlDocument.SelectSingleNode("//ExtraInfo/RefURL");
                 * if (xmlNode != null)
                 * {
                 *  fileDefPat.ExtraInfo.RelURL = xmlNode.InnerText;
                 * }
                 *
                 * xmlNode = xmlDocument.SelectSingleNode("//General/FileNum");
                 * if (xmlNode != null)
                 * {
                 *  fileDefPat.ExtraInfo.FilesScanned = (int) Math.Round(double.Parse(xmlNode.InnerText));
                 * }
                 *
                 * XmlNodeList frontBlockNode = xmlDocument.SelectNodes("//FrontBlock/Pattern");
                 * if (frontBlockNode != null)
                 * {
                 *  LoadFrontBlockNode(fileDefPat, frontBlockNode);
                 * }
                 *
                 * XmlNodeList globalStringsNode = xmlDocument.SelectNodes("//GlobalStrings/String");
                 * if (globalStringsNode != null)
                 * {
                 *  LoadGlobalStringsNode(fileDefPat, globalStringsNode);
                 * }
                 */
                trIdEngineConf.MaxFrontSize = Math.Max(maxFrontSize, fileDefPat.FrontBlockSize);
                trIdEngineConf.Definition   = fileDefPat;
            }

            return(trIdEngineConf);
        }