Skip to content

Commit 7831372

Browse files
authored
Merge pull request #2 from mastercodeon314/master
PR for the third dnSpy debugging hook, System.Diagnostics.Debugger
2 parents abee777 + 1184569 commit 7831372

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
A fork of the original repo that adds the third dnSpy debugging hook, System.Diagnostics.Debugger
2+
13
# dnSpyDetector
24
A quick way to check for the presence of dnSpy hooks in memory
35

4-
![](https://i.imgur.com/UE7fleD.png)
6+
7+
![image](https://user-images.githubusercontent.com/78676320/193439132-b5ddeb8c-6e88-40b7-8c16-26f540843b70.png)
58

69
# Reverse Engineering Discord server
710
Wanna join a cool reverse engineering server ? https://discord.gg/qcfddcE
Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
using System;
2+
using System.Diagnostics;
3+
24
namespace dnSpyDetector
35
{
46
class Program
57
{
6-
78
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
89
public static extern IntPtr LoadLibrary(string dllToLoad);
910

1011
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
1112
public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
1213

13-
static void Main(string[] args) {
14-
14+
static void Main(string[] args)
15+
{
16+
int hookCount = 0;
1517
Console.WriteLine("Checking the presence of dnSpy hooks ...");
1618

1719
IntPtr kernel32 = LoadLibrary("kernel32.dll");
@@ -21,25 +23,41 @@ static void Main(string[] args) {
2123
System.Runtime.InteropServices.Marshal.Copy(GetProcessId, data, 0, 1);
2224

2325
//32-bit relative jump = opcode 0xE9
24-
if (data[0] == 0xE9) {
26+
if (data[0] == 0xE9)
27+
{
2528
Console.WriteLine($"IsDebuggerPresent hook detected ...");
26-
Console.ReadKey();
27-
return;
29+
hookCount++;
2830
}
2931

3032
GetProcessId = GetProcAddress(kernel32, "CheckRemoteDebuggerPresent");
31-
data = new byte[1];
3233
System.Runtime.InteropServices.Marshal.Copy(GetProcessId, data, 0, 1);
3334

3435
//32-bit relative jump = opcode 0xE9
35-
if (data[0] == 0xE9) {
36+
if (data[0] == 0xE9)
37+
{
3638
Console.WriteLine($"CheckRemoteDebuggerPresent hook detected ...");
37-
Console.ReadKey();
38-
return;
39+
hookCount++;
3940
}
4041

42+
var debuggerType = typeof(Debugger);
43+
System.Reflection.MethodInfo[] methods = debuggerType.GetMethods();
44+
var getMethod = debuggerType.GetMethod("get_IsAttached");
45+
46+
IntPtr targetAddre = getMethod.MethodHandle.GetFunctionPointer();
47+
System.Runtime.InteropServices.Marshal.Copy(targetAddre, data, 0, 1);
4148

42-
Console.ReadKey();
49+
if (data[0] == 0x33)
50+
{
51+
Console.WriteLine($"System.Diagnostics.Debugger hook detected ...");
52+
hookCount++;
53+
}
54+
55+
if (hookCount == 0)
56+
{
57+
Console.WriteLine("No dnSpy hooks found!");
58+
}
59+
60+
Console.ReadLine();
4361
}
4462
}
4563
}

0 commit comments

Comments
 (0)