Beispiel #1
0
        public static CodeSectionInfo Parse(byte[] data, bool cryptEc = false)
        {
            var codeSectionInfo = new CodeSectionInfo();

            using (var reader = new BinaryReader(new MemoryStream(data, false)))
            {
                using (BinaryWriter writerForUnknownBeforeLibrary = new BinaryWriter(new MemoryStream()))
                {
                    writerForUnknownBeforeLibrary.Write(reader.ReadInt32());                                      //Unknown
                    writerForUnknownBeforeLibrary.Write(reader.ReadInt32());                                      //Unknown
                    writerForUnknownBeforeLibrary.WriteBytesWithLengthPrefix(reader.ReadBytesWithLengthPrefix()); //Unknown
                    if (cryptEc)
                    {
                        reader.ReadInt32();
                        reader.ReadInt32();
                        writerForUnknownBeforeLibrary.WriteBytesWithLengthPrefix(reader.ReadBytesWithLengthPrefix());//Unknown
                        codeSectionInfo.Flag       = reader.ReadInt32();
                        codeSectionInfo.MainMethod = reader.ReadInt32();
                        codeSectionInfo.Libraries  = LibraryInfo.ReadLibraries(reader);
                        writerForUnknownBeforeLibrary.WriteBytesWithLengthPrefix(reader.ReadBytesWithLengthPrefix());//Unknown
                    }
                    else
                    {
                        writerForUnknownBeforeLibrary.WriteBytesWithLengthPrefix(reader.ReadBytesWithLengthPrefix()); //Unknown
                        writerForUnknownBeforeLibrary.WriteBytesWithLengthPrefix(reader.ReadBytesWithLengthPrefix()); //Unknown
                        codeSectionInfo.Libraries  = LibraryInfo.ReadLibraries(reader);
                        codeSectionInfo.Flag       = reader.ReadInt32();
                        codeSectionInfo.MainMethod = reader.ReadInt32();
                    }
                    ;
                    if ((codeSectionInfo.Flag & 1) != 0)
                    {
                        codeSectionInfo.UnknownBeforeIconData = reader.ReadBytes(16);//Unknown
                    }
                    codeSectionInfo.UnknownBeforeLibrary = ((MemoryStream)writerForUnknownBeforeLibrary.BaseStream).ToArray();
                }

                codeSectionInfo.IconData = reader.ReadBytesWithLengthPrefix();
                codeSectionInfo.DebugCommandParameters = reader.ReadStringWithLengthPrefix();
                if (cryptEc)
                {
                    reader.ReadBytes(12);
                    codeSectionInfo.Methods         = MethodInfo.ReadMethods(reader);
                    codeSectionInfo.DllDeclares     = DllDeclareInfo.ReadDllDeclares(reader);
                    codeSectionInfo.GlobalVariables = VariableInfo.ReadVariables(reader);
                    codeSectionInfo.Classes         = ClassInfo.ReadClasses(reader);
                    codeSectionInfo.Structs         = StructInfo.ReadStructs(reader);
                }
                else
                {
                    codeSectionInfo.Classes         = ClassInfo.ReadClasses(reader);
                    codeSectionInfo.Methods         = MethodInfo.ReadMethods(reader);
                    codeSectionInfo.GlobalVariables = VariableInfo.ReadVariables(reader);
                    codeSectionInfo.Structs         = StructInfo.ReadStructs(reader);
                    codeSectionInfo.DllDeclares     = DllDeclareInfo.ReadDllDeclares(reader);
                }
            }
            return(codeSectionInfo);
        }
Beispiel #2
0
        private static ParamListExpression ParseParamList(BinaryReader reader, CodeSectionInfo codeSectionInfo, int blockId)
        {
            ParamListExpression paramListExpression = new ParamListExpression();
            Expression          item;

            while (!((item = ParseExpression(reader, codeSectionInfo, blockId, true)) is ParamListEnd))
            {
                paramListExpression.Value.Add(item);
            }
            return(paramListExpression);
        }
