Skip to content

Instantly share code, notes, and snippets.

@SlowLogicBoy
Last active April 21, 2017 13:08
Show Gist options
  • Save SlowLogicBoy/ab7ececdbdbb8c2677f53bb0151a9550 to your computer and use it in GitHub Desktop.
Save SlowLogicBoy/ab7ececdbdbb8c2677f53bb0151a9550 to your computer and use it in GitHub Desktop.
Eto.Wpf merge issue
#r "Path\To\dnlib.dll"
using System.Diagnostics;
using dnlib.DotNet;
using dnlib.DotNet.Emit;
public static void LogErr(string format, params object[] args)
{
Console.WriteLine(format, args);
}
public static string Join(this IEnumerable<string> self, string separator)
{
return string.Join(separator, self);
}
public static void Try(Action action)
{
try
{
action();
}
catch (Exception ex)
{
LogErr(ex.ToString());
}
}
const string vanilaCompiled = @"Path\To\Unpacked.exe";
const string packer = @"Path\To\ILRepack.exe";
static readonly string[] dllsToPack = new []{
...
};
const string etowpf = @"Path\To\Eto.Wpf.dll";
const string output = @"MyAssembly.exe";
const string moduleName = "MyModuleName";
//cleanup
Try(() => File.Delete(output));
//Pack dlls
var p = Process.Start($"{packer}", $"{vanilaCompiled} {dllsToPack.Join(" ")} /out:{output}");
p.WaitForExit();
if(p.ExitCode != 0)
{
LogErr("packing failed");
}
//Fix Eto.Wpf
var plModule = ModuleDefMD.Load(File.ReadAllBytes(output));
//Replace resources
var etoModule = ModuleDefMD.Load(File.ReadAllBytes(etowpf));
var res = etoModule.Resources.First();
var badone = plModule.Resources.Single(s => s.Name == res.Name);
plModule.Resources.Remove(badone);
res.Name = $"{moduleName}.g.resources";
plModule.Resources.Add(res);
//Change url
var opCode = plModule.Types.Single(t => t.FullName == "Eto.Wpf.Forms.ApplicationHandler")
.Methods.Single(m => m.Name == "ApplyThemes")
.Body.Instructions.Single(i => i.OpCode == OpCodes.Ldstr);
opCode.Operand = $"pack://application:,,,/{moduleName};component/themes/wpftoolkit/ButtonSpinner.xaml";
plModule.Write(output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment