/// <summary> /// CodeSectionInfo改变时必须重新创建IDToNameMap以便更新数据(尽管部分数据可能自动更新) /// </summary> /// <param name="codeSection"></param> public IdToNameMap(CodeSectionInfo codeSection, ResourceSectionInfo resourceSection) { LibDefinedName = codeSection.Libraries.Select(x => { try { return(LibInfo.LibInfo.Load(x)); } catch (Exception) { return(null); } }).ToArray(); UserDefinedName = new Dictionary <int, string>(); foreach (var method in codeSection.Methods) { UserDefinedName.Add(method.Id, method.Name); Array.ForEach(method.Parameters, x => UserDefinedName.Add(x.Id, x.Name)); Array.ForEach(method.Variables, x => UserDefinedName.Add(x.Id, x.Name)); } foreach (var dll in codeSection.DllDeclares) { UserDefinedName.Add(dll.Id, dll.Name); Array.ForEach(dll.Parameters, x => UserDefinedName.Add(x.Id, x.Name)); } foreach (var classInfo in codeSection.Classes) { UserDefinedName.Add(classInfo.Id, classInfo.Name); Array.ForEach(classInfo.Variables, x => UserDefinedName.Add(x.Id, x.Name)); } foreach (var structInfo in codeSection.Structs) { UserDefinedName.Add(structInfo.Id, structInfo.Name); Array.ForEach(structInfo.Member, x => UserDefinedName.Add(x.Id, x.Name)); } Array.ForEach(codeSection.GlobalVariables, x => UserDefinedName.Add(x.Id, x.Name)); Array.ForEach(resourceSection.Constants, x => UserDefinedName.Add(x.Id, x.Name)); foreach (var formInfo in resourceSection.Forms) { UserDefinedName.Add(formInfo.Id, formInfo.Name); Array.ForEach(formInfo.Elements, x => UserDefinedName.Add(x.Id, x.Name)); } var needToRemove = new List <int>(); foreach (var item in UserDefinedName) { if (string.IsNullOrEmpty(item.Value)) { needToRemove.Add(item.Key); } } needToRemove.ForEach(x => UserDefinedName.Remove(x)); }
public static ResourceSectionInfo Parse(byte[] data) { ResourceSectionInfo resourceSectionInfo; using (var reader = new BinaryReader(new MemoryStream(data, false))) { resourceSectionInfo = new ResourceSectionInfo() { Forms = FormInfo.ReadForms(reader), Constants = ConstantInfo.ReadConstants(reader) }; } return(resourceSectionInfo); }
public void Load(Stream stream, ProjectFileReader.OnInputPassword inputPassword = null) { ESystemInfo = null; ProjectConfigInfo = null; Resource = null; Code = null; EPackageInfo = null; InitEcSectionInfo = null; LosableSection = null; FolderSection = null; EcSection = EcSection2 = AuxiliarySection2 = AuxiliarySection3 = EditInfoSection2 = AuxiliarySection1 = null; OtherSections = new List <SectionInfo>(); using (var reader = new ProjectFileReader(stream, inputPassword)) { var processor = new Dictionary <int, Action <SectionInfo> > { { ESystemInfo.SectionKey, x => ESystemInfo = ESystemInfo.Parse(x.Data) }, { ProjectConfigInfo.SectionKey, x => ProjectConfigInfo = ProjectConfigInfo.Parse(x.Data, Encoding) }, { ResourceSectionInfo.SectionKey, x => Resource = ResourceSectionInfo.Parse(x.Data, Encoding) }, { CodeSectionInfo.SectionKey, x => Code = CodeSectionInfo.Parse(x.Data, Encoding, reader.CryptEc) }, { EPackageInfo.SectionKey, x => EPackageInfo = EPackageInfo.Parse(x.Data, Encoding) }, { InitEcSectionInfo.SectionKey, x => InitEcSectionInfo = InitEcSectionInfo.Parse(x.Data, Encoding) }, { 0x0C007319, x => EcSection = x.Data }, { 0x0F007319, x => EcSection2 = x.Data }, { 0x0B007319, x => AuxiliarySection2 = x.Data }, { LosableSectionInfo.SectionKey, x => LosableSection = LosableSectionInfo.Parse(x.Data, Encoding) }, { 0x10007319, x => AuxiliarySection3 = x.Data }, { 0x09007319, x => EditInfoSection2 = x.Data }, { 0x0A007319, x => AuxiliarySection1 = x.Data }, { FolderSectionInfo.SectionKey, x => FolderSection = FolderSectionInfo.Parse(x.Data, Encoding) } }; while (!reader.IsFinish) { var section = reader.ReadSection(); switch (section.Key) { case int key when processor.ContainsKey(key): processor[key](section); break; default: OtherSections.Add(section); break; } } } }
/// <summary> /// <paramref name="codeSection"/>或<paramref name="resourceSection"/>或<paramref name="losableSection"/>改变时必须重新创建IDToNameMap以便更新数据(尽管部分数据可能自动更新) /// </summary> /// <param name="codeSection">程序段</param> /// <param name="resourceSection">资源段</param> /// <param name="losableSection">可丢失程序段</param> public IdToNameMap(CodeSectionInfo codeSection, ResourceSectionInfo resourceSection, LosableSectionInfo losableSection) : this(codeSection?.Libraries) { if (codeSection != null) { foreach (var method in codeSection.Methods) { if (string.IsNullOrEmpty(method.Name)) { var symbol = ParseDebugComment(method.Comment); if (symbol != null) { UserDefinedName.Add(method.Id, symbol); } } else { UserDefinedName.Add(method.Id, method.Name); } Array.ForEach(method.Parameters, x => UserDefinedName.Add(x.Id, x.Name)); Array.ForEach(method.Variables, x => UserDefinedName.Add(x.Id, x.Name)); } foreach (var dll in codeSection.DllDeclares) { UserDefinedName.Add(dll.Id, dll.Name); Array.ForEach(dll.Parameters, x => UserDefinedName.Add(x.Id, x.Name)); } foreach (var classInfo in codeSection.Classes) { foreach (var item in classInfo.Method) { MethodIdToClassId[item] = classInfo.Id; } if (string.IsNullOrEmpty(classInfo.Name)) { var symbol = ParseDebugComment(classInfo.Comment); if (symbol != null) { UserDefinedName.Add(classInfo.Id, symbol); } } else { UserDefinedName.Add(classInfo.Id, classInfo.Name); } Array.ForEach(classInfo.Variables, x => UserDefinedName.Add(x.Id, x.Name)); } foreach (var structInfo in codeSection.Structs) { UserDefinedName.Add(structInfo.Id, structInfo.Name); Array.ForEach(structInfo.Member, x => UserDefinedName.Add(x.Id, x.Name)); } Array.ForEach(codeSection.GlobalVariables, x => UserDefinedName.Add(x.Id, x.Name)); } if (resourceSection != null) { Array.ForEach(resourceSection.Constants, x => UserDefinedName.Add(x.Id, x.Name)); foreach (var formInfo in resourceSection.Forms) { UserDefinedName.Add(formInfo.Id, formInfo.Name); Array.ForEach(formInfo.Elements, x => UserDefinedName.Add(x.Id, x.Name)); } } if (losableSection != null) { Array.ForEach(losableSection.RemovedDefinedItem, x => UserDefinedName.Add(x.Id, x.Name)); } if (codeSection.MainMethod != 0) { UserDefinedName[codeSection.MainMethod] = "_启动子程序"; } // 处理无名对象 var needToRemove = new List <int>(); foreach (var item in UserDefinedName) { if (string.IsNullOrEmpty(item.Value)) { needToRemove.Add(item.Key); } } needToRemove.ForEach(x => UserDefinedName.Remove(x)); }
/// <summary> /// <paramref name="codeSection"/>或<paramref name="resourceSection"/>改变时必须重新创建IDToNameMap以便更新数据(尽管部分数据可能自动更新) /// </summary> /// <param name="codeSection">程序段</param> /// <param name="resourceSection">资源段</param> public IdToNameMap(CodeSectionInfo codeSection, ResourceSectionInfo resourceSection) : this(codeSection, resourceSection, null) { }
/// <summary> /// <paramref name="codeSection"/>或<paramref name="resourceSection"/>或<paramref name="losableSection"/>改变时必须重新创建IDToNameMap以便更新数据(尽管部分数据可能自动更新) /// </summary> /// <param name="codeSection">程序段</param> /// <param name="resourceSection">资源段</param> /// <param name="losableSection">可丢失程序段</param> public IdToNameMap(CodeSectionInfo codeSection, ResourceSectionInfo resourceSection, LosableSectionInfo losableSection) { libDefinedName = codeSection.Libraries.Select(x => { try { return(LibInfo.LibInfo.Load(x)); } catch (Exception) { return(null); } }).ToArray(); userDefinedName = new Dictionary <int, string>(); if (codeSection != null) { foreach (var method in codeSection.Methods) { if (string.IsNullOrEmpty(method.Name)) { var symbol = ParseDebugComment(method.Comment); if (symbol != null) { userDefinedName.Add(method.Id, symbol); } } else { userDefinedName.Add(method.Id, method.Name); } Array.ForEach(method.Parameters, x => userDefinedName.Add(x.Id, x.Name)); Array.ForEach(method.Variables, x => userDefinedName.Add(x.Id, x.Name)); } foreach (var dll in codeSection.DllDeclares) { userDefinedName.Add(dll.Id, dll.Name); Array.ForEach(dll.Parameters, x => userDefinedName.Add(x.Id, x.Name)); } foreach (var classInfo in codeSection.Classes) { userDefinedName.Add(classInfo.Id, classInfo.Name); Array.ForEach(classInfo.Variables, x => userDefinedName.Add(x.Id, x.Name)); } foreach (var structInfo in codeSection.Structs) { userDefinedName.Add(structInfo.Id, structInfo.Name); Array.ForEach(structInfo.Member, x => userDefinedName.Add(x.Id, x.Name)); } Array.ForEach(codeSection.GlobalVariables, x => userDefinedName.Add(x.Id, x.Name)); } if (resourceSection != null) { Array.ForEach(resourceSection.Constants, x => userDefinedName.Add(x.Id, x.Name)); foreach (var formInfo in resourceSection.Forms) { userDefinedName.Add(formInfo.Id, formInfo.Name); Array.ForEach(formInfo.Elements, x => userDefinedName.Add(x.Id, x.Name)); } } if (losableSection != null) { Array.ForEach(losableSection.RemovedDefinedItem, x => userDefinedName.Add(x.Id, x.Name)); } if (codeSection.MainMethod != 0) { userDefinedName[codeSection.MainMethod] = "_启动子程序"; } // 处理无名对象 var needToRemove = new List <int>(); foreach (var item in userDefinedName) { if (string.IsNullOrEmpty(item.Value)) { needToRemove.Add(item.Key); } } needToRemove.ForEach(x => userDefinedName.Remove(x)); }