Beispiel #3
0
        public static CodeSectionInfo Parse(SectionInfo sectionInfo, bool cryptEc = false)
        {
            byte[]          data            = sectionInfo.Data;
            CodeSectionInfo codeSectionInfo = new CodeSectionInfo();

            using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(data, false)))
            {
                using (BinaryWriter binaryWriter = new BinaryWriter(new MemoryStream()))
                {
                    using (BinaryWriter binaryWriter2 = new BinaryWriter(new MemoryStream()))
                    {
                        binaryWriter.Write(binaryReader.ReadInt32());
                        binaryWriter.Write(binaryReader.ReadInt32());
                        binaryWriter.WriteBytesWithLengthPrefix(binaryReader.ReadBytesWithLengthPrefix());
                        int num;
                        int value;
                        if (cryptEc)
                        {
                            binaryReader.ReadInt32();
                            binaryReader.ReadInt32();
                            binaryWriter.WriteBytesWithLengthPrefix(binaryReader.ReadBytesWithLengthPrefix());
                            num   = binaryReader.ReadInt32();
                            value = binaryReader.ReadInt32();
                            codeSectionInfo.Libraries = LibraryInfo.ReadLibraries(binaryReader);
                            binaryWriter.WriteBytesWithLengthPrefix(binaryReader.ReadBytesWithLengthPrefix());
                        }
                        else
                        {
                            binaryWriter.WriteBytesWithLengthPrefix(binaryReader.ReadBytesWithLengthPrefix());
                            binaryWriter.WriteBytesWithLengthPrefix(binaryReader.ReadBytesWithLengthPrefix());
                            codeSectionInfo.Libraries = LibraryInfo.ReadLibraries(binaryReader);
                            num   = binaryReader.ReadInt32();
                            value = binaryReader.ReadInt32();
                        }
                        binaryWriter2.Write(num);
                        binaryWriter2.Write(value);
                        if ((num & 1) != 0)
                        {
                            binaryWriter2.Write(binaryReader.ReadBytes(16));
                        }
                        codeSectionInfo.UnknownBeforeLibrary  = ((MemoryStream)binaryWriter.BaseStream).ToArray();
                        codeSectionInfo.UnknownBeforeIconData = ((MemoryStream)binaryWriter2.BaseStream).ToArray();
                    }
                }
                codeSectionInfo.IconData = binaryReader.ReadBytesWithLengthPrefix();
                codeSectionInfo.DebugCommandParameters = binaryReader.ReadStringWithLengthPrefix();
                if (cryptEc)
                {
                    binaryReader.ReadBytes(12);
                    codeSectionInfo.Methods         = MethodInfo.ReadMethods(binaryReader);
                    codeSectionInfo.DllDeclares     = DllDeclareInfo.ReadDllDeclares(binaryReader);
                    codeSectionInfo.GlobalVariables = VariableInfo.ReadVariables(binaryReader);
                    codeSectionInfo.Classes         = ClassInfo.ReadClasses(binaryReader);
                    codeSectionInfo.Structs         = StructInfo.ReadStructs(binaryReader);
                }
                else
                {
                    codeSectionInfo.Classes         = ClassInfo.ReadClasses(binaryReader);
                    codeSectionInfo.Methods         = MethodInfo.ReadMethods(binaryReader);
                    codeSectionInfo.GlobalVariables = VariableInfo.ReadVariables(binaryReader);
                    codeSectionInfo.Structs         = StructInfo.ReadStructs(binaryReader);
                    codeSectionInfo.DllDeclares     = DllDeclareInfo.ReadDllDeclares(binaryReader);
                }
            }

            foreach (var method in codeSectionInfo.Methods)
            {
                BinaryReader reader = new BinaryReader(new MemoryStream(method.CodeData[5], false));
                CodeDataParser.StatementBlock statement = CodeDataParser.ParseStatementBlock(reader, codeSectionInfo, method.Id);
                method.Code = statement.ToString();
            }
            return(codeSectionInfo);
        }
