コード例 #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);
        }
コード例 #2
0
ファイル: CodeSectionInfo.cs プロジェクト: hfen-cn/econv
 public void WriteTo(BinaryWriter writer)
 {
     writer.Write(UnknownBeforeLibrary);
     LibraryInfo.WriteLibraries(writer, Libraries);
     writer.Write(UnknownBeforeIconData);
     writer.WriteBytesWithLengthPrefix(IconData);
     writer.WriteStringWithLengthPrefix(DebugCommandParameters);
     ClassInfo.WriteClasses(writer, Classes);
     MethodInfo.WriteMethods(writer, Methods);
     VariableInfo.WriteVariables(writer, GlobalVariables);
     StructInfo.WriteStructs(writer, Structs);
     DllDeclareInfo.WriteDllDeclares(writer, DllDeclares);
     writer.Write(new byte[40]);
 }
コード例 #3
0
ファイル: CodeSectionInfo.cs プロジェクト: hfen-cn/econv
        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);
        }