@@ -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 ( "\n Executing 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" ) ]
0 commit comments