ReactOS  0.4.12-dev-18-gf469aca
reg.h File Reference
#include "resource.h"
Include dependency graph for reg.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MAX_SUBKEY_LEN   257
 

Functions

voidheap_xalloc (size_t size)
 
voidheap_xrealloc (void *buf, size_t size)
 
void output_writeconsole (const WCHAR *str, DWORD wlen)
 
void WINAPIV output_message (unsigned int id,...)
 
BOOL ask_confirm (unsigned int msgid, WCHAR *reg_info)
 
HKEY path_get_rootkey (const WCHAR *path)
 
WCHARbuild_subkey_path (WCHAR *path, DWORD path_len, WCHAR *subkey_name, DWORD subkey_len)
 
BOOL parse_registry_key (const WCHAR *key, HKEY *root, WCHAR **path, WCHAR **long_key)
 
int reg_import (const WCHAR *filename)
 
int reg_export (int argc, WCHAR *argv[])
 

Macro Definition Documentation

◆ MAX_SUBKEY_LEN

#define MAX_SUBKEY_LEN   257

Definition at line 24 of file reg.h.

Referenced by export_registry_data(), query_all(), and query_value().

Function Documentation

◆ ask_confirm()

BOOL ask_confirm ( unsigned int  msgid,
WCHAR reg_info 
)

Definition at line 172 of file reg.c.

Referenced by get_file_handle(), reg_add(), and reg_delete().

173 {
174  HMODULE hmod;
175  WCHAR Ybuffer[4];
176  WCHAR Nbuffer[4];
177  WCHAR defval[32];
178  WCHAR answer[MAX_PATH];
179  WCHAR *str;
180  DWORD count;
181 
182  hmod = GetModuleHandleW(NULL);
183  LoadStringW(hmod, STRING_YES, Ybuffer, ARRAY_SIZE(Ybuffer));
184  LoadStringW(hmod, STRING_NO, Nbuffer, ARRAY_SIZE(Nbuffer));
185  LoadStringW(hmod, STRING_DEFAULT_VALUE, defval, ARRAY_SIZE(defval));
186 
187  str = (reg_info && *reg_info) ? reg_info : defval;
188 
189  while (1)
190  {
191  output_message(msgid, str);
193  ReadConsoleW(GetStdHandle(STD_INPUT_HANDLE), answer, ARRAY_SIZE(answer), &count, NULL);
194  answer[0] = toupperW(answer[0]);
195  if (answer[0] == Ybuffer[0])
196  return TRUE;
197  if (answer[0] == Nbuffer[0])
198  return FALSE;
199  }
200 }
#define TRUE
Definition: types.h:120
#define STRING_NO
Definition: resource.h:42
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLuint GLuint GLsizei count
Definition: gl.h:1545
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:152
void WINAPIV output_message(unsigned int id,...)
Definition: reg.c:147
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
#define STRING_YES
Definition: resource.h:41
#define STD_INPUT_HANDLE
Definition: winbase.h:264
WINE_UNICODE_INLINE WCHAR toupperW(WCHAR ch)
Definition: unicode.h:141
BOOL WINAPI DECLSPEC_HOTPATCH ReadConsoleW(IN HANDLE hConsoleInput, OUT LPVOID lpBuffer, IN DWORD nNumberOfCharsToRead, OUT LPDWORD lpNumberOfCharsRead, IN PCONSOLE_READCONSOLE_CONTROL pInputControl OPTIONAL)
Definition: readwrite.c:1176
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
static PEXPLICIT_ACCESSW *static HMODULE hmod
Definition: security.c:141
#define STRING_DEFAULT_VALUE
Definition: resource.h:44
#define ARRAY_SIZE(a)
Definition: main.h:24
#define STRING_YESNO
Definition: resource.h:40
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:845

◆ build_subkey_path()

WCHAR* build_subkey_path ( WCHAR path,
DWORD  path_len,
WCHAR subkey_name,
DWORD  subkey_len 
)

Definition at line 632 of file reg.c.

Referenced by export_registry_data(), query_all(), and query_value().

633 {
634  WCHAR *subkey_path;
635  static const WCHAR fmt[] = {'%','s','\\','%','s',0};
636 
637  subkey_path = heap_xalloc((path_len + subkey_len + 2) * sizeof(WCHAR));
638  sprintfW(subkey_path, fmt, path, subkey_name);
639 
640  return subkey_path;
641 }
__wchar_t WCHAR
Definition: xmlstorage.h:180
static DWORD path_len
Definition: batch.c:31
Definition: services.c:325
#define sprintfW
Definition: unicode.h:58
void * heap_xalloc(size_t size)
Definition: reg.c:83
Definition: dsound.c:943

