ReactOS  0.4.13-dev-241-g63286c6
regproc.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define KEY_MAX_LEN   1024
 
#define REG_FORMAT_5   1
 
#define REG_FORMAT_4   2
 

Functions

BOOL export_registry_key (WCHAR *file_name, WCHAR *reg_key_name, DWORD format)
 
BOOL import_registry_file (FILE *in)
 
void delete_registry_key (WCHAR *reg_key_name)
 
WCHARGetWideString (const char *strA)
 
CHARGetMultiByteString (const WCHAR *strW)
 

Macro Definition Documentation

◆ KEY_MAX_LEN

#define KEY_MAX_LEN   1024

Definition at line 22 of file regproc.h.

◆ REG_FORMAT_4

#define REG_FORMAT_4   2

Definition at line 25 of file regproc.h.

◆ REG_FORMAT_5

#define REG_FORMAT_5   1

Definition at line 24 of file regproc.h.

Function Documentation

◆ delete_registry_key()

void delete_registry_key ( WCHAR reg_key_name)

Definition at line 1432 of file regproc.c.

1433 {
1434  WCHAR *key_name = NULL;
1435  HKEY key_class;
1436 
1437  if (!reg_key_name || !reg_key_name[0])
1438  return;
1439 
1440  if (!parseKeyName(reg_key_name, &key_class, &key_name)) {
1441  char* reg_key_nameA = GetMultiByteString(reg_key_name);
1442  fprintf(stderr,"%S: Incorrect registry class specification in '%s'\n",
1443  getAppName(), reg_key_nameA);
1444  HeapFree(GetProcessHeap(), 0, reg_key_nameA);
1445  exit(1);
1446  }
1447  if (!*key_name) {
1448  char* reg_key_nameA = GetMultiByteString(reg_key_name);
1449  fprintf(stderr,"%S: Can't delete registry class '%s'\n",
1450  getAppName(), reg_key_nameA);
1451  HeapFree(GetProcessHeap(), 0, reg_key_nameA);
1452  exit(1);
1453  }
1454 
1455  SHDeleteKey(key_class, key_name);
1456 }
static BOOL parseKeyName(LPWSTR lpKeyName, HKEY *hKey, LPWSTR *lpKeyPath)
Definition: regproc.c:286
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
smooth NULL
Definition: ftsmooth.c:416
char * GetMultiByteString(const WCHAR *strW)
Definition: regproc.c:109
#define GetProcessHeap()
Definition: compat.h:395
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define SHDeleteKey
Definition: shlwapi.h:44
LPCWSTR getAppName(void)
Definition: regedit.c:61
FILE * stderr
void exit(int exitcode)
Definition: _exit.c:33
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by PerformRegAction(), and processRegEntry().

◆ export_registry_key()

BOOL export_registry_key ( WCHAR file_name,
WCHAR reg_key_name,
DWORD  format 
)

Definition at line 1310 of file regproc.c.

