Skip to content

Commit fdb43d5

Browse files
committed
Added StackTrace to notify where the current invoke was called from, fixed parameters not changing
1 parent c45593f commit fdb43d5

File tree

4 files changed

+43
-35
lines changed

4 files changed

+43
-35
lines changed

README.md

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<img width="256" heigth="256" src="VMUP/media/vmup.png">
33
<h1 align="center">VMUnprotect.NET</h1>
44
<p align="center">
5-
<strong>VMUnprotect</strong> is a project engaged in hunting virtualized <a href="https://vmpsoft.com">VMProtect</a> methods. It makes use of <a href="https://github.com/pardeike/Harmony">Harmony</a> to dynamically read <strong>VMP</strong> behavior. Currently only supports method administration. Currently supports <a href="https://vmpsoft.com/20210919/vmprotect-3-5-1/">VMProtect 3.5.1</a> (Lasted) and few versions back.
5+
<strong>VMUnprotect</strong> is a project engaged in hunting virtualized <a href="https://vmpsoft.com">VMProtect</a> methods. It makes use of <a href="https://github.com/pardeike/Harmony">Harmony</a> to dynamically read <strong>VMP</strong> behavior. Currently only supports method administration. Works on <a href="https://vmpsoft.com/20210919/vmprotect-3-5-1/">VMProtect 3.5.1</a> (Latest) and few versions back.
66
</p>
77
</p>
88
<p align="center">
@@ -14,7 +14,7 @@
1414
## Showcase
1515
<img src="VMUP/media/gif.gif">
1616

17-
## Usage
17+
# Usage
1818
```sh
1919
VMUnprotect.exe <path to assembly> [args to assembly]
2020
```
@@ -32,7 +32,7 @@ Virtualization Tools | Yes
3232
Strip Debug Information | Yes
3333
Pack the Output File | No
3434

