2 * PROJECT: Global Flags utility
3 * LICENSE: GPL-2.0 (https://spdx.org/licenses/GPL-2.0)
4 * PURPOSE: Global Flags utility entrypoint
5 * COPYRIGHT: Copyright 2017 Pierre Schweitzer (pierre@reactos.org)
6 * Copyright 2018 Mark Jansen (mark.jansen@reactos.org)
11 static BOOL UsePageHeap
= FALSE
;
13 const WCHAR ImageExecOptionsString
[] = L
"Software\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options";
15 BOOL
OpenImageFileExecOptions(IN REGSAM SamDesired
, IN OPTIONAL PCWSTR ImageName
, OUT HKEY
* Key
)
18 HKEY HandleKey
, HandleSubKey
;
20 Ret
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, ImageExecOptionsString
, 0, KEY_WRITE
| KEY_READ
, &HandleKey
);
21 if (Ret
!= ERROR_SUCCESS
)
23 wprintf(L
"OpenIFEO: RegOpenKeyEx failed (%d)\n", Ret
);
27 if (ImageName
== NULL
)
33 Ret
= RegCreateKeyExW(HandleKey
, ImageName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
| KEY_READ
, NULL
, &HandleSubKey
, NULL
);
34 CloseHandle(HandleKey
);
36 if (Ret
!= ERROR_SUCCESS
)
38 wprintf(L
"OpenIFEO: RegCreateKeyEx failed (%d)\n", Ret
);
46 DWORD
ReadSZFlagsFromRegistry(HKEY SubKey
, PWSTR Value
)
48 WCHAR Buffer
[20] = { 0 };
49 DWORD Len
, Flags
, Type
;
51 Len
= sizeof(Buffer
) - sizeof(WCHAR
);
53 if (RegQueryValueExW(SubKey
, Value
, NULL
, &Type
, (BYTE
*)Buffer
, &Len
) == ERROR_SUCCESS
&& Type
== REG_SZ
)
55 Flags
= wcstoul(Buffer
, NULL
, 16);
61 static BOOL
ParseCmdline(int argc
, LPWSTR argv
[])
67 wprintf(L
"Not enough args!\n");
71 for (i
= 1; i
< argc
; i
++)
73 if (argv
[i
][0] == L
'/')
75 if (argv
[i
][1] == L
'p' && argv
[i
][2] == UNICODE_NULL
)
78 return PageHeap_ParseCmdline(i
+ 1, argc
, argv
);
83 wprintf(L
"Invalid option: %s\n", argv
[i
]);
90 wprintf(L
"Only page heap flags are supported\n");
98 int wmain(int argc
, LPWSTR argv
[])
100 if (!ParseCmdline(argc
, argv
))
102 wprintf(L
"Usage: gflags /p [image.exe] [/enable|/disable [/full]]\n"
103 L
" image.exe: Image you want to deal with\n"
104 L
" /enable: enable page heap for the image\n"
105 L
" /disable: disable page heap for the image\n"
106 L
" /full: activate full debug page heap\n");
112 return PageHeap_Execute();