-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotect.c
More file actions
70 lines (58 loc) · 2.18 KB
/
protect.c
File metadata and controls
70 lines (58 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <windows.h>
#include <stdio.h>
// We define the constants needed for IOCTL ourselves
#ifndef FILE_DEVICE_UNKNOWN
#define FILE_DEVICE_UNKNOWN 0x00000022
#endif
#ifndef METHOD_BUFFERED
#define METHOD_BUFFERED 0
#endif
#ifndef FILE_ANY_ACCESS
#define FILE_ANY_ACCESS 0
#endif
// Standard CTL_CODE macro (copied from winioctl.h)
#define CTL_CODE(DeviceType, Function, Method, Access) \
(((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method))
// Our IOCTL – must match the one in the driver
#define IOCTL_HIDE_WINDOW CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS)
// Structure sent to the driver – same as in the driver
typedef struct _HIDE_WINDOW_DATA {
ULONG64 WindowHandle;
ULONG Flags;
} HIDE_WINDOW_DATA;
int main() {
// Open the driver (the symbolic link created by the driver)
HANDLE hDevice = CreateFileA("\\\\.\\HideWindow",
GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING, 0, NULL);
if (hDevice == INVALID_HANDLE_VALUE) {
printf("Failed to open driver. Error: %d\n", GetLastError());
return 1;
}
// Get the handle of the current console window
HWND hWnd = GetConsoleWindow();
if (hWnd == NULL) {
printf("Failed to get console window.\n");
CloseHandle(hDevice);
return 1;
}
printf("Console HWND: %p\n", hWnd);
// Prepare the data structure – HWND is pointer sized, cast safely to 64‑bit
HIDE_WINDOW_DATA data;
data.WindowHandle = (ULONG64)(ULONG_PTR)hWnd;
data.Flags = 0;
DWORD bytesReturned;
// Send the IOCTL to the driver
if (DeviceIoControl(hDevice, IOCTL_HIDE_WINDOW,
&data, sizeof(data),
NULL, 0, &bytesReturned, NULL)) {
printf("Window hiding activated successfully!\n");
printf("This window is now invisible to any screen capture tool.\n");
} else {
printf("Failed to send IOCTL. Error: %d\n", GetLastError());
}
CloseHandle(hDevice);
printf("\nPress Enter to exit...\n");
getchar();
return 0;
}