1311 {
1312  WCHAR *reg_key_name_buf;
1313  WCHAR *val_name_buf;
1314  BYTE *val_buf;
1315  WCHAR *line_buf;
1316  DWORD reg_key_name_size = KEY_MAX_LEN;
1317  DWORD val_name_size = KEY_MAX_LEN;
1318  DWORD val_size = REG_VAL_BUF_SIZE;
1319  DWORD line_buf_size = KEY_MAX_LEN + REG_VAL_BUF_SIZE;
1320  FILE *file = NULL;
1321  BOOL unicode = (format == REG_FORMAT_5);
1322 
1323  reg_key_name_buf = HeapAlloc(GetProcessHeap(), 0,
1324  reg_key_name_size * sizeof(*reg_key_name_buf));
1325  val_name_buf = HeapAlloc(GetProcessHeap(), 0,
1326  val_name_size * sizeof(*val_name_buf));
1327  val_buf = HeapAlloc(GetProcessHeap(), 0, val_size);
1328  line_buf = HeapAlloc(GetProcessHeap(), 0, line_buf_size * sizeof(*line_buf));
1329  CHECK_ENOUGH_MEMORY(reg_key_name_buf && val_name_buf && val_buf && line_buf);
1330 
1331  if (reg_key_name && reg_key_name[0]) {
1332  HKEY reg_key_class;
1333  WCHAR *branch_name = NULL;
1334  HKEY key;
1335 
1336  REGPROC_resize_char_buffer(&reg_key_name_buf, &reg_key_name_size,
1337  lstrlenW(reg_key_name));
1338  lstrcpyW(reg_key_name_buf, reg_key_name);
1339 
1340  /* open the specified key */
1341  if (!parseKeyName(reg_key_name, &reg_key_class, &branch_name)) {
1342  CHAR* key_nameA = GetMultiByteString(reg_key_name);
1343  fprintf(stderr,"%S: Incorrect registry class specification in '%s'\n",
1344  getAppName(), key_nameA);
1345  HeapFree(GetProcessHeap(), 0, key_nameA);
1346  exit(1);
1347  }
1348  if (!branch_name[0]) {
1349  /* no branch - registry class is specified */
1351  export_hkey(file, reg_key_class,
1352  &reg_key_name_buf, &reg_key_name_size,
1353  &val_name_buf, &val_name_size,
1354  &val_buf, &val_size, &line_buf,
1355  &line_buf_size, unicode);
1356  } else if (RegOpenKeyW(reg_key_class, branch_name, &key) == ERROR_SUCCESS) {
1358  export_hkey(file, key,
1359  &reg_key_name_buf, &reg_key_name_size,
1360  &val_name_buf, &val_name_size,
1361  &val_buf, &val_size, &line_buf,
1362  &line_buf_size, unicode);
1363  RegCloseKey(key);
1364  } else {
1365  CHAR* key_nameA = GetMultiByteString(reg_key_name);
1366  fprintf(stderr,"%S: Can't export. Registry key '%s' does not exist!\n",
1367  getAppName(), key_nameA);
1368  HeapFree(GetProcessHeap(), 0, key_nameA);
1370  }
1371  } else {
1372  unsigned int i;
1373 
1374  /* export all registry classes */
1376  for (i = 0; i < REG_CLASS_NUMBER; i++) {
1377  /* do not export HKEY_CLASSES_ROOT */
1382  lstrcpyW(reg_key_name_buf, reg_class_namesW[i]);
1384  &reg_key_name_buf, &reg_key_name_size,
1385  &val_name_buf, &val_name_size,
1386  &val_buf, &val_size, &line_buf,
1387  &line_buf_size, unicode);
1388  }
1389  }
1390  }
1391 
1392  if (file) {
1393  fclose(file);
1394  }
1395  HeapFree(GetProcessHeap(), 0, reg_key_name);
1396  HeapFree(GetProcessHeap(), 0, val_name_buf);
1397  HeapFree(GetProcessHeap(), 0, val_buf);
1398  HeapFree(GetProcessHeap(), 0, line_buf);
1399  return TRUE;
1400 }
static BOOL parseKeyName(LPWSTR lpKeyName, HKEY *hKey, LPWSTR *lpKeyPath)
Definition: regproc.c:286
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define HKEY_CURRENT_USER
Definition: winreg.h:11
char CHAR
Definition: xmlstorage.h:175
#define HKEY_DYN_DATA
Definition: winreg.h:16
#define HKEY_CURRENT_CONFIG
Definition: winreg.h:15
#define lstrlenW
Definition: compat.h:407
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
#define KEY_MAX_LEN
Definition: regproc.h:22
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
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
static FILE * REGPROC_open_export_file(WCHAR *file_name, BOOL unicode)
Definition: regproc.c:1268
unsigned int BOOL
Definition: ntddk_ex.h:94
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3311
smooth NULL
Definition: ftsmooth.c:416
char * GetMultiByteString(const WCHAR *strW)
Definition: regproc.c:109
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
static void REGPROC_print_error(void)
Definition: regproc.c:892
const WCHAR * reg_class_namesW[]
Definition: regproc.c:38
unsigned long DWORD
Definition: ntddk_ex.h:95
#define REG_FORMAT_5
Definition: regproc.h:24
#define REG_CLASS_NUMBER
Definition: regproc.c:49
HKEY key
Definition: reg.c:42
unsigned char BYTE
Definition: mem.h:68
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
#define lstrcpyW
Definition: compat.h:406
static void export_hkey(FILE *file, HKEY key, WCHAR **reg_key_name_buf, DWORD *reg_key_name_size, WCHAR **val_name_buf, DWORD *val_name_size, BYTE **val_buf, DWORD *val_size, WCHAR **line_buf, DWORD *line_buf_size, BOOL unicode)
Definition: regproc.c:1096
static LPCWSTR file_name
Definition: protocol.c:146
static HKEY reg_class_keys[]
Definition: regproc.c:44
LPCWSTR getAppName(void)
Definition: regedit.c:61
FILE * stderr
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
void exit(int exitcode)
Definition: _exit.c:33
static void REGPROC_resize_char_buffer(WCHAR **buffer, DWORD *len, DWORD required_len)
Definition: regproc.c:921
#define REG_VAL_BUF_SIZE
Definition: regproc.c:31
#define CHECK_ENOUGH_MEMORY(p)
Definition: regproc.c:58
#define HeapFree(x, y, z)
Definition: compat.h:394
Definition: path.c:42
Definition: fci.c:126

