ReactOS 0.4.16-dev-257-g6aa11ac
imagefile.c
Go to the documentation of this file.
1/*
2 * PROJECT: Global Flags utility
3 * LICENSE: GPL-2.0 (https://spdx.org/licenses/GPL-2.0)
4 * PURPOSE: Global Flags utility image file options
5 * COPYRIGHT: Copyright 2018 Mark Jansen (mark.jansen@reactos.org)
6 */
7
8#include "gflags.h"
9
11static DWORD OptionsAdd = 0;
14
15typedef struct FlagInfo
16{
18 const wchar_t* szAbbr;
20 const wchar_t* szDesc;
22
23#define FLG_DISABLE_DBGPRINT 0x8000000
24#define FLG_CRITSEC_EVENT_CREATION 0x10000000
25#define FLG_STOP_ON_UNHANDLED_EXCEPTION 0x20000000
26#define FLG_ENABLE_HANDLE_EXCEPTIONS 0x40000000
27#define FLG_DISABLE_PROTDLLS 0x80000000
28
29
30static const FlagInfo g_Flags[] =
31{
32 {FLG_STOP_ON_EXCEPTION, L"soe", (DEST_REGISTRY | DEST_KERNEL | DEST_IMAGE), L"Stop on exception"},
33 {FLG_SHOW_LDR_SNAPS, L"sls", (DEST_REGISTRY | DEST_KERNEL | DEST_IMAGE), L"Show loader snaps"},
34 {FLG_DEBUG_INITIAL_COMMAND, L"dic", (DEST_REGISTRY), L"Debug initial command"},
35 {FLG_STOP_ON_HUNG_GUI, L"shg", (DEST_KERNEL), L"Stop on hung GUI"},
36 {FLG_HEAP_ENABLE_TAIL_CHECK, L"htc", (DEST_REGISTRY | DEST_KERNEL | DEST_IMAGE), L"Enable heap tail checking"},
37 {FLG_HEAP_ENABLE_FREE_CHECK, L"hfc", (DEST_REGISTRY | DEST_KERNEL | DEST_IMAGE), L"Enable heap free checking"},
38 {FLG_HEAP_VALIDATE_PARAMETERS, L"hpc", (DEST_REGISTRY | DEST_KERNEL | DEST_IMAGE), L"Enable heap parameter checking"},
39 {FLG_HEAP_VALIDATE_ALL, L"hvc", (DEST_REGISTRY | DEST_KERNEL | DEST_IMAGE), L"Enable heap validation on call"},
40 {FLG_APPLICATION_VERIFIER, L"vrf", (DEST_REGISTRY | DEST_KERNEL | DEST_IMAGE), L"Enable application verifier"},
41 // FLG_MONITOR_SILENT_PROCESS_EXIT
42 {FLG_POOL_ENABLE_TAGGING, L"ptg", (DEST_REGISTRY), L"Enable pool tagging"},
43 {FLG_HEAP_ENABLE_TAGGING, L"htg", (DEST_REGISTRY | DEST_KERNEL | DEST_IMAGE), L"Enable heap tagging"},
44 {FLG_USER_STACK_TRACE_DB, L"ust", (DEST_REGISTRY | DEST_KERNEL | DEST_IMAGE), L"Create user mode stack trace database"},
45 {FLG_KERNEL_STACK_TRACE_DB, L"kst", (DEST_REGISTRY), L"Create kernel mode stack trace database"},
46 {FLG_MAINTAIN_OBJECT_TYPELIST, L"otl", (DEST_REGISTRY), L"Maintain a list of objects for each type"},
47 {FLG_HEAP_ENABLE_TAG_BY_DLL, L"htd", (DEST_REGISTRY | DEST_KERNEL | DEST_IMAGE), L"Enable heap tagging by DLL"},
48 {FLG_DISABLE_STACK_EXTENSION, L"dse", (DEST_IMAGE), L"Disable stack extension"},
49
50 {FLG_ENABLE_CSRDEBUG, L"d32", (DEST_REGISTRY), L"Enable debugging of Win32 subsystem"},
51 {FLG_ENABLE_KDEBUG_SYMBOL_LOAD, L"ksl", (DEST_REGISTRY | DEST_KERNEL), L"Enable loading of kernel debugger symbols"},
52 {FLG_DISABLE_PAGE_KERNEL_STACKS, L"dps", (DEST_REGISTRY), L"Disable paging of kernel stacks"},
53 {FLG_ENABLE_SYSTEM_CRIT_BREAKS, L"scb", (DEST_REGISTRY | DEST_KERNEL | DEST_IMAGE), L"Enable system critical breaks"},
54 {FLG_HEAP_DISABLE_COALESCING, L"dhc", (DEST_REGISTRY | DEST_KERNEL | DEST_IMAGE), L"Disable heap coalesce on free"},
55 {FLG_ENABLE_CLOSE_EXCEPTIONS, L"ece", (DEST_REGISTRY | DEST_KERNEL), L"Enable close exception"},
56 {FLG_ENABLE_EXCEPTION_LOGGING, L"eel", (DEST_REGISTRY | DEST_KERNEL), L"Enable exception logging"},
57 {FLG_ENABLE_HANDLE_TYPE_TAGGING, L"eot", (DEST_REGISTRY | DEST_KERNEL), L"Enable object handle type tagging"},
58 {FLG_HEAP_PAGE_ALLOCS, L"hpa", (DEST_REGISTRY | DEST_KERNEL | DEST_IMAGE), L"Enable page heap"},
59 {FLG_DEBUG_INITIAL_COMMAND_EX, L"dwl", (DEST_REGISTRY), L"Debug WinLogon"},
60 {FLG_DISABLE_DBGPRINT, L"ddp", (DEST_REGISTRY | DEST_KERNEL), L"Buffer DbgPrint Output"},
61 {FLG_CRITSEC_EVENT_CREATION, L"cse", (DEST_REGISTRY | DEST_KERNEL | DEST_IMAGE), L"Early critical section event creation"},
62 {FLG_STOP_ON_UNHANDLED_EXCEPTION, L"sue", (DEST_REGISTRY | DEST_KERNEL | DEST_IMAGE), L"Stop on unhandled user-mode exception"},
63 {FLG_ENABLE_HANDLE_EXCEPTIONS, L"bhd", (DEST_REGISTRY | DEST_KERNEL), L"Enable bad handles detection"},
64 {FLG_DISABLE_PROTDLLS, L"dpd", (DEST_REGISTRY | DEST_KERNEL | DEST_IMAGE), L"Disable protected DLL verification"},
65};
66
68{
69 DWORD n;
70
71 for (n = 0; n < ARRAYSIZE(g_Flags); ++n)
72 {
73 if (!Dest || (g_Flags[n].wDest & Dest))
74 {
75 if (g_Flags[n].dwFlag & GlobalFlags)
76 {
77 wprintf(L" %s - %s\n", g_Flags[n].szAbbr, g_Flags[n].szDesc);
78 }
79 }
80 }
81}
82
83static void ShowStatus(DWORD GlobalFlags, DWORD Ignored)
84{
85 if (GlobalFlags)
86 {
87 wprintf(L"Current Registry Settings for %s executable are: %08x\n", ImageFile, GlobalFlags);
89 }
90 else
91 {
92 wprintf(L"No Registry Settings for %s executable\n", ImageFile);
93 }
94 if (Ignored)
95 {
96 wprintf(L"The following settings were ignored: %08x\n", Ignored);
97 PrintFlags(Ignored, 0);
98 }
99}
100
102{
103 DWORD n;
104 DWORD Valid = 0;
105
106 for (n = 0; n < ARRAYSIZE(g_Flags); ++n)
107 {
108 if (g_Flags[n].wDest & Dest)
109 {
110 Valid |= g_Flags[n].dwFlag;
111 }
112 }
113
114 return GlobalFlags & Valid;
115}
116
118{
119 DWORD n;
120
121 for (n = 0; n < ARRAYSIZE(g_Flags); ++n)
122 {
123 if (g_Flags[n].wDest & Dest)
124 {
125 if (!_wcsicmp(Name, g_Flags[n].szAbbr))
126 {
127 return g_Flags[n].dwFlag;
128 }
129 }
130 }
131
132 return 0;
133}
134
136{
137 LONG Ret;
138 DWORD GlobalFlags, Requested, Ignored;
139 HKEY IFEOKey;
140 WCHAR Buffer[11];
141
143 {
144 return;
145 }
146
147 if (OptionsSet)
148 {
149 Requested = OptionsAdd;
150 }
151 else
152 {
153 Requested = ReadSZFlagsFromRegistry(IFEOKey, L"GlobalFlag");
154 Requested &= ~OptionsRemove;
155 Requested |= OptionsAdd;
156 }
157
159 Ignored = GlobalFlags ^ Requested;
160
161 if (GlobalFlags)
162 {
163 wsprintf(Buffer, L"0x%08x", GlobalFlags);
164 Ret = RegSetValueExW(IFEOKey, L"GlobalFlag", 0, REG_SZ, (BYTE*)Buffer, (wcslen(Buffer) + 1) * sizeof(WCHAR));
165 if (Ret != ERROR_SUCCESS)
166 {
167 wprintf(L"MS: RegSetValueEx failed (%d)\n", Ret);
168 }
169 else
170 {
171 ShowStatus(GlobalFlags, Ignored);
172 }
173 }
174 else
175 {
176 Ret = RegDeleteValueW(IFEOKey, L"GlobalFlag");
177 if (Ret != ERROR_SUCCESS)
178 {
179 wprintf(L"MS: RegDeleteValue failed (%d)\n", Ret);
180 }
181 else
182 {
183 ShowStatus(GlobalFlags, Ignored);
184 }
185 }
186 CloseHandle(IFEOKey);
187}
188
189
191{
192 HKEY IFEOKey;
194
196 {
197 return;
198 }
199
200 GlobalFlags = ReadSZFlagsFromRegistry(IFEOKey, L"GlobalFlag");
202
203 CloseHandle(IFEOKey);
204}
205
206
208{
209 for (; i < argc; i++)
210 {
211 if (ImageFile == NULL)
212 {
213 ImageFile = argv[i];
214 }
215 else if (argv[i][0] == '+')
216 {
217 if (OptionsSet)
218 {
219 wprintf(L"Unexpected argument - '%s'\n", argv[i]);
220 return FALSE;
221 }
223 }
224 else if (argv[i][0] == '-')
225 {
226 if (OptionsSet)
227 {
228 wprintf(L"Unexpected argument - '%s'\n", argv[i]);
229 return FALSE;
230 }
232 }
233 else
234 {
236 OptionsAdd = wcstoul(argv[i], NULL, 16);
237 if (OptionsAdd == ~0)
238 OptionsAdd = 0;
239 }
240 }
241
242 if (ImageFile == NULL)
243 {
244 wprintf(L"No Image specified\n");
245 return FALSE;
246 }
247
248 return TRUE;
249}
250
252{
254 {
256 }
257 else
258 {
259 ModifyStatus();
260 }
261
262 return 0;
263}
static int argc
Definition: ServiceArgs.c:12
Definition: bufpool.h:45
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
Definition: reg.c:2330
#define CloseHandle
Definition: compat.h:739
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
BOOL OpenImageFileExecOptions(IN REGSAM SamDesired, IN OPTIONAL PCWSTR ImageName, OUT HKEY *Key)
Definition: gflags.c:16
DWORD ReadSZFlagsFromRegistry(HKEY SubKey, PWSTR Value)
Definition: gflags.c:47
#define DEST_KERNEL
Definition: gflags.h:34
#define DEST_REGISTRY
Definition: gflags.h:33
#define DEST_IMAGE
Definition: gflags.h:35
GLdouble n
Definition: glext.h:7729
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
UINT NTAPI GlobalFlags(HGLOBAL hMem)
Definition: heapmem.c:520
static DWORD ValidateFlags(DWORD GlobalFlags, WORD Dest)
Definition: imagefile.c:101
BOOL ImageFile_ParseCmdline(INT i, int argc, LPWSTR argv[])
Definition: imagefile.c:207
static BOOL OptionsSet
Definition: imagefile.c:13
static void ShowStatus(DWORD GlobalFlags, DWORD Ignored)
Definition: imagefile.c:83
static VOID DisplayStatus(VOID)
Definition: imagefile.c:190
INT ImageFile_Execute()
Definition: imagefile.c:251
static DWORD FindFlag(PCWSTR Name, WORD Dest)
Definition: imagefile.c:117
#define FLG_ENABLE_HANDLE_EXCEPTIONS
Definition: imagefile.c:26
#define FLG_DISABLE_PROTDLLS
Definition: imagefile.c:27
#define FLG_CRITSEC_EVENT_CREATION
Definition: imagefile.c:24
static DWORD OptionsAdd
Definition: imagefile.c:11
static DWORD OptionsRemove
Definition: imagefile.c:12
#define FLG_DISABLE_DBGPRINT
Definition: imagefile.c:23
static VOID ModifyStatus(VOID)
Definition: imagefile.c:135
static const FlagInfo g_Flags[]
Definition: imagefile.c:30
static PWSTR ImageFile
Definition: imagefile.c:10
#define FLG_STOP_ON_UNHANDLED_EXCEPTION
Definition: imagefile.c:25
void PrintFlags(IN DWORD GlobalFlags, IN OPTIONAL WORD Dest)
Definition: imagefile.c:67
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define FLG_HEAP_DISABLE_COALESCING
Definition: pstypes.h:80
#define FLG_ENABLE_SYSTEM_CRIT_BREAKS
Definition: pstypes.h:78
#define FLG_HEAP_ENABLE_TAGGING
Definition: pstypes.h:66
#define FLG_KERNEL_STACK_TRACE_DB
Definition: pstypes.h:68
#define FLG_USER_STACK_TRACE_DB
Definition: pstypes.h:67
#define FLG_DISABLE_STACK_EXTENSION
Definition: pstypes.h:71
#define FLG_DEBUG_INITIAL_COMMAND
Definition: pstypes.h:58
#define FLG_DISABLE_PAGE_KERNEL_STACKS
Definition: pstypes.h:74
#define FLG_STOP_ON_EXCEPTION
Definition: pstypes.h:56
#define FLG_ENABLE_EXCEPTION_LOGGING
Definition: pstypes.h:82
#define FLG_ENABLE_CLOSE_EXCEPTIONS
Definition: pstypes.h:81
#define FLG_ENABLE_CSRDEBUG
Definition: pstypes.h:72
#define FLG_SHOW_LDR_SNAPS
Definition: pstypes.h:57
#define FLG_ENABLE_HANDLE_TYPE_TAGGING
Definition: pstypes.h:83
#define FLG_DEBUG_INITIAL_COMMAND_EX
Definition: pstypes.h:85
#define FLG_HEAP_PAGE_ALLOCS
Definition: pstypes.h:84
#define FLG_POOL_ENABLE_TAGGING
Definition: pstypes.h:65
#define FLG_HEAP_ENABLE_FREE_CHECK
Definition: pstypes.h:61
#define FLG_MAINTAIN_OBJECT_TYPELIST
Definition: pstypes.h:69
#define FLG_HEAP_VALIDATE_PARAMETERS
Definition: pstypes.h:62
#define FLG_STOP_ON_HUNG_GUI
Definition: pstypes.h:59
#define FLG_APPLICATION_VERIFIER
Definition: pstypes.h:64
#define FLG_HEAP_ENABLE_TAIL_CHECK
Definition: pstypes.h:60
#define FLG_HEAP_VALIDATE_ALL
Definition: pstypes.h:63
#define FLG_ENABLE_KDEBUG_SYMBOL_LOAD
Definition: pstypes.h:73
#define FLG_HEAP_ENABLE_TAG_BY_DLL
Definition: pstypes.h:70
#define REG_SZ
Definition: layer.c:22
#define argv
Definition: mplay32.c:18
#define KEY_READ
Definition: nt_native.h:1023
#define KEY_WRITE
Definition: nt_native.h:1031
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
DWORD dwFlag
Definition: imagefile.c:17
WORD wDest
Definition: imagefile.c:19
const wchar_t * szAbbr
Definition: imagefile.c:18
const wchar_t * szDesc
Definition: imagefile.c:20
uint16_t * PWSTR
Definition: typedefs.h:56
const uint16_t * PCWSTR
Definition: typedefs.h:57
int32_t INT
Definition: typedefs.h:58
#define IN
Definition: typedefs.h:39
#define wprintf(...)
Definition: whoami.c:18
#define wsprintf
Definition: winuser.h:5877
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
unsigned char BYTE
Definition: xxhash.c:193