-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
65 lines (47 loc) · 1.88 KB
/
Program.cs
File metadata and controls
65 lines (47 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using dnlib.DotNet;
using dnlib.DotNet.Writer;
using dnlib.DotNet.MD;
foreach (var s in args)
{
PatchDLL(s);
}
static void PatchDLL(string dllPath)
{
Console.WriteLine("reading: " + dllPath);
ModuleDef module = ModuleDefMD.Load(dllPath);
var entry = module?.Find("Assistant.Engine", true)?.FindMethod("Install");
if (entry != null && entry.IsStatic && entry.IsPublic)
{
entry.ExportInfo = new MethodExportInfo();
entry.IsUnmanagedExport = true;
if (module.EntryPoint != null)
{
Console.WriteLine("entry point removed");
module.EntryPoint = null;
}
ModuleWriterOptions opts = new ModuleWriterOptions(module);
opts.PEHeadersOptions.Machine = dnlib.PE.Machine.AMD64;
opts.Cor20HeaderOptions.Flags &= ~ComImageFlags.ILOnly;
if ((opts.PEHeadersOptions.Characteristics & dnlib.PE.Characteristics.Dll) == 0)
{
Console.WriteLine("file converted to DLL");
opts.PEHeadersOptions.Characteristics |= dnlib.PE.Characteristics.Dll;
}
if ((opts.PEHeadersOptions.Characteristics & dnlib.PE.Characteristics.Bit32Machine) != 0)
{
Console.WriteLine("removed 32 bit support.");
opts.PEHeadersOptions.Characteristics &= ~dnlib.PE.Characteristics.Bit32Machine;
}
opts.PEHeadersOptions.Characteristics |= dnlib.PE.Characteristics.LargeAddressAware;
opts.ModuleKind = ModuleKind.Dll;
Console.WriteLine("writing asm...");
string path = Path.GetDirectoryName(dllPath);
string name = Path.GetFileName(dllPath).Replace(".exe", ".dll").Replace(".dll", ".FIXED.dll");
module.Write(Path.Combine(path, name), opts);
Console.WriteLine("done");
}
else
{
Console.WriteLine("impossible to find the 'Assitant.Engine.Install' method");
}
}