◆ heap_xalloc()

void* heap_xalloc ( size_t  size)

Definition at line 83 of file reg.c.

Referenced by build_subkey_path(), dword_data_state(), escape_string(), export_dword_data(), export_hex_data(), export_hex_data_type(), export_key_name(), export_registry_data(), export_string_data(), export_value_name(), get_lineA(), get_lineW(), get_long_key(), get_regdata(), GetWideString(), GetWideStringN(), header_state(), open_key(), output_writeconsole(), query_all(), query_value(), quoted_value_name_state(), reg_data_to_wchar(), and reg_delete().

84 {
85  void *buf = heap_alloc(size);
86  if (!buf)
87  {
88  ERR("Out of memory!\n");
89  exit(1);
90  }
91  return buf;
92 }
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
GLsizeiptr size
Definition: glext.h:5919
#define ERR(fmt,...)
Definition: debug.h:109
void exit(int exitcode)
Definition: _exit.c:33

◆ heap_xrealloc()

void* heap_xrealloc ( void buf,
size_t  size 
)

Definition at line 94 of file reg.c.

Referenced by convert_hex_csv_to_hex(), export_registry_data(), get_lineA(), get_lineW(), query_all(), query_value(), and reg_delete().

95 {
96  void *new_buf = heap_realloc(buf, size);
97 
98  if (!new_buf)
99  {
100  ERR("Out of memory!\n");
101  exit(1);
102  }
103 
104  return new_buf;
105 }
static void * heap_realloc(void *mem, size_t len)
Definition: appwiz.h:70
GLsizeiptr size
Definition: glext.h:5919
#define ERR(fmt,...)
Definition: debug.h:109
void exit(int exitcode)
Definition: _exit.c:33

◆ output_message()

void WINAPIV output_message ( unsigned int  id,
  ... 
)

Definition at line 147 of file reg.c.

Referenced by ask_confirm(), get_file_handle(), get_regdata(), key_name_state(), parse_registry_key(), parse_win31_line_state(), query_value(), reg_add(), reg_delete(), reg_export(), reg_import(), reg_query(), sane_path(), unescape_string(), and wmain().

148 {
149  WCHAR fmt[1024];
150  __ms_va_list va_args;
151 
152  if (!LoadStringW(GetModuleHandleW(NULL), id, fmt, ARRAY_SIZE(fmt)))
153  {
154  WINE_FIXME("LoadString failed with %d\n", GetLastError());
155  return;
156  }
157  __ms_va_start(va_args, id);
158  output_formatstring(fmt, va_args);
159  __ms_va_end(va_args);
160 }
static const char __ms_va_list
Definition: printf.c:70
__wchar_t WCHAR
Definition: xmlstorage.h:180
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
smooth NULL
Definition: ftsmooth.c:416
static void output_formatstring(const WCHAR *fmt, __ms_va_list va_args)
Definition: reg.c:130
#define ARRAY_SIZE(a)
Definition: main.h:24
#define __ms_va_end(list)
Definition: windef.h:448
#define __ms_va_start(list, arg)
Definition: windef.h:447
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:845
Definition: dsound.c:943
#define WINE_FIXME
Definition: debug.h:370

◆ output_writeconsole()

void output_writeconsole ( const WCHAR str,
DWORD  wlen 
)

Definition at line 107 of file reg.c.

Referenced by get_file_handle(), and output_formatstring().