Beispiel #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            bool   parseSessionData = checkBox1.Checked;
            bool   parseCodeData    = checkBox2.Checked;
            string fileName         = textBox2.Text;

            textBox1.Text = "正在处理...";

            new Task(() =>
            {
                try
                {
                    var output = new StringBuilder();
                    using (var projectFileReader = new ProjectFileReader(File.OpenRead(fileName), InputPassword))
                    {
                        while (!projectFileReader.IsFinish)
                        {
                            var section = projectFileReader.ReadSection();
                            output.AppendLine("------------------" + section.Name + "------------------");
                            output.AppendLine("***Flags: 0x" + section.Flags.ToString("X8"));
                            output.AppendLine("***Key: " + section.Key.ToHexString());
                            output.AppendLine();
                            if (!parseSessionData)
                            {
                                continue;
                            }
                            switch (section.Name)
                            {
                            case ESystemInfo.SectionName:
                                {
                                    var systemInfo = ESystemInfo.Parse(section.Data);
                                    output.AppendLine(systemInfo.ToString());
                                }
                                break;

                            case ProjectConfigInfo.SectionName:
                                {
                                    var projectConfig = ProjectConfigInfo.Parse(section.Data);
                                    output.AppendLine(projectConfig.ToString());
                                }
                                break;

                            case CodeSectionInfo.SectionName:
                                {
                                    var codeSectionInfo = CodeSectionInfo.Parse(section.Data, projectFileReader.CryptEc);
                                    output.AppendLine(codeSectionInfo.ToString());

                                    if (parseCodeData)
                                    {
                                        output.AppendLine("~~~~~~~~~~~~~~解析代码~~~~~~~~~~~~~~");
                                        foreach (var method in codeSectionInfo.Methods)
                                        {
                                            output.AppendLine($"TryToParseCode: {method.Name}(Id: {method.Id})");
                                            try
                                            {
                                                var reader           = new BinaryReader(new MemoryStream(method.CodeData[5], false));
                                                var lineOffestStream = new MemoryStream();
                                                var block            = CodeDataParser.ParseStatementBlock(reader, new BinaryWriter(lineOffestStream));
                                                output.AppendLine($"LineOffest(生成): {lineOffestStream.ToArray().ToHexString()}");
                                                output.AppendLine($"BlockOffest(生成): {CodeDataParser.GenerateBlockOffest(block).ToHexString()}");
                                                output.AppendLine(block.ToString());
                                            }
                                            catch (Exception exception)
                                            {
                                                output.AppendLine("出现错误:");
                                                output.AppendLine(exception.ToString());
                                                output.AppendLine();
                                            }
                                        }
                                    }
                                }
                                break;

                            case EPackageInfo.SectionName:
                                {
                                    var packageInfo = EPackageInfo.Parse(section.Data);
                                    output.AppendLine(packageInfo.ToString());
                                }
                                break;

                            case ResourceSectionInfo.SectionName:
                                {
                                    var resourceSectionInfo = ResourceSectionInfo.Parse(section.Data);
                                    output.AppendLine(resourceSectionInfo.ToString());
                                }
                                break;

                            case InitEcSectionInfo.SectionName:
                                {
                                    var initEcSectionInfo = InitEcSectionInfo.Parse(section.Data);
                                    output.AppendLine(initEcSectionInfo.ToString());
                                }
                                break;

                            default:
                                output.Append("Unknown: ");
                                output.AppendLine(section.Data.ToHexString());
                                break;
                            }
                        }
                    }
                    Invoke(new Action(() =>
                    {
                        textBox1.Text = output.ToString();
                    }));
                }
                catch (Exception exception)
                {
                    Invoke(new Action(() =>
                    {
                        textBox1.Text = $"出现错误:\r\n{exception}\r\n请加群后将文件发送给作者以便修复此问题";
                    }));
                }
            })
            .Start();
        }
