ReactOS  0.4.15-dev-1203-g0e5a4d5
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.

Function Documentation

◆ ask_confirm()

BOOL ask_confirm ( unsigned int  msgid,
WCHAR reg_info 
)

Definition at line 172 of file reg.c.

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 
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);
194  answer[0] = towupper(answer[0]);
195  if (answer[0] == Ybuffer[0])
196  return TRUE;
197  if (answer[0] == Nbuffer[0])
198  return FALSE;
199  }
200 }
#define STRING_NO
Definition: resource.h:42
#define TRUE
Definition: types.h:120
GLuint GLuint GLsizei count
Definition: gl.h:1545
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:200
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)
#define FALSE
Definition: types.h:117
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
#define STRING_YES
Definition: resource.h:41
#define STD_INPUT_HANDLE
Definition: winbase.h:264
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:1174
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:34
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:838
#define towupper(c)
Definition: wctype.h:99

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

◆ 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.

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  swprintf(subkey_path, fmt, path, subkey_name);
639 
640  return subkey_path;
641 }
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define swprintf(buf, format,...)
Definition: sprintf.c:56
static DWORD path_len
Definition: batch.c:31
void * heap_xalloc(size_t size)
Definition: reg.c:83
Definition: dsound.c:943

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

◆ heap_xalloc()

void* heap_xalloc ( size_t  size)

Definition at line 83 of file reg.c.

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:110
void exit(int exitcode)
Definition: _exit.c:33

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().

◆ heap_xrealloc()

void* heap_xrealloc ( void buf,
size_t  size 
)

Definition at line 94 of file reg.c.

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 }
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
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:110
void exit(int exitcode)
Definition: _exit.c:33

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

◆ output_message()

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

Definition at line 147 of file reg.c.