108 {
109  DWORD count, ret;
110 
111  ret = WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), str, wlen, &count, NULL);
112  if (!ret)
113  {
114  DWORD len;
115  char *msgA;
116 
117  /* On Windows WriteConsoleW() fails if the output is redirected. So fall
118  * back to WriteFile(), assuming the console encoding is still the right
119  * one in that case.
120  */
121  len = WideCharToMultiByte(GetConsoleOutputCP(), 0, str, wlen, NULL, 0, NULL, NULL);
122  msgA = heap_xalloc(len);
123 
124  WideCharToMultiByte(GetConsoleOutputCP(), 0, str, wlen, msgA, len, NULL, NULL);
125  WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), msgA, len, &count, FALSE);
126  heap_free(msgA);
127  }
128 }
#define WideCharToMultiByte
Definition: compat.h:101
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleW(IN HANDLE hConsoleOutput, IN CONST VOID *lpBuffer, IN DWORD nNumberOfCharsToWrite, OUT LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
Definition: readwrite.c:1449
GLuint GLuint GLsizei count
Definition: gl.h:1545
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:152
UINT WINAPI DECLSPEC_HOTPATCH GetConsoleOutputCP(VOID)
Definition: console.c:2453
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
GLenum GLsizei len
Definition: glext.h:6722
#define STD_OUTPUT_HANDLE
Definition: winbase.h:265
void * heap_xalloc(size_t size)
Definition: reg.c:83
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

◆ parse_registry_key()

BOOL parse_registry_key ( const WCHAR key,
HKEY root,
WCHAR **  path,
WCHAR **  long_key 
)

Definition at line 863 of file reg.c.

Referenced by reg_export(), and wmain().

864 {
865  if (!sane_path(key))
866  return FALSE;
867 
868  *path = strchrW(key, '\\');
869  if (*path) (*path)++;
870 
871  *root = path_get_rootkey(key);
872  if (!*root)
873  {
874  if (*path) *(*path - 1) = 0;
876  return FALSE;
877  }
878 
879  *long_key = get_long_key(*root, *path);
880 
881  return TRUE;
882 }
#define TRUE
Definition: types.h:120
WINE_UNICODE_INLINE WCHAR * strchrW(const WCHAR *str, WCHAR ch)
Definition: unicode.h:248
static WCHAR * get_long_key(HKEY root, WCHAR *path)
Definition: reg.c:836
void WINAPIV output_message(unsigned int id,...)
Definition: reg.c:147
#define STRING_INVALID_SYSTEM_KEY
Definition: resource.h:62
static BOOL sane_path(const WCHAR *key)
Definition: reg.c:354
Definition: services.c:325
HKEY path_get_rootkey(const WCHAR *path)
Definition: reg.c:210
Definition: path.c:42

◆ path_get_rootkey()

HKEY path_get_rootkey ( const WCHAR path)

Definition at line 210 of file reg.c.

Referenced by parse_key_name(), and parse_registry_key().

211 {
212  DWORD i;
213 
214  for (i = 0; i < ARRAY_SIZE(root_rels); i++)
215  {
218  return root_rels[i].key;
219  }
220 
221  return NULL;
222 }
GLenum GLclampf GLint i
Definition: glfuncs.h:14
smooth NULL
Definition: ftsmooth.c:416
static BOOL path_rootname_cmp(const WCHAR *input_path, const WCHAR *rootkey_name)
Definition: reg.c:202
unsigned long DWORD
Definition: ntddk_ex.h:95
const WCHAR * short_name
Definition: reg.c:43
const WCHAR * long_name
Definition: reg.c:44
#define ARRAY_SIZE(a)
Definition: main.h:24
Definition: services.c:325
static const struct @2 root_rels[]
Definition: path.c:42

◆ reg_export()

int reg_export ( int  argc,
WCHAR argv[] 
)

Definition at line 373 of file export.c.

Referenced by wmain().

374 {
375  HKEY root, hkey;
376  WCHAR *path, *long_key;
377  BOOL overwrite_file = FALSE;
378  HANDLE hFile;
379  int ret;
380 
381  if (argc == 3 || argc > 5)
382  goto error;
383 
384  if (!parse_registry_key(argv[2], &root, &path, &long_key))
385  return 1;
386 
387  if (argc == 5 && !(overwrite_file = is_overwrite_switch(argv[4])))
388  goto error;
389 
390  if (RegOpenKeyExW(root, path, 0, KEY_READ, &hkey))
391  {
393  return 1;
394  }
395 
396  hFile = get_file_handle(argv[3], overwrite_file);
397  export_file_header(hFile);
398  ret = export_registry_data(hFile, hkey, long_key);
399  export_newline(hFile);
400  CloseHandle(hFile);
401 
402  RegCloseKey(hkey);
403 
404  return ret;
405 
406 error:
409  return 1;
410 }
static int argc
Definition: ServiceArgs.c:12
#define CloseHandle
Definition: compat.h:398
#define error(str)
Definition: mkdosfs.c:1605
static BOOL is_overwrite_switch(const WCHAR *s)
Definition: export.c:362
#define KEY_READ
Definition: nt_native.h:1023
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLsizei const GLchar ** path
Definition: glext.h:7234
struct _root root
void WINAPIV output_message(unsigned int id,...)
Definition: reg.c:147
BOOL parse_registry_key(const WCHAR *key, HKEY *root, WCHAR **path, WCHAR **long_key)
Definition: reg.c:863
static char ** argv
Definition: ServiceArgs.c:11
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define STRING_INVALID_KEY
Definition: resource.h:31
#define STRING_FUNC_HELP
Definition: resource.h:55
unsigned int BOOL
Definition: ntddk_ex.h:94
static HANDLE get_file_handle(WCHAR *filename, BOOL overwrite_file)
Definition: export.c:329
#define STRING_INVALID_SYNTAX
Definition: resource.h:52
static int export_registry_data(HANDLE hFile, HKEY key, WCHAR *path)
Definition: export.c:241
int ret
_In_ HANDLE hFile
Definition: mswsock.h:90
static void export_newline(HANDLE hFile)
Definition: export.c:187
static void export_file_header(HANDLE hFile)
Definition: export.c:315
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3381
WINE_UNICODE_INLINE WCHAR * struprW(WCHAR *str)
Definition: unicode.h:288

◆ reg_import()

int reg_import ( const WCHAR filename)

Definition at line 995 of file import.c.

Referenced by wmain().

996 {
997  FILE *fp;
998  static const WCHAR rb_mode[] = {'r','b',0};
999  BYTE s[2];
1000  struct parser parser;
1001  WCHAR *pos;
1002 
1003  fp = _wfopen(filename, rb_mode);
1004  if (!fp)
1005  {
1007  return 1;
1008  }
1009 
1010  if (fread(s, sizeof(WCHAR), 1, fp) != 1)
1011  goto error;
1012 
1013  parser.is_unicode = (s[0] == 0xff && s[1] == 0xfe);
1015 
1016  parser.file = fp;
1017  parser.two_wchars[0] = s[0];
1018  parser.two_wchars[1] = s[1];
1019  parser.reg_version = -1;
1020  parser.hkey = NULL;
1021  parser.key_name = NULL;
1023  parser.parse_type = 0;
1024  parser.data_type = 0;
1025  parser.data = NULL;
1026  parser.data_size = 0;
1028  parser.state = HEADER;
1029 
1030  pos = parser.two_wchars;
1031 
1032  /* parser main loop */
1033  while (pos)
1034  pos = (parser_funcs[parser.state])(&parser, pos);
1035 
1037  goto error;
1038 
1040  close_key(&parser);
1041 
1042  fclose(fp);
1043  return 0;
1044 
1045 error:
1046  fclose(fp);
1047  return 1;
1048 }
WCHAR * value_name
Definition: import.c:94
static WCHAR * get_lineA(FILE *fp)
Definition: import.c:884
static void close_key(struct parser *parser)
Definition: import.c:363
#define error(str)
Definition: mkdosfs.c:1605
BOOL is_unicode
Definition: import.c:90
_Check_return_ _CRTIMP FILE *__cdecl _wfopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode)
__wchar_t WCHAR
Definition: xmlstorage.h:180
enum parser_state state
Definition: import.c:100
void WINAPIV output_message(unsigned int id,...)
Definition: reg.c:147
WCHAR two_wchars[2]
Definition: import.c:89
const char * filename
Definition: ioapi.h:135
BOOL backslash
Definition: import.c:99
void * data
Definition: import.c:97
DWORD parse_type
Definition: import.c:95
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
#define STRING_FILE_NOT_FOUND
Definition: resource.h:58
short int reg_version
Definition: import.c:91
smooth NULL
Definition: ftsmooth.c:416
Definition: import.c:66
FILE * file
Definition: import.c:88
HKEY hkey
Definition: import.c:92
static WCHAR * get_lineW(FILE *fp)
Definition: import.c:942
GLdouble s
Definition: gl.h:2039
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
unsigned char BYTE
Definition: ntddk_ex.h:96
static WCHAR *(* get_line)(FILE *)
Definition: import.c:61
WCHAR * key_name
Definition: import.c:93
Definition: import.c:86
DWORD data_type
Definition: import.c:96
static const parser_state_func parser_funcs[NB_PARSER_STATES]
Definition: import.c:124
DWORD data_size
Definition: import.c:98
static BOOL heap_free(void *mem)
Definition: appwiz.h:75