Beispiel #5
0
        private static void FixEProjectFile(string source, string target, ProjectFileReader.OnInputPassword inputPassword = null)
        {
            ESystemInfo         systemInfo          = null;
            CodeSectionInfo     codeSectionInfo     = null;
            ResourceSectionInfo resourceSectionInfo = null;
            InitEcSectionInfo   initEcSectionInfo   = null;
            var sections = new List <SectionInfo>();

            using (var projectFileReader = new ProjectFileReader(File.OpenRead(source), inputPassword))
            {
                while (!projectFileReader.IsFinish)
                {
                    var section = projectFileReader.ReadSection();
                    switch (section.Name)
                    {
                    case ESystemInfo.SectionName:
                        systemInfo = ESystemInfo.Parse(section.Data);
                        break;

                    case CodeSectionInfo.SectionName:
                        codeSectionInfo = CodeSectionInfo.Parse(section.Data, projectFileReader.CryptEc);
                        break;

                    case ResourceSectionInfo.SectionName:
                        resourceSectionInfo = ResourceSectionInfo.Parse(section.Data);
                        break;

                    case InitEcSectionInfo.SectionName:
                        initEcSectionInfo = InitEcSectionInfo.Parse(section.Data);
                        break;

                    default:
                        break;
                    }
                    sections.Add(section);
                }
            }
            systemInfo.FileType = 1;
            foreach (var classInfo in codeSectionInfo.Classes)
            {
                if (!ValidEplName(classInfo.Name))
                {
                    classInfo.Name = ParseDebugComment(classInfo.Comment);
                    if (classInfo.Name == null)
                    {
                        if (classInfo.Comment == "_-@M<>")
                        {
                            classInfo.Comment = "";
                        }
                        classInfo.Name = (classInfo.BaseClass == 0 ? "_程序集" : "_类") + (classInfo.Id & IdMask).ToString("X");
                    }
                    else
                    {
                        classInfo.Comment = "";
                    }
                }
                FixVariablesName(classInfo.Variables, classInfo.BaseClass == 0 ? "_程序集变量" : "_成员");
            }
            FixVariablesName(codeSectionInfo.GlobalVariables, "_全局");
            foreach (var method in codeSectionInfo.Methods)
            {
                if (!ValidEplName(method.Name))
                {
                    method.Name = ParseDebugComment(method.Comment);
                    if (method.Name == null)
                    {
                        if (method.Comment == "_-@S<>")
                        {
                            method.Comment = "";
                        }
                        method.Name = $"_子程序{(method.Id & IdMask).ToString("X")}";
                    }
                    else
                    {
                        method.Comment = "";
                    }
                }
                FixVariablesName(method.Parameters, "_参数", true);
                FixVariablesName(method.Variables, "_局部", true);

                var reader           = new BinaryReader(new MemoryStream(method.CodeData[5], false));
                var lineOffestStream = new MemoryStream();
                CodeDataParser.StatementBlock block = null;
                try
                {
                    block = CodeDataParser.ParseStatementBlock(reader, new BinaryWriter(lineOffestStream));
                }
                catch (Exception)
                {
                    method.Comment = $"[修复失败]{method.Comment}";
                    continue;
                }

                method.CodeData[0] = lineOffestStream.ToArray();
                method.CodeData[1] = CodeDataParser.GenerateBlockOffest(block);
            }
            foreach (var structInfo in codeSectionInfo.Structs)
            {
                if (!ValidEplName(structInfo.Name))
                {
                    structInfo.Name = $"_结构{(structInfo.Id & IdMask).ToString("X")}";
                }
                FixVariablesName(structInfo.Member, "_成员", false);
            }
            foreach (var dll in codeSectionInfo.DllDeclares)
            {
                if (!ValidEplName(dll.Name))
                {
                    dll.Name = dll.NameInLibrary;
                    if (dll.Name.StartsWith("@"))
                    {
                        dll.Name = dll.Name.Substring(1);
                    }
                    dll.Name = "_" + dll.Name;
                    if (!ValidEplName("_" + dll.Name))
                    {
                        dll.Name = "";
                    }
                    dll.Name = $"_DLL命令{(dll.Id & IdMask).ToString("X")}{dll.Name}";
                }
                FixVariablesName(dll.Parameters, "_参数", true);
            }
            foreach (var constant in resourceSectionInfo.Constants)
            {
                if (!ValidEplName(constant.Name))
                {
                    constant.Name = $"_常量{(constant.Id & IdMask).ToString("X")}";
                }
            }
            foreach (var formInfo in resourceSectionInfo.Forms)
            {
                if (!ValidEplName(formInfo.Name))
                {
                    formInfo.Name = $"_窗口{(formInfo.Id & IdMask).ToString("X")}";
                }
                foreach (var elem in formInfo.Elements)
                {
                    if (elem is FormMenuInfo)
                    {
                        var        menu        = (FormMenuInfo)elem;
                        MethodInfo eventMethod = null;
                        if (menu.ClickEvent != 0)
                        {
                            eventMethod = Array.Find(codeSectionInfo.Methods, x => x.Id == menu.ClickEvent);
                        }
                        if (string.IsNullOrEmpty(menu.Name))
                        {
                            if (ValidEplName("_" + menu.Text))
                            {
                                menu.Name = $"_菜单{(menu.Id & IdMask).ToString("X")}_{menu.Text}";
                            }
                            else
                            {
                                menu.Name = $"_菜单{(menu.Id & IdMask).ToString("X")}";
                            }
                            if (eventMethod != null && eventMethod.Name != null &&
                                eventMethod.Name.StartsWith("_") && eventMethod.Name.EndsWith("_被选择"))//尝试从事件子程序名还原名称
                            {
                                menu.Name = eventMethod.Name.Substring(1, eventMethod.Name.Length - 5);
                            }
                        }
                        if (eventMethod != null)
                        {
                            eventMethod.Name = $"_{menu.Name}_被选择";
                        }
                    }
                    else if (elem is FormControlInfo)
                    {
                        var control  = (FormControlInfo)elem;
                        var elemName = control.Name;

                        if (!ValidEplName(elemName))
                        {
                            if (control.Events.Length > 0)//尝试从子程序名恢复窗口名
                            {
                                var        eventItem   = control.Events[0];
                                MethodInfo eventMethod = Array.Find(codeSectionInfo.Methods, x => x.Id == eventItem.Value);//TODO:使用哈希表提高效率
                                if (eventMethod != null)
                                {
                                    var eventName = GetEventName(codeSectionInfo.Libraries, control.DataType, eventItem.Key);
                                    if (eventName != null && eventMethod.Name.StartsWith("_") && eventMethod.Name.EndsWith($"_{eventName}"))
                                    {
                                        formInfo.Name = eventMethod.Name.Substring(1, eventMethod.Name.Length - 1 - eventName.Length - 1);
                                    }
                                }
                            }
                            elemName = formInfo.Name;
                        }
                        foreach (var eventItem in control.Events)
                        {
                            MethodInfo eventMethod = Array.Find(codeSectionInfo.Methods, x => x.Id == eventItem.Value);//TODO:使用哈希表提高效率
                            if (eventMethod != null)
                            {
                                var eventName = GetEventName(codeSectionInfo.Libraries, control.DataType, eventItem.Key);
                                if (eventName != null)
                                {
                                    eventMethod.Name = $"_{elemName}_{eventName}";
                                }
                                else if (!eventMethod.Name.StartsWith($"_{elemName}_"))
                                {
                                    eventName        = $"事件{eventItem.Key.ToString("X8")}";
                                    eventMethod.Name = $"_{elemName}_{eventName}";
                                }
                            }
                        }
                    }
                }
                var formClass = Array.Find(codeSectionInfo.Classes, x => x.Id == formInfo.Class);//TODO:使用哈希表提高效率
                if (formClass != null)
                {
                    var prefix = $"[“{formInfo.Name}”的窗口程序集]";
                    if (!formClass.Comment.StartsWith(prefix))
                    {
                        formClass.Comment = $"{prefix}{formClass.Comment}";
                    }
                }
            }
            {
                //TODO:使用哈希表提高效率
                var mainMethod = Array.Find(codeSectionInfo.Methods, x => x.Id == codeSectionInfo.MainMethod);
                if (mainMethod != null)
                {
                    mainMethod.Name = "_启动子程序";
                    if (initEcSectionInfo.InitMethod.Length > 0)
                    {
                        var prefix = "[注意:本子程序将在 初始模块_X 后调用]";
                        if (!mainMethod.Comment.StartsWith(prefix))
                        {
                            mainMethod.Comment = $"{prefix}{mainMethod.Comment}";
                        }
                    }
                }
                for (int i = 0; i < initEcSectionInfo.InitMethod.Length; i++)
                {
                    var initMethod = Array.Find(codeSectionInfo.Methods, x => x.Id == initEcSectionInfo.InitMethod[i]);
                    initMethod.Name = $"初始模块_{i + 1}";
                    if (ValidEplName("_" + initEcSectionInfo.EcName[i]))
                    {
                        initMethod.Name += "_" + initEcSectionInfo.EcName[i];
                    }

                    var prefix = $"[禁止删除][注意:本子程序将自动在启动时被调用,且早于 _启动子程序 被调用][为内联的模块“{initEcSectionInfo.EcName[i]}”做初始化工作]";
                    if (!initMethod.Comment.StartsWith(prefix))
                    {
                        initMethod.Comment = $"{prefix}{initMethod.Comment}";
                    }
                }
            }

            using (var projectFileWriter = new ProjectFileWriter(File.OpenWrite(target)))
            {
                foreach (var section in sections)
                {
                    switch (section.Name)
                    {
                    case ESystemInfo.SectionName:
                        section.Data = systemInfo.ToBytes();
                        break;

                    case CodeSectionInfo.SectionName:
                        section.Data = codeSectionInfo.ToBytes();
                        break;

                    case ResourceSectionInfo.SectionName:
                        section.Data = resourceSectionInfo.ToBytes();
                        break;

                    case InitEcSectionInfo.SectionName:
                        section.Data = initEcSectionInfo.ToBytes();
                        break;

                    default:
                        break;
                    }
                    projectFileWriter.WriteSection(section);
                }
            }
        }
