-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
59 lines (58 loc) · 2.25 KB
/
Program.cs
File metadata and controls
59 lines (58 loc) · 2.25 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using dnlib.DotNet.Emit;
using dnlib.DotNet;
using System.Windows.Forms;//tmp
namespace Smth
{
class Builder
{
// To use just add a class into your project.
// Paste this code. Add "DnLib" to your project (Project > Manage NuGet Packages...)
// Call Build and specify your parameters.
// path -> Where to save new binary
// file -> The main file. (Usually the "stub")
// replacements -> a 2d array in this format: {"ip", ip.Text}, {"port", port.Text}
// There is room for improvement lmk if you want to help :D
public async void Build(string path, byte[] file, string[,] replacements)
{
ModuleDefMD asmDef = ModuleDefMD.Load(file);
Modify(asmDef, path, replacements);
asmDef.Write(path);
asmDef.Dispose();
MessageBox.Show("Done!");
}
void Modify(ModuleDefMD asmDef, string AsmName, string[,] rep)
{
try
{
foreach (TypeDef type in asmDef.Types)
{
asmDef.Assembly.Name = Path.GetFileNameWithoutExtension(AsmName);
asmDef.Name = Path.GetFileName(AsmName);
foreach (MethodDef method in type.Methods)
{
if (method.Body == null) continue;
for (int i = 0; i < method.Body.Instructions.Count(); i++)
{
if (method.Body.Instructions[i].OpCode == OpCodes.Ldstr)
{
// Check for strings from the array & replace with new values.
for (int k = rep.Length / 2; k > 0; k--)
{
if (method.Body.Instructions[i].Operand.ToString() == rep[k - 1, 0])
method.Body.Instructions[i].Operand = rep[k - 1, 1];
}
}
}
}
}
}
catch { throw; }
}
}
}