Data leakage prevention | ban PrintScreen key

       In the data leak prevention software, generally prohibit the PrintScreen key, to prevent the picture is saved as a result of data through screenshots leak.

       If you want to implement such software is relatively simple, but powerful want to do some function, or the need to work hard. Previously used a data leakage prevention software, which have this feature, it can not only prohibits off PrintScreen key, but also prohibit other professional screenshot software. Similarly, the method is prohibited screenshots difficulty lies in the software compatibility is not to affect the normal operation of the software.

Here are some of the how to disable the PrintScreen key. Actually very simple, just install low-level keyboard hook (WH_KEYBOARD_LL) can handle, ordinary keyboard hook (WH_KEYBOARD) is unable to filter some of the system keys. In the lower keyboard hook callback function, it is determined whether the PrintScreen key, if it is directly returns TRUE, the next, if not the chain hook to pass.

 

      Look at the code it! ! !

 

 1 extern "C" __declspec(dllexport) BOOL SetHookOn()
 2 {
 3     if ( g_hHook != NULL )
 4     {
 5         return FALSE;
 6     }
 7     g_hHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, g_hIns, NULL);
 8     if ( NULL == g_hHook )
 9     {
10         MessageBox(NULL, "安装钩子出错 !", "error", MB_ICONSTOP);
11         return FALSE;
12     }
13 
14     return TRUE;
15 }
16 
17 extern "C" __declspec(dllexport) BOOL SetHookOff()
18 {    
19     if ( g_hHook == NULL )
20     {
21         return FALSE;
22     }
23     UnhookWindowsHookEx(g_hHook);
24     g_hHook = NULL;
25     return TRUE;
26 }
27 
28 LRESULT CALLBACK LowLevelKeyboardProc(
29             int nCode, WPARAM wParam, LPARAM lParam)
30 {
31     KBDLLHOOKSTRUCT *Key_Info = (KBDLLHOOKSTRUCT*)lParam;
32 
33     if ( HC_ACTION == nCode )
34     {
35         if ( WM_KEYDOWN == wParam || WM_SYSKEYDOWN == wParam )
36         {
37             if ( Key_Info->vkCode == VK_SNAPSHOT )
38             {
39                 return TRUE;
40             }
41         }
42     }
43 
44     return CallNextHookEx(g_hHook, nCode, wParam, lParam);
45 }

 

       The amount of code is very short, yes ...... is this short code prevents data leakage. Of course, such a protection for an attacker, the code will not be able to protect the data. For an attacker, this protection is also very fragile. Any protection has breakthrough approach to attack everywhere, the attacker tries to break through any means of protection for all.

 


 

Welcome to the concern micro-channel public number: "Code farming UP2U"

Guess you like

Origin www.cnblogs.com/tosser/p/11594916.html