public static void Extract(string fullPath) { Logger.Info($"Creating output directories in '{OutputDir}'..."); Directory.CreateDirectory(OutputDir); Directory.CreateDirectory(Path.Combine(OutputDir, OutputDirOriginal)); Directory.CreateDirectory(Path.Combine(OutputDir, OutputDirEdit)); Logger.Info("Loading module..."); var mod = ModuleDefMD.Load(fullPath); var res = mod.Resources; Debug.Assert(mod.Types.Count == 2, "Too many/little types"); Debug.Assert(mod.Types[1].Namespace == Namespace, "Invalid namespace for resource type"); Debug.Assert(res.Count == 1, "Invalid amount of resources"); Debug.Assert(res[0] is EmbeddedResource, "Resource is not embedded"); Debug.Assert(res[0].Name == Resources, "Invalid resource name"); if (res.Count != 1 || !(res[0] is EmbeddedResource r) || r.Name != Resources) { throw new Exception("Invalid dll"); } Logger.Info("Saving resources..."); foreach (var element in ResourceReader.Read(mod, r.Data).ResourceElements) { Logger.Debug(element.ToString()); //save ResourceBase b = FileFormatHelper.ToFileFormat(element, out string category); if (b.GetType() == typeof(UnknownResource)) { Logger.Warn("Unknown resource detected: " + element.Name); } else { Logger.Debug("\tCreated " + b.GetType().Name); } string catFolder = Path.Combine(OutputDir, OutputDirOriginal, category); Directory.CreateDirectory(catFolder); using (FileStream fs = File.OpenWrite(Path.Combine(catFolder, (b.FileName ?? element.Name) + b.FileExtension))) b.Deserialize(fs); } }
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")); }