Exemplo n.º 1
0
        public static CodeSectionInfo Parse(byte[] data, Encoding encoding, bool cryptEc = false)
        {
            var codeSectionInfo = new CodeSectionInfo();

            int[]   minRequiredCmds;
            short[] minRequiredDataTypes;
            short[] minRequiredConstants;
            using (var reader = new BinaryReader(new MemoryStream(data, false), encoding))
            {
                codeSectionInfo.allocatedIdNum = reader.ReadInt32();
                reader.ReadInt32(); // 确认于易语言V5.71
                minRequiredCmds = reader.ReadInt32sWithByteSizePrefix();
                if (cryptEc)
                {
                    reader.ReadInt32();
                    reader.ReadInt32();
                    minRequiredDataTypes       = reader.ReadInt16sWithByteSizePrefix();
                    codeSectionInfo.Flag       = reader.ReadInt32();
                    codeSectionInfo.MainMethod = reader.ReadInt32();
                    codeSectionInfo.Libraries  = LibraryRefInfo.ReadLibraries(reader, encoding);
                    minRequiredConstants       = reader.ReadInt16sWithByteSizePrefix();
                }
                else
                {
                    minRequiredDataTypes       = reader.ReadInt16sWithByteSizePrefix();
                    minRequiredConstants       = reader.ReadInt16sWithByteSizePrefix();
                    codeSectionInfo.Libraries  = LibraryRefInfo.ReadLibraries(reader, encoding);
                    codeSectionInfo.Flag       = reader.ReadInt32();
                    codeSectionInfo.MainMethod = reader.ReadInt32();
                }
                LibraryRefInfo.ApplyCompatibilityInfo(codeSectionInfo.Libraries, minRequiredCmds, minRequiredDataTypes, minRequiredConstants);
                if ((codeSectionInfo.Flag & 1) != 0)
                {
                    codeSectionInfo.UnknownBeforeIconData = reader.ReadBytes(16); // Unknown
                }
                codeSectionInfo.IconData = reader.ReadBytesWithLengthPrefix();
                codeSectionInfo.DebugCommandParameters = reader.ReadStringWithLengthPrefix(encoding);
                if (cryptEc)
                {
                    reader.ReadBytes(12);
                    codeSectionInfo.Methods         = MethodInfo.ReadMethods(reader, encoding);
                    codeSectionInfo.DllDeclares     = DllDeclareInfo.ReadDllDeclares(reader, encoding);
                    codeSectionInfo.GlobalVariables = AbstractVariableInfo.ReadVariables(reader, encoding, x => new GlobalVariableInfo(x));
                    codeSectionInfo.Classes         = ClassInfo.ReadClasses(reader, encoding);
                    codeSectionInfo.Structs         = StructInfo.ReadStructs(reader, encoding);
                }
                else
                {
                    codeSectionInfo.Classes         = ClassInfo.ReadClasses(reader, encoding);
                    codeSectionInfo.Methods         = MethodInfo.ReadMethods(reader, encoding);
                    codeSectionInfo.GlobalVariables = AbstractVariableInfo.ReadVariables(reader, encoding, x => new GlobalVariableInfo(x));
                    codeSectionInfo.Structs         = StructInfo.ReadStructs(reader, encoding);
                    codeSectionInfo.DllDeclares     = DllDeclareInfo.ReadDllDeclares(reader, encoding);
                }
            }
            return(codeSectionInfo);
        }