Beispiel #6
0
        private static CallExpression ParseCallExpressionWithoutType(BinaryReader reader, CodeSectionInfo codeSectionInfo, int blockId, out string unvalidCode, out string comment, out bool mask)
        {
            int   methodId  = reader.ReadInt32();
            short libraryId = reader.ReadInt16();
            short num       = reader.ReadInt16();

            unvalidCode = reader.ReadStringWithLengthPrefix();
            comment     = reader.ReadStringWithLengthPrefix();
            mask        = (num == 1 || num == 32);
            if ("".Equals(unvalidCode))
            {
                unvalidCode = null;
            }
            if ("".Equals(comment))
            {
                comment = null;
            }
            CallExpression callExpression = new CallExpression(libraryId, methodId, codeSectionInfo);

            if (reader.BaseStream.Position != reader.BaseStream.Length)
            {
                switch (reader.ReadByte())
                {
                case 54:
                    callExpression.ParamList = ParseParamList(reader, codeSectionInfo, blockId);
                    break;

                case 56:
                    reader.BaseStream.Position -= 1L;
                    callExpression.Target       = ParseExpression(reader, codeSectionInfo, blockId, true);
                    callExpression.ParamList    = ParseParamList(reader, codeSectionInfo, blockId);
                    break;

                default:
                    reader.BaseStream.Position -= 1L;
                    throw new Exception();
                }
            }
            return(callExpression);
        }
