Exemple #1
0
        public override void BuildSignature()
        {
            if (isSignatureBuilt)
            {
                return;
            }

            Program.Log(LogLevel.NOR, "Building Signature for Fragment[" + Name + "]");

            foreach (var(num, code) in this.Lines)
            {
                var(sign, infos)    = ParseSignatureLine(code);
                Program.CurrentLine = num;

                if (infos != null)
                {
                    // "pad-<sz>" is already included in ParseSignatureLine()
                    Signature += " " + sign;
                    Infos.Add(infos);
                }
                else
                {
                    // for "Fragment", code could be one of these:
                    // + Fragment[       // fragment within fragment

                    if (code.StartsWith("+ Fragment"))
                    {
                        var obj = Fragment.GetFragmentByCode(code);

                        Signature += " " + obj.Signature;
                        Infos.AddRange(obj.Infos);
                    }
                    else if (code.StartsWith("+ REP"))
                    {
                        Signature += " [REPS]";
                        Infos.Add(ParamPlaceholderName);
                    }
                    else if (code.StartsWith("- REP"))
                    {
                        Signature += " [REPE]";
                        Infos.Add(ParamPlaceholderName);
                    }
                    else
                    {
                        Program.Log(LogLevel.ERR | LogLevel.EXIT,
                                    "Invalid code for \"Fragment\".",
                                    "Raw: " + code);
                    }
                }
            }

            Signature        = Signature.Trim();
            isSignatureBuilt = true;
        }
Exemple #2
0
        public override void BuildSignature()
        {
            if (isSignatureBuilt)
            {
                return;
            }

            Program.Log(LogLevel.NOR, "Building Signature for Packet[" + Header.PadRight(4, ' ') + "][" + Desc + "]");

            bool   doesSubcatePlaceholderAppeared = false;
            bool   packetBodySectionEnded         = false;
            bool   isInSubcate          = false;
            bool   isRepeatableTagEnded = true;
            string tmpSignature         = ""; // subcate is not replaced yet
            JArray infoBeforeSubcate    = new JArray();
            JArray infoAfterSubcate     = new JArray();

            dynamic tmpObj = new JObject();
            string  tmpSubcateSignature = "";
            JArray  tmpSubcateInfo      = new JArray();

            foreach (var(num, code) in Lines)
            {
                var(sign, infos)    = ParseSignatureLine(code);
                Program.CurrentLine = num;

                if (infos != null)
                {
                    if (isInSubcate)
                    {
                        tmpSubcateSignature += " " + sign;
                        tmpSubcateInfo.Add(infos);
                    }
                    else
                    {
                        tmpSignature += " " + sign;
                        if (doesSubcatePlaceholderAppeared)
                        {
                            infoAfterSubcate.Add(infos);
                        }
                        else
                        {
                            infoBeforeSubcate.Add(infos);
                        }
                    }
                }
                else
                {
                    if (code.StartsWith("+ Fragment"))
                    {
                        var obj = Fragment.GetFragmentByCode(code);

                        tmpSignature += " " + obj.Signature;
                        // add range
                        obj.Infos.ForEach(info => infoBeforeSubcate.Add(info));
                    }
                    else if (code.StartsWith("+ SubCate"))
                    {
                        // set constraint, only 1 subcate code can be used
                        if (doesSubcatePlaceholderAppeared)
                        {
                            Program.Log(LogLevel.ERR | LogLevel.EXIT,
                                        "Constraint Violation - You can only use 1 \"+ SubCate\" within same packet/fragment.",
                                        "Occurred within: Packet[" + Header.PadRight(4, ' ') + "] " + Desc
                                        );
                        }
                        else if (packetBodySectionEnded)
                        {
                            Program.Log(LogLevel.ERR | LogLevel.EXIT,
                                        "Constraint Violation - You cannot include another subcate within a subcate.",
                                        "Occurred within: Packet[" + Header.PadRight(4, ' ') + "] " + Desc
                                        );
                        }

                        tmpSignature += " {SUBCATE}";
                        doesSubcatePlaceholderAppeared = true;
                    }
                    else if (code.StartsWith("SubCate["))
                    {
                        // start of subcate signature
                        var m = regexSubcate.Match(code);
                        var g = m.Groups;
                        if (!m.Success || (g[1].Value == "" && g[2].Value == ""))
                        {
                            Program.Log(LogLevel.ERR | LogLevel.EXIT,
                                        "Invalid SubCate declaration.",
                                        "Occurred within: Packet[" + Header.PadRight(4, ' ') + "] " + Desc,
                                        "Captured: [" + string.Join(", ", g.Values) + "]",
                                        "Raw: " + code
                                        );
                        }

                        // have subcate before this subcate (another)
                        // push the previous subcate to dict list
                        if (isInSubcate)
                        {
                            if (tmpSignature == "")
                            {
                                Program.Log(LogLevel.WARN,
                                            "Skipped invalid SubCate declaration - No actual signature/body.",
                                            "Occurred within: Packet[" + Header.PadRight(4, ' ') + "] " + Desc
                                            );
                            }
                            else
                            {
                                subcate.Add(tmpSubcateSignature.TrimStart(), tmpObj);
                            }
                        }

                        tmpObj              = new JObject(); // renew
                        tmpObj.desc         = g[1].Value;
                        tmpObj["params"]    = tmpSubcateInfo = new JArray();
                        tmpSubcateSignature = "";

                        if (g[2].Value != "")
                        {
                            // with hex-byte (static hex subcate signature)
                            tmpSubcateSignature += " " + g[2].Value[1..];