bool IsXamlResource(ModuleDef module, string name, ResourceElementSet set) { var asm = module.Assembly; if (asm is null || !module.IsManifestModule) { return(false); } string culture = UTF8String.IsNullOrEmpty(asm.Culture) ? string.Empty : "." + asm.Culture; if (!StringComparer.OrdinalIgnoreCase.Equals(asm.Name + ".g" + culture + ".resources", name)) { return(false); } var elems = set.ResourceElements.ToArray(); if (elems.Length == 0) { return(false); } foreach (var e in elems) { if (!(e.ResourceData.Code == ResourceTypeCode.ByteArray || e.ResourceData.Code == ResourceTypeCode.Stream)) { return(false); } } return(true); }
public ResourceElementSetTreeNode(ModuleDef module, EmbeddedResource er) : base(er) { this.module = module; this.resourceElementSet = dnlib.DotNet.Resources.ResourceReader.Read(module, er.Data); this.LazyLoading = true; }
internal ResourceElementSetTreeNode(ModuleDef module, string name, ManifestResourceAttributes flags) : base(new EmbeddedResource(name, new byte[0], flags)) { this.module = module; RegenerateEmbeddedResource(module); this.resourceElementSet = dnlib.DotNet.Resources.ResourceReader.Read(module, ((EmbeddedResource)r).Data); this.LazyLoading = true; }
ResXProjectFile CreateResXFile(ModuleDef module, EmbeddedResource er, ResourceElementSet set, string filename, string typeFullName, bool isSatellite) { Debug.Assert(Options.CreateResX); if (!Options.CreateResX) { throw new InvalidOperationException(); } return(new ResXProjectFile(module, filename, typeFullName, er) { IsSatelliteFile = isSatellite, }); }
void RegenerateEmbeddedResource(ModuleDef module) { TreeNode.EnsureChildrenLoaded(); var outStream = new MemoryStream(); var resources = new ResourceElementSet(); foreach (ResourceElementNode child in TreeNode.DataChildren) { resources.Add(child.ResourceElement); } ResourceWriter.Write(module, outStream, resources); Resource = new EmbeddedResource(Resource.Name, outStream.ToArray(), Resource.Attributes); }
void RegenerateEmbeddedResource(ModuleDef module) { EnsureChildrenFiltered(); var outStream = new MemoryStream(); var resources = new ResourceElementSet(); foreach (ResourceElementTreeNode child in Children) { resources.Add(child.ResourceElement); } ResourceWriter.Write(module, outStream, resources); this.r = new EmbeddedResource(r.Name, outStream.ToArray(), r.Attributes); }
public byte[] convert() { var resources = new ResourceElementSet(); foreach (var info in infos) { resources.add(convert(info)); } var memStream = new MemoryStream(); ResourceWriter.write(module, memStream, resources); return(memStream.ToArray()); }
void RegenerateEmbeddedResource(ModuleDef module) { TreeNode.EnsureChildrenLoaded(); var outStream = new MemoryStream(); var resources = new ResourceElementSet(); foreach (DocumentTreeNodeData child in TreeNode.DataChildren) { var resourceElement = ResourceElementNode.GetResourceElement(child); if (resourceElement is null) { throw new InvalidOperationException(); } resources.Add(resourceElement); } ResourceWriter.Write(module, outStream, resources); Resource = new EmbeddedResource(Resource.Name, outStream.ToArray(), Resource.Attributes); }
public static void Build(string fullPath, string outputPath) { var mod = new ModuleDefUser(ModuleName, null, ModuleDefMD.Load(typeof(void).Module).Assembly.ToAssemblyRef()) { Kind = ModuleKind.Dll }; var ass = new AssemblyDefUser(AssemblyName, Version.Parse("1.0.0.0")); ass.Modules.Add(mod); //get resourceset var set = new ResourceElementSet(); foreach (ResourceElement re in FileFormatHelper.GetResourceElements(fullPath)) { set.Add(re); } //write set to byte[] and add to module resources using (var ms = new MemoryStream()) { ResourceWriter.Write(mod, ms, set); mod.Resources.Add(new EmbeddedResource(Resources, ms.ToArray(), ManifestResourceAttributes.Private)); } //create store type TypeDef store = new TypeDefUser(Namespace, ResourceStore, mod.CorLibTypes.Object.TypeDefOrRef) { Attributes = TypeAttributes.Public | TypeAttributes.BeforeFieldInit }; //add the type to the module mod.Types.Add(store); //add code BuildStore(mod, ref store); //write module mod.Write(Path.Combine(outputPath, "osu!ui-rebuilt.dll")); }
IEnumerable <ProjectFile> CreateXamlResourceFiles(ModuleDef module, ResourceNameCreator resourceNameCreator, ResourceElementSet set) { bool decompileBaml = Options.DecompileXaml && !(Options.DecompileBaml is null); foreach (var e in set.ResourceElements) { Debug.Assert(e.ResourceData.Code == ResourceTypeCode.ByteArray || e.ResourceData.Code == ResourceTypeCode.Stream); var data = (byte[])((BuiltInResourceData)e.ResourceData).Data; var rsrcName = Uri.UnescapeDataString(e.Name); if (decompileBaml && rsrcName.EndsWith(".baml", StringComparison.OrdinalIgnoreCase)) { var filename = resourceNameCreator.GetBamlResourceName(rsrcName, out string typeFullName); yield return(new BamlResourceProjectFile(filename, data, typeFullName, (bamlData, stream) => Options.DecompileBaml !(module, bamlData, Options.DecompilationContext.CancellationToken, stream))); } else if (StringComparer.InvariantCultureIgnoreCase.Equals(splashScreenImageName, e.Name)) { var filename = resourceNameCreator.GetXamlResourceFilename(rsrcName); yield return(new SplashScreenProjectFile(filename, data, e.Name)); } else { var filename = resourceNameCreator.GetXamlResourceFilename(rsrcName); yield return(new ResourceProjectFile(filename, data, e.Name)); } } }
public ResourceElementSetNodeImpl(ITreeNodeGroup treeNodeGroup, ModuleDef module, EmbeddedResource resource) : base(treeNodeGroup, resource) { this.module = module; resourceElementSet = ResourceReader.Read(module, resource.GetReader()); }
public ResourceElementSetNode(ITreeNodeGroup treeNodeGroup, ModuleDef module, EmbeddedResource resource) : base(treeNodeGroup, resource) { this.module = module; this.resourceElementSet = ResourceReader.Read(module, resource.Data); }