ReactOS 0.4.15-dev-8058-ga7cbb60
gflags.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 entrypoint
5 * COPYRIGHT: Copyright 2017 Pierre Schweitzer (pierre@reactos.org)
6 * Copyright 2018 Mark Jansen (mark.jansen@reactos.org)
7 */
8
9#include "gflags.h"
10
13
14const WCHAR ImageExecOptionsString[] = L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options";
15
17{
18 LONG Ret;
19 HKEY HandleKey, HandleSubKey;
20
21 Ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE, ImageExecOptionsString, 0, SamDesired, &HandleKey);
22 if (Ret != ERROR_SUCCESS)
23 {
24 wprintf(L"OpenIFEO: RegOpenKeyEx failed (%d)\n", Ret);
25 return FALSE;
26 }
27
28 if (ImageName == NULL)
29 {
30 *Key = HandleKey;
31 return TRUE;
32 }
33
34 Ret = RegCreateKeyExW(HandleKey, ImageName, 0, NULL, REG_OPTION_NON_VOLATILE, SamDesired, NULL, &HandleSubKey, NULL);
35 CloseHandle(HandleKey);
36
37 if (Ret != ERROR_SUCCESS)
38 {
39 wprintf(L"OpenIFEO: RegCreateKeyEx failed (%d)\n", Ret);
40 return FALSE;
41 }
42 *Key = HandleSubKey;
43 return TRUE;
44}
45
46
48{
49 WCHAR Buffer[20] = { 0 };
51
52 Len = sizeof(Buffer) - sizeof(WCHAR);
53 Flags = 0;
54 if (RegQueryValueExW(SubKey, Value, NULL, &Type, (BYTE*)Buffer, &Len) == ERROR_SUCCESS && Type == REG_SZ)
55 {
56 Flags = wcstoul(Buffer, NULL, 16);
57 }
58
59 return Flags;
60}
61
63{
64 INT i;
65
66 if (argc < 2)
67 {
68 wprintf(L"Not enough args!\n");
69 return FALSE;
70 }
71
72 for (i = 1; i < argc; i++)
73 {
74 if (argv[i][0] == L'/')
75 {
76 if (argv[i][1] == L'p' && argv[i][2] == UNICODE_NULL)
77 {
79 return PageHeap_ParseCmdline(i + 1, argc, argv);
80 }
81 if (argv[i][1] == L'i' && argv[i][2] == UNICODE_NULL)
82 {
84 return ImageFile_ParseCmdline(i + 1, argc, argv);
85 }
86 }
87 else
88 {
89 wprintf(L"Invalid option: %s\n", argv[i]);
90 return FALSE;
91 }
92 }
93
95 {
96 wprintf(L"Only page heap / image file flags are supported\n");
97 return FALSE;
98 }
99
100 return TRUE;
101}
102
103
105{
106 if (!ParseCmdline(argc, argv))
107 {
108 wprintf(L"Usage: gflags [/p [image.exe] [/enable|/disable [/full]]]\n"
109 L" [/i <image.exe> [<Flags>]]\n"
110 L" image.exe: Image you want to deal with\n"
111 L" /enable: enable page heap for the image\n"
112 L" /disable: disable page heap for the image\n"
113 L" /full: activate full debug page heap\n"
114 L" <Flags>: A 32 bit hex number (0x00000001) that specifies\n"
115 L" one or more global flags to set.\n"
116 L" Without any flags, the current settings are shown.\n"
117 L" Specify FFFFFFFF to delete the GlobalFlags entry.\n"
118 L" Additionally, instead of a single hex number,\n"
119 L" specify a list of abbreviations prefixed with\n"
120 L" a '+' to add, and '-' to remove a bit.\n"
121 L" Valid abbreviations:\n");
123 return 1;
124 }
125
126 if (UsePageHeap)
127 {
128 return PageHeap_Execute();
129 }
130 else if (UseImageFile)
131 {
132 return ImageFile_Execute();
133 }
134 return 2;
135}
static int argc
Definition: ServiceArgs.c:12
Type
Definition: Type.h:7
Definition: bufpool.h:45
#define Len
Definition: deflate.h:82
#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
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1096
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define CloseHandle
Definition: compat.h:739
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
static BOOL ParseCmdline(int argc, LPWSTR argv[])
Definition: gflags.c:62
BOOL OpenImageFileExecOptions(IN REGSAM SamDesired, IN OPTIONAL PCWSTR ImageName, OUT HKEY *Key)
Definition: gflags.c:16
static BOOL UseImageFile
Definition: gflags.c:12
static BOOL UsePageHeap
Definition: gflags.c:11
DWORD ReadSZFlagsFromRegistry(HKEY SubKey, PWSTR Value)
Definition: gflags.c:47
const WCHAR ImageExecOptionsString[]
Definition: gflags.c:14
BOOL ImageFile_ParseCmdline(INT i, int argc, LPWSTR argv[])
Definition: imagefile.c:207
BOOL PageHeap_ParseCmdline(INT i, int argc, LPWSTR argv[])
Definition: pageheap.c:244
INT ImageFile_Execute()
Definition: imagefile.c:251
INT PageHeap_Execute()
Definition: pageheap.c:295
void PrintFlags(IN DWORD GlobalFlags, IN OPTIONAL WORD Dest)
Definition: imagefile.c:67
#define DEST_IMAGE
Definition: gflags.h:35
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
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
#define REG_SZ
Definition: layer.c:22
static const char * ImageName
Definition: image.c:34
#define argv
Definition: mplay32.c:18
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define UNICODE_NULL
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
int wmain()
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
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 OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
#define wprintf(...)
Definition: whoami.c:18
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
ACCESS_MASK REGSAM
Definition: winreg.h:69
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
unsigned char BYTE
Definition: xxhash.c:193