Beispiel #7
0
        private static CallExpression ParseCallExpressionWithoutType(BinaryReader reader, CodeSectionInfo codeSectionInfo, int blockId)
        {
            string text;
            string text2;
            bool   flag;

            return(ParseCallExpressionWithoutType(reader, codeSectionInfo, blockId, out text, out text2, out flag));
        }
Beispiel #8
0
        private static Expression ParseExpression(BinaryReader reader, CodeSectionInfo codeSectionInfo, int blockId, bool parseMember = true)
        {
            Expression expression = null;
            byte       b          = reader.ReadByte();

            switch (b)
            {
            case 1:
                expression = new ParamListEnd();
                break;

            case 22:
                expression = null;
                break;

            case 23:
                expression = new NumberLiteral(reader.ReadDouble());
                break;

            case 24:
                expression = new BoolLiteral(reader.ReadInt16() != 0);
                break;

            case 25:
                expression = new DateTimeLiteral(DateTime.FromOADate(reader.ReadDouble()));
                break;

            case 26:
                expression = new StringLiteral(reader.ReadStringWithLengthPrefix());
                break;

            case 27:
                expression = new ConstantExpression(-2, reader.ReadInt32());
                break;

            case 28:
                expression = new ConstantExpression(reader.ReadInt16(), reader.ReadInt16());
                break;

            case 29:
                if (reader.ReadByte() != 56)
                {
                    throw new Exception();
                }
                expression = new VariableExpression(reader.ReadInt32(), codeSectionInfo, blockId);
                break;

            case 30:
                expression = new SubPtrExpression(reader.ReadInt32(), codeSectionInfo);
                break;

            case 33:
                expression = ParseCallExpressionWithoutType(reader, codeSectionInfo, blockId);
                break;

            case 35:
                expression = new EmnuConstantExpression(reader.ReadInt32(), reader.ReadInt32());
                break;

            case 31:
            {
                ArrayLiteralExpression arrayLiteralExpression = new ArrayLiteralExpression();
                Expression             item;
                while (!((item = ParseExpression(reader, codeSectionInfo, blockId, true)) is ArrayLiteralEnd))
                {
                    arrayLiteralExpression.Value.Add(item);
                }
                expression = arrayLiteralExpression;
                break;
            }

            case 32:
                expression = new ArrayLiteralEnd();
                break;

            case 56:
            {
                int num = reader.ReadInt32();
                if (num == 83951614)
                {
                    reader.ReadByte();
                    expression = ParseExpression(reader, codeSectionInfo, blockId, true);
                }
                else
                {
                    expression = new VariableExpression(num, codeSectionInfo, blockId);
                }
                break;
            }

            case 59:
                expression = new NumberLiteral((double)reader.ReadInt32());
                break;

            default:
                throw new Exception(string.Format("Unknown Type: {0}", b.ToString("X2")));

            case 55:
                break;
            }
            //bool flag = false;
            if (parseMember && (expression is VariableExpression || expression is CallExpression))
            {
                while (reader.BaseStream.Position != reader.BaseStream.Length)
                {
                    switch (reader.ReadByte())
                    {
                    case 57:
                        break;

                    case 58:
                        goto IL_027a;

                    default:
                        reader.BaseStream.Position -= 1L;
                        goto IL_02eb;

                    case 55:
                        goto IL_02eb;
                    }
                    int memberId = reader.ReadInt32();
                    int structId = reader.ReadInt32();
                    expression = new AccessMemberExpression(expression, structId, memberId);
                    continue;
IL_027a:
                    bool parseMember2           = reader.ReadByte() == 56;
                    reader.BaseStream.Position -= 1L;
                    expression = new AccessArrayExpression(expression, ParseExpression(reader, codeSectionInfo, blockId, parseMember2));
                }
            }
            goto IL_02eb;
IL_02eb:
            return(expression);
        }
