Skip to content

Commit f52fbbf

Browse files
committed
Update for VMProtect 3.6.0
+ Search for pattern in 3.6.0 + Fixed --bypassantidebug crashing - Removed Costura
1 parent e29f3b9 commit f52fbbf

File tree

11 files changed

+40
-43
lines changed

11 files changed

+40
-43
lines changed

VMUP/VMUnprotect.Runtime/General/Engine.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Autofac;
22
using HarmonyLib;
3-
using System;
43
using System.Diagnostics;
54
using System.Runtime.CompilerServices;
65
using VMUnprotect.Runtime.Hooks;
@@ -33,12 +32,12 @@ internal static void Run(Project project) {
3332

3433
using var scope = Container.BeginLifetimeScope();
3534
ctx.Scope = scope;
36-
35+
3736
logger.Debug("Applying VMProtect hooks...");
3837
hooks.Initialize();
3938
hooks.ApplyHooks();
40-
41-
39+
40+
4241
logger.Debug("Invoking Target...");
4342
InvokeTarget(ctx, logger);
4443

VMUP/VMUnprotect.Runtime/General/Project.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void Run(ILogger logger, CommandLineOptions options) {
1616

1717
Engine.Initialize(this, logger, options);
1818

19-
19+
2020
Engine.Run(this);
2121
}
2222
}

VMUP/VMUnprotect.Runtime/Hooks/HooksManager.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@ public class HooksManager : Params, IHooksManager
1414

1515
public HooksManager(Context ctx, ILogger logger) : base(ctx, logger) { }
1616

