Skip to content
This repository was archived by the owner on Mar 17, 2023. It is now read-only.

Commit d333b77

Browse files
committed
Examples Update
1 parent b4ea3dd commit d333b77

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

src/Examples/Program.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,47 @@ internal class Program
1010

1111
private static void Main()
1212
{
13+
Console.WriteLine($"HookDetector.NET Version: {HookDetector.Version}\n");
1314
Console.WriteLine("Executing Example1");
14-
Console.ForegroundColor = ConsoleColor.Yellow;
1515
Example1();
16-
Console.ResetColor();
16+
1717
Console.WriteLine("\nExecuting Example2");
18-
Console.ForegroundColor = ConsoleColor.Yellow;
1918
Example2();
19+
2020
Console.ResetColor();
2121
Console.ReadKey();
2222
}
2323

2424
private static void Example1()
2525
{
26+
Console.ForegroundColor = ConsoleColor.Yellow;
2627
Console.WriteLine($"IsDebuggerPresent (not hooked) = {IsDebuggerPresent()}");
2728
var hookDetector = new HookDetector("kernel32.dll");
2829
var isHooked = hookDetector.IsHooked("IsDebuggerPresent");
29-
Console.WriteLine($"is Kernel32.IsDebuggerPresent hooked? {isHooked}");
30+
Console.WriteLine($"is Kernel32.IsDebuggerPresent hooked = {isHooked}");
31+
Console.ResetColor();
3032
}
3133

3234
private static void Example2()
3335
{
34-
byte[] hook = {0xB8, 0x00, 0x00, 0x00, 0x00, 0xC3};
36+
byte[] hook =
37+
{
38+
0xB8, 0x00, 0x00, 0x00, 0x00, // mov eax, 0(false)
39+
0xC3 // ret
40+
};
3541
var addr = GetProcAddress(LoadLibrary("kernel32.dll"), "IsDebuggerPresent");
36-
37-
VirtualProtectEx(Process.GetCurrentProcess().Handle, addr, (UIntPtr) 1, 0x40, out var oldp);
42+
Console.ForegroundColor = ConsoleColor.Yellow;
43+
Console.WriteLine("Hooking IsDebuggerPresent...");
44+
VirtualProtectEx(Process.GetCurrentProcess().Handle, addr, (UIntPtr)1, 0x40, out var oldp);
3845
WriteProcessMemory(Process.GetCurrentProcess().Handle, addr, hook, 6, out _);
39-
VirtualProtectEx(Process.GetCurrentProcess().Handle, addr, (UIntPtr) 1, oldp, out _);
46+
VirtualProtectEx(Process.GetCurrentProcess().Handle, addr, (UIntPtr)1, oldp, out _);
4047

4148
Console.WriteLine($"IsDebuggerPresent (Hooked to be always false) = {IsDebuggerPresent()}");
4249

4350
var hookDetector = new HookDetector("kernel32.dll");
4451
var isHooked = hookDetector.IsHooked("IsDebuggerPresent");
45-
Console.WriteLine($"is Kernel32.IsDebuggerPresent hooked? {isHooked}");
52+
Console.WriteLine($"is Kernel32.IsDebuggerPresent hooked = {isHooked}");
53+
Console.ResetColor();
4654
}
4755

4856
[DllImport("kernel32.dll")]

src/HookDetector.NET/HookDetector.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace Hook_Detector
66
{
77
public class HookDetector
88
{
9+
public static readonly string Version = "1.0";
10+
911
public HookDetector(string moduleName, bool is32Bits = true)
1012
{
1113
this.ModuleName = moduleName;

src/HookDetector.NET/HookDetector.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</PropertyGroup>
2727
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2828
<PlatformTarget>AnyCPU</PlatformTarget>
29-
<DebugType>pdbonly</DebugType>
29+
<DebugType>none</DebugType>
3030
<Optimize>true</Optimize>
3131
<OutputPath>bin\Release\</OutputPath>
3232
<DefineConstants>TRACE</DefineConstants>

0 commit comments

Comments
 (0)