148 {
149  WCHAR fmt[1024];
150  __ms_va_list va_args;
151 
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 static const char __ms_va_list
Definition: printf.c:76
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
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
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define ARRAY_SIZE(a)
Definition: main.h:24
#define __ms_va_end(list)
Definition: windef.h:458
#define __ms_va_start(list, arg)
Definition: windef.h:457
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
Definition: dsound.c:943
#define WINE_FIXME
Definition: debug.h:365

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().

◆ output_writeconsole()

void output_writeconsole ( const WCHAR str,
DWORD  wlen 
)

Definition at line 107 of file reg.c.

108 {
109  DWORD count, ret;
110 
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  */
122  msgA = heap_xalloc(len);
123 
124  WideCharToMultiByte(GetConsoleOutputCP(), 0, str, wlen, msgA, len, NULL, NULL);
126  heap_free(msgA);
127  }
128 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define WideCharToMultiByte
Definition: compat.h:111
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleW(IN HANDLE hConsoleOutput, IN CONST VOID *lpBuffer, IN DWORD nNumberOfCharsToWrite, OUT LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
Definition: readwrite.c:1447
GLuint GLuint GLsizei count
Definition: gl.h:1545
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:200
#define FALSE
Definition: types.h:117
UINT WINAPI DECLSPEC_HOTPATCH GetConsoleOutputCP(VOID)
Definition: console.c:2453
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
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

Referenced by get_file_handle(), and output_formatstring().

◆ 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.

864 {
865  if (!sane_path(key))
866  return FALSE;
867 
868  *path = wcschr(key, '\\');
869  if (*path) (*path)++;
870 
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
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 FALSE
Definition: types.h:117
#define STRING_INVALID_SYSTEM_KEY
Definition: resource.h:62
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
static BOOL sane_path(const WCHAR *key)
Definition: reg.c:354
HKEY path_get_rootkey(const WCHAR *path)
Definition: reg.c:210
Definition: path.c:41

Referenced by reg_export(), and wmain().

◆ path_get_rootkey()

HKEY path_get_rootkey ( const WCHAR path)

Definition at line 210 of file reg.c.

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 }
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
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
static const struct @2 root_rels[]
Definition: path.c:41

Referenced by parse_key_name(), and parse_registry_key().

◆ reg_export()

int reg_export ( int  argc,
WCHAR argv[] 
)

Definition at line 373 of file export.c.

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);
398  ret = export_registry_data(hFile, hkey, long_key);
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:598
#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
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
#define argv
Definition: mplay32.c:18
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define STRING_INVALID_KEY
Definition: resource.h:31
#define STRING_FUNC_HELP
Definition: resource.h:55
_CRTIMP wchar_t *__cdecl _wcsupr(_Inout_z_ wchar_t *_String)
static HANDLE get_file_handle(WCHAR *filename, BOOL overwrite_file)
Definition: export.c:329
__wchar_t WCHAR
Definition: xmlstorage.h:180
#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:3366

Referenced by wmain().

◆ reg_import()

int reg_import ( const WCHAR filename)

Definition at line 991 of file import.c.

992 {
993  FILE *fp;
994  static const WCHAR rb_mode[] = {'r','b',0};
995  BYTE s[2];
996  struct parser parser;
997  WCHAR *pos;
998 
999  fp = _wfopen(filename, rb_mode);
1000  if (!fp)
1001  {
1003  return 1;
1004  }
1005 
1006  if (fread(s, sizeof(WCHAR), 1, fp) != 1)
1007  goto error;
1008 
1009  parser.is_unicode = (s[0] == 0xff && s[1] == 0xfe);
1011 
1012  parser.file = fp;
1013  parser.two_wchars[0] = s[0];
1014  parser.two_wchars[1] = s[1];
1015  parser.reg_version = -1;
1016  parser.hkey = NULL;
1017  parser.key_name = NULL;
1019  parser.parse_type = 0;
1020  parser.data_type = 0;
1021  parser.data = NULL;
1022  parser.data_size = 0;
1024  parser.state = HEADER;
1025 
1026  pos = parser.two_wchars;
1027 
1028  /* parser main loop */
1029  while (pos)
1031 
1033  goto error;
1034 
1036  close_key(&parser);
1037 
1038  fclose(fp);
1039  return 0;
1040 
1041 error:
1042  fclose(fp);
1043  return 1;
1044 }
WCHAR * value_name
Definition: import.c:93
static WCHAR * get_lineA(FILE *fp)
Definition: import.c:880
static void close_key(struct parser *parser)
Definition: import.c:362
#define error(str)
Definition: mkdosfs.c:1605
BOOL is_unicode
Definition: import.c:89
_Check_return_ _CRTIMP FILE *__cdecl _wfopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode)
enum parser_state state
Definition: import.c:99
void WINAPIV output_message(unsigned int id,...)
Definition: reg.c:147
WCHAR two_wchars[2]
Definition: import.c:88
const char * filename
Definition: ioapi.h:135
BOOL backslash
Definition: import.c:98
void * data
Definition: import.c:96
DWORD parse_type
Definition: import.c:94
_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 FALSE
Definition: types.h:117
short int reg_version
Definition: import.c:90
smooth NULL
Definition: ftsmooth.c:416
Definition: import.c:65
__wchar_t WCHAR
Definition: xmlstorage.h:180
FILE * file
Definition: import.c:87
#define STRING_FILE_NOT_FOUND
Definition: resource.h:8
HKEY hkey
Definition: import.c:91
static WCHAR * get_lineW(FILE *fp)
Definition: import.c:938
GLdouble s
Definition: gl.h:2039
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
unsigned char BYTE
Definition: xxhash.c:193
static WCHAR *(* get_line)(FILE *)
Definition: import.c:60
WCHAR * key_name
Definition: import.c:92
Definition: import.c:85
DWORD data_type
Definition: import.c:95
static const parser_state_func parser_funcs[NB_PARSER_STATES]
Definition: import.c:123
DWORD data_size
Definition: import.c:97
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by wmain().