17-
public void RestoreAll()
18-
{
17+
public void RestoreAll() {
1918
if (!_isApplied)
20-
{
2119
return;
22-
}
2320

2421
foreach (var patch in Ctx.Scope.Resolve<IEnumerable<IVmupHook>>()) {
2522
Logger.Debug($"Restoring hook {patch.GetType().Name}");

VMUP/VMUnprotect.Runtime/Hooks/Methods/AntiDebug/NtQueryInformationProcessPatch.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace VMUnprotect.Runtime.Hooks.Methods.AntiDebug
77
{
88
public class NtQueryInformationProcessPatch : Params, INtQueryInformationProcessPatch
99
{
10-
private IntPtr _ntQueryInformationProcessPtr = new(0);
10+
private IntPtr _ntQueryInformationProcessPtr = new(0x0);
1111
public NtQueryInformationProcessPatch(Context ctx, ILogger logger) : base(ctx, logger) { }
1212
private Delegate NtQueryInformationProcessDelegate { get; set; }
1313

@@ -30,7 +30,8 @@ public void GetDelegateForFunctionPointer(object __result, object[] parameters)
3030
if (parameters.Any(x => x.Equals("NtQueryInformationProcess")))
3131
_ntQueryInformationProcessPtr = (IntPtr) __result;
3232

33-
if (parameters.Any(x => x.Equals(_ntQueryInformationProcessPtr)))
33+
if (parameters.Any(x => x.Equals(_ntQueryInformationProcessPtr) &&
34+
_ntQueryInformationProcessPtr != new IntPtr(0x0)))
3435
NtQueryInformationProcessDelegate = (Delegate) __result;
3536
}
3637
}

VMUP/VMUnprotect.Runtime/Hooks/Methods/AssemblyFix/GetEntryAssemblyPatch.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,5 @@ public static void Postfix(ref Assembly __result) {
2424
public override void Patch(Harmony instance) {
2525
PatchPostfix(instance, TargetMethod);
2626
}
27-
2827
}
2928
}

VMUP/VMUnprotect.Runtime/Hooks/VmUnprotectPatch.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,16 @@ namespace VMUnprotect.Runtime.Hooks
1111
public abstract class VmUnprotectPatch : Params, IVmupHook
1212
{
1313
private readonly List<MethodBase> _activePatches = new();
14-
14+
1515
protected VmUnprotectPatch(Context ctx, ILogger logger) : base(ctx, logger) { }
1616

1717
public abstract void Patch(Harmony harmony);
1818

19-
public void Restore(Harmony harmony)
20-
{
19+
public void Restore(Harmony harmony) {
2120
foreach (var targetMethod in _activePatches)
2221
harmony.Unpatch(targetMethod, HarmonyPatchType.All, harmony.Id);
2322
}
24-
23+
2524
private HarmonyMethod GetHarmonyMethod(string methodName) {
2625

2726
var method = AccessTools.DeclaredMethod(GetType(), methodName);
@@ -77,7 +76,7 @@ private void PatchMultiple(
7776

7877
harmony.Patch(targetMethod, harmonyPrefixMethod, harmonyPostfixMethod, harmonyTranspilerMethod,
7978
harmonyFinalizerMethod);
80-
79+
8180
_activePatches.Add(targetMethod);
8281
}
8382
}

VMUP/VMUnprotect.Runtime/Structure/VmRuntimeAnalyzer.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ public void Discover() {
1717
if (functionHandler is null || vmTypeDef is null)
1818
throw new ApplicationException("Could not locate VmProtectFunctionHandler.");
1919

20-
Logger.Debug("Found VmTypeDef, MDToken 0x{0:X4}", vmTypeDef.MDToken);
21-
Logger.Debug("Found VMPFunctionHandler, MDToken 0x{0:X4}", functionHandler.MDToken);
22-
2320
Ctx.VmRuntimeStructure = new VmRuntimeStructure {
2421
FunctionHandler = functionHandler,
2522
VmTypeDef = vmTypeDef
@@ -46,19 +43,41 @@ private static (MethodDef vmpHandler, TypeDef vmTypeDef) LocateVmHandlerAndTypDe
4643
TypeDef vmTypeDef = null;
4744

4845
foreach (var type in module.GetTypes()) {
46+
// search pattern for 3.5.1 and older
4947
vmpHandler = type.Methods.Where(IsVmpFunctionHandler)
50-
.FirstOrDefault(method => new LocalTypes(method).All(VmpFunctionHandlerLocals));
48+
.FirstOrDefault(method => new LocalTypes(method).All(VmpFunctionHandlerLocals)) ?? type.Methods
49+
// Search for pattern in 3.6.0
50+
.Where(IsVmpFunctionHandlerNew)
51+
.FirstOrDefault(method => new LocalTypes(method).All(VmpFunctionHandlerLocals));
5152

5253
if (vmpHandler == null)
5354
continue;
5455

5556
vmTypeDef = type;
57+
58+
Logger.Info("Found VmTypeDef, MDToken 0x{0:X4}", vmTypeDef.MDToken);
59+
Logger.Info("Found VMPFunctionHandler, MDToken 0x{0:X4}", vmpHandler.MDToken);
5660
break;
5761
}
5862

63+
if (vmpHandler is null) {
64+
Logger.Error("Could not find VMP Method handler? Are you using supported version of VMP?");
65+
Console.ReadKey();
66+
}
67+
5968
return (vmpHandler, vmTypeDef);
6069
}
6170

71+
/// <summary>
72+
/// Checks RetType and Params, etc of MethodDef
73+
/// </summary>
74+
/// <param name="method"></param>
75+
/// <returns>Does method match the requirements</returns>
76+
private static bool IsVmpFunctionHandlerNew(MethodDef method) {
77+
return method is {IsStatic: false} && method.MethodSig.GetParamCount() == 0;
78+
}
79+
80+
6281
/// <summary>
6382
/// Checks RetType and Params, etc of MethodDef
6483
/// </summary>
@@ -70,7 +89,6 @@ private static bool IsVmpFunctionHandler(MethodDef method) {
7089
method.MethodSig.Params[0].GetElementType() == ElementType.Class &&
7190
method.MethodSig.Params[1].GetElementType() == ElementType.Boolean;
7291
}
73-
7492
#endregion
7593
}
7694

VMUP/VMUnprotect/Program.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ____ ____ ____ ____ _____ _____ _______
2020
\ ' / _| |_\/_| |_ \ \__/ / _| |_
2121
\_/ |_____||_____| `.__.' |_____|
2222
https://github.com/void-stack/VMUnprotect
23-
VMUnprotect Ultimate v 3.5.1
23+
VMUnprotect Ultimate v 3.6.0
2424
";
2525

2626
public static void Main(string[] args) {
@@ -36,8 +36,9 @@ public static void Main(string[] args) {
3636
var fullPath = Path.GetFullPath(options.FilePath!);
3737

3838
var logger = new ConsoleLogger(fileName);
39-
logger.Info("Doesn't work? Make sure you dump the file before with: https://github.com/void-stack/VMUnprotect.Dumper");
40-
39+
logger.Info(
40+
"Doesn't work? Make sure you dump the file before with: https://github.com/void-stack/VMUnprotect.Dumper");
41+
4142
var project = new Project {
4243
TargetFilePath = fullPath
4344
};

VMUP/VMUnprotect/Utils/ConsoleLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class ConsoleLogger : ILogger
1414
public ConsoleLogger(string filename) {
1515
if (Directory.Exists("VMUP_Logs"))
1616
Directory.CreateDirectory("VMUP_Logs");
17-
17+
1818
_logger = new LoggerConfiguration().WriteTo.File($"VMUP_Logs\\{filename}_{DateTime.Now:HH-mm-ss}.vmuplog")
1919
.WriteTo.Console(theme: AnsiConsoleTheme.Grayscale)
2020
.MinimumLevel.Verbose()

VMUP/VMUnprotect/VMUnprotect.csproj

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="..\packages\Costura.Fody.5.7.0\build\Costura.Fody.props" Condition="Exists('..\packages\Costura.Fody.5.7.0\build\Costura.Fody.props')"/>
43
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"/>
54
<PropertyGroup>
65
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -46,10 +45,6 @@
4645
<HintPath>..\packages\CommandLineParser.2.9.0-preview1\lib\net461\CommandLine.dll</HintPath>
4746
<Private>True</Private>
4847
</Reference>
49-
<Reference Include="Costura, Version=5.7.0.0, Culture=neutral, PublicKeyToken=null">
50-
<HintPath>..\packages\Costura.Fody.5.7.0\lib\netstandard1.0\Costura.dll</HintPath>
51-
<Private>True</Private>
52-
</Reference>
5348
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51">
5449
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.1.1.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
5550
<Private>True</Private>
@@ -218,16 +213,6 @@
218213
</ProjectReference>
219214
</ItemGroup>
220215
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
221-
<Import Project="..\packages\Fody.6.5.5\build\Fody.targets" Condition="Exists('..\packages\Fody.6.5.5\build\Fody.targets')"/>
222-
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
223-
<PropertyGroup>
224-
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
225-
</PropertyGroup>
226-
<Error Condition="!Exists('..\packages\Fody.6.5.5\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.6.5.5\build\Fody.targets'))"/>
227-
<Error Condition="!Exists('..\packages\Costura.Fody.5.7.0\build\Costura.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.5.7.0\build\Costura.Fody.props'))"/>
228-
<Error Condition="!Exists('..\packages\Costura.Fody.5.7.0\build\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.5.7.0\build\Costura.Fody.targets'))"/>
229-
</Target>
230-
<Import Project="..\packages\Costura.Fody.5.7.0\build\Costura.Fody.targets" Condition="Exists('..\packages\Costura.Fody.5.7.0\build\Costura.Fody.targets')"/>
231216
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
232217
Other similar extension points exist, see Microsoft.Common.targets.
233218
<Target Name="BeforeBuild">

0 commit comments

Comments
 (0)