Skip to content

Commit 06aacf3

Browse files
committed
Added support for vmp 3.7.0
1 parent 7b1d62c commit 06aacf3

File tree

4 files changed

+60
-23
lines changed

4 files changed

+60
-23
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ obj/
44
/packages/
55
riderModule.iml
66
/_ReSharper.Caches/
7+
.vs/VMUnprotect/v17/.suo

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<img width="256" heigth="256" src="docs\vmup.png">
33
<h1 align="center">VMUnprotect.Dumper</h1>
44
<p align="center">
5-
<strong>VMUnprotect.Dumper</strong> is a project engaged in hunting tampered <strong>VMProtect assemblies</strong>. It makes use of <a href="https://github.com/pardeike/Harmony">AsmResolver</a> to dynamically unpack <strong>VMP</strong> protected assembly. Works on <a href="https://vmpsoft.com/20210919/vmprotect-3-5-1/">VMProtect 3.5.1</a> (Latest) and few versions back.
5+
<strong>VMUnprotect.Dumper</strong> is a project engaged in hunting tampered <strong>VMProtect assemblies</strong>. It makes use of <a href="https://github.com/pardeike/Harmony">AsmResolver</a> to dynamically unpack <strong>VMP</strong> protected assembly. Works on <a href="https://vmpsoft.com/20220827/vmprotect-3-7/">VMProtect 3.7.0</a> (Latest) and few versions back.
66
</p>
77
</p>
88
<p align="center">

VMUnprotect.Dumper/Program.cs

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// See https://aka.ms/new-console-template for more information
2-
using AsmResolver.IO;
3-
using AsmResolver.PE.File;
4-
using System;
5-
using System.IO;
2+
63
using System.Reflection;
74
using System.Runtime.CompilerServices;
85
using System.Runtime.InteropServices;
6+
using AsmResolver.DotNet;
7+
using AsmResolver.IO;
8+
using AsmResolver.PE.File;
9+
using Sharprompt;
910

1011
const string asciiArt = @"
1112
_________ __
@@ -18,34 +19,68 @@ _________ __
1819
https://github.com/void-stack
1920
Credits: wwh1004, MrToms
2021
";
21-
22+
2223
Console.Title = "VMUnprotect.Dumper";
2324
Console.WriteLine(asciiArt);
2425

25-
if (args.Length > 0 && File.Exists(args[0])) {
26-
var target = args[0];
26+
string? target;
27+
28+
if (args.Length > 0 && File.Exists(args[0]))
29+
target = Prompt.Input<string>("Enter file path", args[0]);
30+
else
31+
target = Prompt.Input<string>("Enter file path");
32+
33+
if (File.Exists(target))
34+
{
2735
var output = $"{Path.GetFileNameWithoutExtension(target)}-decrypted.exe";
28-
var assembly = Assembly.LoadFile(target);
29-
var moduleHandle = assembly.ManifestModule.ModuleHandle;
36+
Assembly? assembly = null;
37+
38+
try
39+
{
40+
assembly = Assembly.LoadFile(target);
41+
}
42+
catch (BadImageFormatException)
43+
{
44+
Console.WriteLine("Target app probably has a different framework.");
45+
}
3046

31-
Console.WriteLine("[+] Decrypting methods");
32-
RuntimeHelpers.RunModuleConstructor(moduleHandle);
33-
var hInstanceFixed = Marshal.GetHINSTANCE(assembly.ManifestModule);
47+
var manifestModule = assembly.ManifestModule;
3448

35-
Console.WriteLine("[+] Reading decrypted module");
36-
var decryptedPeFile = PEFile.FromModuleBaseAddress(hInstanceFixed);
49+
var module = ModuleDefinition.FromFile(target);
3750

38-
foreach (var section in decryptedPeFile.Sections)
39-
Console.WriteLine("[+] Sections: " + section.Name);
51+
var cctor =
52+
assembly.ManifestModule.ResolveMethod(module.TopLevelTypes[0].GetStaticConstructor()!.MetadataToken.ToInt32());
4053

41-
Console.WriteLine("[+] Writing file");
42-
using (var fs = File.Create(output)) {
43-
decryptedPeFile.Write(new BinaryStreamWriter(fs));
44-
}
54+
var hInstance = Marshal.GetHINSTANCE(manifestModule);
55+
56+
if (cctor != null)
57+
{
58+
RuntimeHelpers.PrepareMethod(cctor.MethodHandle);
59+
60+
var diskImage = PEFile.FromFile(target);
61+
62+
var epFromDisk = diskImage.OptionalHeader.AddressOfEntrypoint;
63+
var runtimeImage = PEFile.FromModuleBaseAddress(hInstance, PEMappingMode.Mapped);
64+
var optionalHeader = runtimeImage.OptionalHeader;
4565

46-
Console.WriteLine("[+] Decrypted all methods!");
66+
optionalHeader.Magic = diskImage.OptionalHeader.Magic;
67+
optionalHeader.AddressOfEntrypoint = epFromDisk;
68+
69+
using (var fs = File.Create(output))
70+
{
71+
runtimeImage.Write(new BinaryStreamWriter(fs));
72+
}
73+
74+
Console.WriteLine($"Saved as: {Path.GetFullPath(output)}");
75+
}
76+
else
77+
{
78+
Console.WriteLine("Failed to prepare .cctor");
79+
}
4780
}
48-
else
81+
else
82+
{
4983
Console.WriteLine("File either doesn't exist or you didn't provide it (VMProtect.Dumper File.exe)");
84+
}
5085

5186
Console.ReadKey();

VMUnprotect.Dumper/VMUnprotect.Dumper.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<PackageReference Include="AsmResolver" Version="4.8.0" />
1313
<PackageReference Include="AsmResolver.DotNet" Version="4.8.0" />
1414
<PackageReference Include="AsmResolver.PE" Version="4.8.0" />
15+
<PackageReference Include="Sharprompt" Version="2.4.4" />
1516
</ItemGroup>
1617

1718
</Project>

0 commit comments

Comments
 (0)