35-
## Usage can be found in ```MiddleMan.cs```
35+
# Usage can be found in ```MiddleMan.cs```
3636
```csharp
3737
namespace VMUnprotect
3838
{
@@ -44,15 +44,21 @@ namespace VMUnprotect
4444
/// <summary>
4545
/// This function manipulate can manipulate, log actual invokes from virtualized VMP functions.
4646
/// </summary>
47-
public static void VmpMethodLogger(
48-
object obj,
49-
BindingFlags? bindingFlags,
50-
Binder binder,
51-
ref object[] parameters,
52-
CultureInfo culture,
53-
MethodBase methodBase,
54-
ref object returnValue)
47+
public static object VmpMethodLogger(object obj, BindingFlags? bindingFlags, Binder binder, ref object[] parameters, CultureInfo culture, MethodBase methodBase)
5548
{
49+
// Invoke the method and get return value.
50+
var returnValue = methodBase.Invoke(obj, parameters);
51+
52+
// TODO: Add option to disable this because can cause bugs and can be broken easily
53+
var trace = new StackTrace();
54+
var frame = trace.GetFrame(5); // <--
55+
var method = frame.GetMethod();
56+
57+
if (method.IsConstructor)
58+
ConsoleLogger.Warn($"VMP Method (Constructor) {method.FullDescription()}");
59+
60+
ConsoleLogger.Warn($"VMP Method: {method.FullDescription()}");
61+
5662
ConsoleLogger.Warn("MethodName: {0}", methodBase.Name);
5763
ConsoleLogger.Warn("FullDescription: {0}", methodBase.FullDescription());
5864
ConsoleLogger.Warn("MethodType: {0}", methodBase.GetType());
@@ -70,6 +76,8 @@ namespace VMUnprotect
7076

7177
if (returnValue != null)
7278
ConsoleLogger.Warn("Return type: {0}\n", returnValue.GetType());
79+
80+
return returnValue;
7381
}
7482
}
7583
}
@@ -86,7 +94,8 @@ As VMProtect describes it on their's website. Code virtualization is the next st
8694
### Can it devirtualize VMP?
8795
No, isn't even meant for devirtualization.
8896

89-
## Credits
97+
# Credits
9098
This tool uses the following (open source) software:
9199
* [dnlib](https://github.com/0xd4d/dnlib) by [0xd4d](https://github.com/0xd4d), licensed under the MIT license, for reading/writing assemblies.
92-
* [Harmony](https://github.com/pardeike/Harmony) by [Andreas Pardeike](https://github.com/pardeike), licensed under the MIT license, for patching the stacktrace which allows for reflection invocation to be used.
100+
* [Harmony](https://github.com/pardeike/Harmony) by [Andreas Pardeike](https://github.com/pardeike), licensed under the MIT license, for patching the stacktrace which allows for reflection invocation to be used.
101+
* [Serilog](https://github.com/serilog/serilog) provides diagnostic logging to files, the console, and elsewhere. It is easy to set up, has a clean API.

VMUP/VMUnprotect/Hooks/Methods/VMProtectDumper.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,9 @@ public object HookedInvoke(object obj, BindingFlags bindingFlags, Binder binder,
6262
// Indicate this method was called by newer version of VMP.
6363
ConsoleLogger.Warn("============================================= HookedInvoke =============================================\n");
6464

65-
// Invoke the method and get return value.
66-
var returnValue = methodBase.Invoke(obj, bindingFlags, binder, parameters, culture);
67-
6865
// Route the arguments and return value to our middleman function where they can be manipulated or logged.
69-
MiddleMan.VmpMethodLogger(obj, bindingFlags, binder, ref parameters, culture, methodBase, ref returnValue);
70-
71-
// Return logged return value.
72-
return returnValue;
66+
return MiddleMan.VmpMethodLogger(obj, null, null, ref parameters, null, methodBase);
67+
;
7368
}
7469
catch (Exception ex)
7570
{
@@ -109,14 +104,9 @@ public object HookedInvokeOld(object obj, object[] parameters, MethodBase method
109104
// Indicate this method was called by older version of VMP.
110105
ConsoleLogger.Warn("============================================= HookedInvokeOld =============================================\n");
111106

112-
// Invoke the method and get return value.
113-
var returnValue = methodBase.Invoke(obj, parameters);
114-
115107
// Route the arguments and return value to our middleman function where they can be manipulated or logged.
116-
MiddleMan.VmpMethodLogger(obj, null, null, ref parameters, null, methodBase, ref returnValue);
117-
118-
// Return logged return value.
119-
return returnValue;
108+
return MiddleMan.VmpMethodLogger(obj, null, null, ref parameters, null, methodBase);
109+
;
120110
}
121111
catch (Exception ex)
122112
{

VMUP/VMUnprotect/MiddleMan.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using HarmonyLib;
2+
using System.Diagnostics;
23
using System.Globalization;
34
using System.Reflection;
45
using VMUnprotect.Utils;
@@ -13,15 +14,21 @@ internal static class MiddleMan
1314
/// <summary>
1415
/// This function manipulate can manipulate, log actual invokes from virtualized VMP functions.
1516
/// </summary>
16-
public static void VmpMethodLogger(
17-
object obj,
18-
BindingFlags? bindingFlags,
19-
Binder binder,
20-
ref object[] parameters,
21-
CultureInfo culture,
22-
MethodBase methodBase,
23-
ref object returnValue)
17+
public static object VmpMethodLogger(object obj, BindingFlags? bindingFlags, Binder binder, ref object[] parameters, CultureInfo culture, MethodBase methodBase)
2418
{
19+
// Invoke the method and get return value.
20+
var returnValue = methodBase.Invoke(obj, parameters);
21+
22+
// TODO: Add option to disable this because can cause bugs and can be broken easily
23+
var trace = new StackTrace();
24+
var frame = trace.GetFrame(5); // <--
25+
var method = frame.GetMethod();
26+
27+
if (method.IsConstructor)
28+
ConsoleLogger.Warn($"VMP Method (Constructor) {method.FullDescription()}");
29+
30+
ConsoleLogger.Warn($"VMP Method: {method.FullDescription()}");
31+
2532
ConsoleLogger.Warn("MethodName: {0}", methodBase.Name);
2633
ConsoleLogger.Warn("FullDescription: {0}", methodBase.FullDescription());
2734
ConsoleLogger.Warn("MethodType: {0}", methodBase.GetType());
@@ -39,6 +46,8 @@ public static void VmpMethodLogger(
3946

4047
if (returnValue != null)
4148
ConsoleLogger.Warn("Return type: {0}\n", returnValue.GetType());
49+
50+
return returnValue;
4251
}
4352
}
4453
}

VMUP/media/gif.gif

222 KB
Loading

0 commit comments

Comments
 (0)