Referenced by ExportRegistryFile(), and PerformRegAction().

◆ GetMultiByteString()

CHAR* GetMultiByteString ( const WCHAR strW)

Definition at line 109 of file regproc.c.

110 {
111  if(strW)
112  {
113  char* strA;
114  int len = WideCharToMultiByte(CP_ACP, 0, strW, -1, NULL, 0, NULL, NULL);
115 
116  strA = HeapAlloc(GetProcessHeap(), 0, len);
119  return strA;
120  }
121  return NULL;
122 }
char strA[12]
Definition: clipboard.c:2028
#define WideCharToMultiByte
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:99
WCHAR strW[12]
Definition: clipboard.c:2029
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
GLenum GLsizei len
Definition: glext.h:6722
#define CHECK_ENOUGH_MEMORY(p)
Definition: regproc.c:58

Referenced by convertHexCSVToHex(), delete_registry_key(), export_hkey(), export_registry_key(), openKeyW(), processRegEntry(), processSetValue(), REGPROC_open_export_file(), and REGPROC_write_line().

◆ GetWideString()

WCHAR* GetWideString ( const char strA)

Definition at line 70 of file regproc.c.

71 {
72  if(strA)
73  {
74  WCHAR* strW;
75  int len = MultiByteToWideChar(CP_ACP, 0, strA, -1, NULL, 0);
76 
77  strW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
80  return strW;
81  }
82  return NULL;
83 }
char strA[12]
Definition: clipboard.c:2028
#define CP_ACP
Definition: compat.h:99
WCHAR strW[12]
Definition: clipboard.c:2029
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLenum GLsizei len
Definition: glext.h:6722
#define MultiByteToWideChar
Definition: compat.h:100
#define CHECK_ENOUGH_MEMORY(p)
Definition: regproc.c:58

Referenced by processRegLinesA().

◆ import_registry_file()

BOOL import_registry_file ( FILE in)

Definition at line 1405 of file regproc.c.

1406 {
1407  if (reg_file)
1408  {
1409  BYTE s[2];
1410  if (fread( s, 2, 1, reg_file) == 1)
1411  {
1412  if (s[0] == 0xff && s[1] == 0xfe)
1413  {
1414  processRegLinesW(reg_file);
1415  } else
1416  {
1417  processRegLinesA(reg_file, (char*)s);
1418  }
1419  }
1420  return TRUE;
1421  }
1422  return FALSE;
1423 }
#define TRUE
Definition: types.h:120
static void processRegLinesA(FILE *in, char *first_chars)
Definition: regproc.c:618
_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)
unsigned char BYTE
Definition: mem.h:68
GLdouble s
Definition: gl.h:2039
static void processRegLinesW(FILE *in)
Definition: regproc.c:761

Referenced by ImportRegistryFile(), and PerformRegAction().