public static EPackageInfo Parse(byte[] data) { var packageInfo = new EPackageInfo(); using (var reader = new BinaryReader(new MemoryStream(data, false))) { var nameList = new List <string>(); while (!(reader.BaseStream.Position == reader.BaseStream.Length)) { var name = reader.ReadStringWithLengthPrefix(); if ("".Equals(name)) { name = null; } nameList.Add(name); } packageInfo.FileNames = nameList.ToArray(); } return(packageInfo); }
public static EPackageInfo Parse(SectionInfo sectionInfo, bool cryptEc = false) { byte[] data = sectionInfo.Data; EPackageInfo ePackageInfo = new EPackageInfo(); using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(data, false))) { List <string> list = new List <string>(); while (binaryReader.BaseStream.Position != binaryReader.BaseStream.Length) { string text = binaryReader.ReadStringWithLengthPrefix(); if ("".Equals(text)) { text = null; } list.Add(text); } ePackageInfo.FileNames = list.ToArray(); } return(ePackageInfo); }
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(); }