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); }
public static CodeSectionInfo Parse(byte[] data, bool cryptEc = false) { var codeSectionInfo = new CodeSectionInfo(); using (var reader = new BinaryReader(new MemoryStream(data, false))) { codeSectionInfo.AllocatedIdNum = reader.ReadInt32(); reader.ReadInt32(); //确认于易语言V5.71 codeSectionInfo.UnknownBeforeLibrary_1 = reader.ReadBytesWithLengthPrefix(); //Unknown if (cryptEc) { reader.ReadInt32(); reader.ReadInt32(); codeSectionInfo.UnknownBeforeLibrary_2 = reader.ReadBytesWithLengthPrefix();//Unknown codeSectionInfo.Flag = reader.ReadInt32(); codeSectionInfo.MainMethod = reader.ReadInt32(); codeSectionInfo.Libraries = LibraryRefInfo.ReadLibraries(reader); codeSectionInfo.UnknownBeforeLibrary_3 = reader.ReadBytesWithLengthPrefix();//Unknown } else { codeSectionInfo.UnknownBeforeLibrary_2 = reader.ReadBytesWithLengthPrefix(); //Unknown codeSectionInfo.UnknownBeforeLibrary_3 = reader.ReadBytesWithLengthPrefix(); //Unknown codeSectionInfo.Libraries = LibraryRefInfo.ReadLibraries(reader); codeSectionInfo.Flag = reader.ReadInt32(); codeSectionInfo.MainMethod = reader.ReadInt32(); } ; if ((codeSectionInfo.Flag & 1) != 0) { codeSectionInfo.UnknownBeforeIconData = reader.ReadBytes(16);//Unknown } 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 = AbstractVariableInfo.ReadVariables(reader, x => new GlobalVariableInfo(x)); codeSectionInfo.Classes = ClassInfo.ReadClasses(reader); codeSectionInfo.Structs = StructInfo.ReadStructs(reader); } else { codeSectionInfo.Classes = ClassInfo.ReadClasses(reader); codeSectionInfo.Methods = MethodInfo.ReadMethods(reader); codeSectionInfo.GlobalVariables = AbstractVariableInfo.ReadVariables(reader, x => new GlobalVariableInfo(x)); codeSectionInfo.Structs = StructInfo.ReadStructs(reader); codeSectionInfo.DllDeclares = DllDeclareInfo.ReadDllDeclares(reader); } } return(codeSectionInfo); }
private void WriteTo(BinaryWriter writer, Encoding encoding) { writer.Write(allocatedIdNum); writer.Write(51113791); // 确认于易语言V5.71 LibraryRefInfo.WriteLibraries(writer, encoding, Libraries); writer.Write(Flag); writer.Write(MainMethod); if (UnknownBeforeIconData != null) { writer.WriteBytesWithLengthPrefix(UnknownBeforeIconData); } writer.WriteBytesWithLengthPrefix(IconData); writer.WriteStringWithLengthPrefix(encoding, DebugCommandParameters); ClassInfo.WriteClasses(writer, encoding, Classes); MethodInfo.WriteMethods(writer, encoding, Methods); AbstractVariableInfo.WriteVariables(writer, encoding, GlobalVariables); StructInfo.WriteStructs(writer, encoding, Structs); DllDeclareInfo.WriteDllDeclares(writer, encoding, DllDeclares); writer.Write(new byte[40]); // Unknown(40个0) }