コード例 #1
0
ファイル: Project.cs プロジェクト: youxiaotian/dnSpy
        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);
        }
コード例 #2
0
 public ResourceElementSetTreeNode(ModuleDef module, EmbeddedResource er)
     : base(er)
 {
     this.module             = module;
     this.resourceElementSet = dnlib.DotNet.Resources.ResourceReader.Read(module, er.Data);
     this.LazyLoading        = true;
 }
コード例 #3
0
 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;
 }
コード例 #4
0
ファイル: Project.cs プロジェクト: youxiaotian/dnSpy
        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,
            });
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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());
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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"));
        }
コード例 #10
0
ファイル: Project.cs プロジェクト: youxiaotian/dnSpy
        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));
                }
            }
        }
コード例 #11
0
 public ResourceElementSetNodeImpl(ITreeNodeGroup treeNodeGroup, ModuleDef module, EmbeddedResource resource)
     : base(treeNodeGroup, resource)
 {
     this.module        = module;
     resourceElementSet = ResourceReader.Read(module, resource.GetReader());
 }
コード例 #12
0
 public ResourceElementSetNode(ITreeNodeGroup treeNodeGroup, ModuleDef module, EmbeddedResource resource)
     : base(treeNodeGroup, resource)
 {
     this.module             = module;
     this.resourceElementSet = ResourceReader.Read(module, resource.Data);
 }