public static ProjectConfigInfo Parse(SectionInfo sectionInfo, bool cryptEc = false) { byte[] data = sectionInfo.Data; ProjectConfigInfo projectConfigInfo = new ProjectConfigInfo(); using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(data, false))) { projectConfigInfo.Name = binaryReader.ReadStringWithLengthPrefix(); projectConfigInfo.Description = binaryReader.ReadStringWithLengthPrefix(); projectConfigInfo.Author = binaryReader.ReadStringWithLengthPrefix(); projectConfigInfo.ZipCode = binaryReader.ReadStringWithLengthPrefix(); projectConfigInfo.Address = binaryReader.ReadStringWithLengthPrefix(); projectConfigInfo.TelephoneNumber = binaryReader.ReadStringWithLengthPrefix(); projectConfigInfo.FaxNumber = binaryReader.ReadStringWithLengthPrefix(); projectConfigInfo.Email = binaryReader.ReadStringWithLengthPrefix(); projectConfigInfo.Homepage = binaryReader.ReadStringWithLengthPrefix(); projectConfigInfo.CopyrightNotice = binaryReader.ReadStringWithLengthPrefix(); projectConfigInfo.Version = new Version(binaryReader.ReadInt32(), binaryReader.ReadInt32(), binaryReader.ReadInt32(), binaryReader.ReadInt32()); projectConfigInfo.NotWriteVersion = (binaryReader.ReadInt32() != 0); projectConfigInfo.CompilePlugins = binaryReader.ReadStringWithFixedLength(20); projectConfigInfo.ExportPublicClassMethod = (binaryReader.ReadInt32() != 0); } return(projectConfigInfo); }
public static ProjectConfigInfo Parse(byte[] data) { var projectConfig = new ProjectConfigInfo(); using (var reader = new BinaryReader(new MemoryStream(data, false))) { projectConfig.Name = reader.ReadStringWithLengthPrefix(); projectConfig.Description = reader.ReadStringWithLengthPrefix(); projectConfig.Author = reader.ReadStringWithLengthPrefix(); projectConfig.ZipCode = reader.ReadStringWithLengthPrefix(); projectConfig.Address = reader.ReadStringWithLengthPrefix(); projectConfig.TelephoneNumber = reader.ReadStringWithLengthPrefix(); projectConfig.FaxNumber = reader.ReadStringWithLengthPrefix(); projectConfig.Email = reader.ReadStringWithLengthPrefix(); projectConfig.Homepage = reader.ReadStringWithLengthPrefix(); projectConfig.CopyrightNotice = reader.ReadStringWithLengthPrefix(); projectConfig.Version = new Version(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32()); projectConfig.WriteVersion = reader.ReadInt32() == 0; projectConfig.CompilePlugins = reader.ReadStringWithFixedLength(20); projectConfig.ExportPublicClassMethod = reader.ReadInt32() != 0; } return(projectConfig); }
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(); }