Beispiel #9
0
        public static StatementBlock ParseStatementBlock(BinaryReader reader, CodeSectionInfo codeSectionInfo, int blockId)
        {
            StatementBlock statementBlock = new StatementBlock();

            while (reader.BaseStream.Position != reader.BaseStream.Length)
            {
                int  num = (int)reader.BaseStream.Position;
                byte b   = reader.ReadByte();

                switch (b)
                {
                case 80:
                case 81:
                case 82:
                case 84:
                case 110:
                case 111:
                case 113:
                    reader.BaseStream.Position = num;
                    return(statementBlock);

                case 109:
                    reader.ReadByte();
                    goto default;

                default:
                {
                    string         text;
                    string         text2;
                    bool           flag;
                    CallExpression callExpression = ParseCallExpressionWithoutType(reader, codeSectionInfo, blockId, out text, out text2, out flag);
                    switch (b)
                    {
                    case 109:
                    {
                        SwitchStatement switchStatement = new SwitchStatement();
                        Expression      condition       = callExpression.ParamList.Value.ElementAtOrDefault(0);
                        StatementBlock  statementBlock2 = ParseStatementBlock(reader, codeSectionInfo, blockId);
                        while (true)
                        {
                            switch (reader.ReadByte())
                            {
                            case 110:
                                switchStatement.Case.Add(new SwitchStatement.CaseInfo
                                        {
                                            Condition   = condition,
                                            Block       = statementBlock2,
                                            UnvalidCode = text,
                                            Comment     = text2,
                                            Mask        = flag
                                        });
                                condition       = ParseCallExpressionWithoutType(reader, codeSectionInfo, blockId, out text, out text2, out flag).ParamList.Value.ElementAtOrDefault(0);
                                statementBlock2 = ParseStatementBlock(reader, codeSectionInfo, blockId);
                                continue;

                            case 111:
                                switchStatement.Case.Add(new SwitchStatement.CaseInfo
                                        {
                                            Condition   = condition,
                                            Block       = statementBlock2,
                                            UnvalidCode = text,
                                            Comment     = text2,
                                            Mask        = flag
                                        });
                                condition       = null;
                                statementBlock2 = ParseStatementBlock(reader, codeSectionInfo, blockId);
                                continue;

                            case 84:
                                break;

                            default:
                                throw new Exception();
                            }
                            break;
                        }
                        switchStatement.EndOffest = (int)reader.BaseStream.Position;
                        reader.ReadByte();
                        switchStatement.DefaultBlock = statementBlock2;
                        switchStatement.StartOffest  = num;
                        statementBlock.Statements.Add(switchStatement);
                        break;
                    }

                    case 112:
                    {
                        StatementBlock block           = ParseStatementBlock(reader, codeSectionInfo, blockId);
                        CallExpression callExpression2 = null;
                        int            endOffest3      = (int)reader.BaseStream.Position;
                        byte           b2 = reader.ReadByte();
                        if (b2 == 113)
                        {
                            callExpression2 = ParseCallExpressionWithoutType(reader, codeSectionInfo, blockId, out string unvalidCode, out string commentOnEnd, out bool maskOnEnd);
                            if (callExpression.LibraryId != 0)
                            {
                                throw new Exception();
                            }
                            LoopStatement loopStatement = null;
                            switch (callExpression.MethodId)
                            {
                            case 3:
                                loopStatement = new WhileStatement
                                {
                                    Condition   = callExpression.ParamList.Value.ElementAtOrDefault(0),
                                    Block       = block,
                                    UnvalidCode = text
                                };
                                break;

                            case 5:
                                loopStatement = new DoWhileStatement
                                {
                                    Condition   = callExpression2.ParamList.Value.ElementAtOrDefault(0),
                                    Block       = block,
                                    UnvalidCode = unvalidCode
                                };
                                break;

                            case 7:
                                loopStatement = new CounterStatement
                                {
                                    Count       = callExpression.ParamList.Value.ElementAtOrDefault(0),
                                    Var         = callExpression.ParamList.Value.ElementAtOrDefault(1),
                                    Block       = block,
                                    UnvalidCode = text
                                };
                                break;

                            case 9:
                                loopStatement = new ForStatement
                                {
                                    Start       = callExpression.ParamList.Value.ElementAtOrDefault(0),
                                    End         = callExpression.ParamList.Value.ElementAtOrDefault(1),
                                    Step        = callExpression.ParamList.Value.ElementAtOrDefault(2),
                                    Var         = callExpression.ParamList.Value.ElementAtOrDefault(3),
                                    Block       = block,
                                    UnvalidCode = text
                                };
                                break;

                            default:
                                throw new Exception();
                            }
                            loopStatement.StartOffest    = num;
                            loopStatement.EndOffest      = endOffest3;
                            loopStatement.CommentOnStart = text2;
                            loopStatement.CommentOnEnd   = commentOnEnd;
                            loopStatement.MaskOnStart    = flag;
                            loopStatement.MaskOnEnd      = maskOnEnd;
                            statementBlock.Statements.Add(loopStatement);
                            break;
                        }
                        throw new Exception();
                    }

                    case 108:
                    {
                        IfStatement ifStatement = new IfStatement
                        {
                            Condition   = callExpression.ParamList.Value.ElementAtOrDefault(0),
                            UnvalidCode = text,
                            Block       = ParseStatementBlock(reader, codeSectionInfo, blockId),
                            Comment     = text2,
                            Mask        = flag
                        };
                        if (reader.ReadByte() != 82)
                        {
                            throw new Exception();
                        }
                        int endOffest = (int)reader.BaseStream.Position;
                        reader.ReadByte();
                        ifStatement.StartOffest = num;
                        ifStatement.EndOffest   = endOffest;
                        statementBlock.Statements.Add(ifStatement);
                        break;
                    }

                    case 107:
                    {
                        IfElseStatement ifElseStatement = new IfElseStatement
                        {
                            Condition   = callExpression.ParamList.Value.ElementAtOrDefault(0),
                            UnvalidCode = text,
                            Comment     = text2,
                            Mask        = flag
                        };
                        ifElseStatement.BlockOnTrue = ParseStatementBlock(reader, codeSectionInfo, blockId);
                        if (reader.ReadByte() != 80)
                        {
                            throw new Exception();
                        }
                        ifElseStatement.BlockOnFalse = ParseStatementBlock(reader, codeSectionInfo, blockId);
                        if (reader.ReadByte() != 81)
                        {
                            throw new Exception();
                        }
                        int endOffest2 = (int)reader.BaseStream.Position;
                        reader.ReadByte();
                        ifElseStatement.StartOffest = num;
                        ifElseStatement.EndOffest   = endOffest2;
                        statementBlock.Statements.Add(ifElseStatement);
                        break;
                    }

                    default:
                        if (text != null)
                        {
                            statementBlock.Statements.Add(new UnvalidStatement
                                {
                                    UnvalidCode = text,
                                    Mask        = flag
                                });
                        }
                        else if (callExpression.LibraryId == -1)
                        {
                            statementBlock.Statements.Add(new ExpressionStatement
                                {
                                    Expression = null,
                                    Comment    = text2
                                });
                        }
                        else
                        {
                            statementBlock.Statements.Add(new ExpressionStatement
                                {
                                    Expression = callExpression,
                                    Comment    = text2,
                                    Mask       = flag
                                });
                        }
                        break;
                    }
                    break;
                }

                case 83:
                case 85:
                    break;
                }
            }
            return(statementBlock);
        }
Beispiel #10
0
 public CallExpression(short LibraryId, int MethodId, CodeSectionInfo codeSectionInfo)
 {
     this.LibraryId       = LibraryId;
     this.MethodId        = MethodId;
     this.codeSectionInfo = codeSectionInfo;
 }
Beispiel #11
0
 public SubPtrExpression(int Id, CodeSectionInfo codeSectionInfo)
 {
     this.Id = Id;
     this.codeSectionInfo = codeSectionInfo;
 }
Beispiel #12
0
 public VariableExpression(int Id, CodeSectionInfo codeSectionInfo, int blockId)
 {
     this.Id = Id;
     this.codeSectionInfo = codeSectionInfo;
     this.blockId         = blockId;
 }