29 #include <wine/unicode.h> 31 #define REG_VAL_BUF_SIZE 4096 36 #define REG_FILE_HEX_LINE_LEN (2 + 25 * 3) 40 L"HKEY_LOCAL_MACHINE",
L"HKEY_USERS",
L"HKEY_CLASSES_ROOT",
41 L"HKEY_CURRENT_CONFIG",
L"HKEY_CURRENT_USER",
L"HKEY_DYN_DATA" 49 #define REG_CLASS_NUMBER (sizeof(reg_class_keys) / sizeof(reg_class_keys[0])) 52 #define NOT_ENOUGH_MEMORY 1 58 #define CHECK_ENOUGH_MEMORY(p) \ 61 fprintf(stderr,"%S: file %s, line %d: Not enough memory\n", \ 62 getAppName(), __FILE__, __LINE__); \ 63 exit(NOT_ENOUGH_MEMORY); \ 181 if (
end ==
s || wc > 0xff || (*
end && *
end !=
',')) {
183 fprintf(
stderr,
"%S: ERROR converting CSV hex stream. Invalid value at '%s'\n",
210 static const WCHAR str[] = {
's',
't',
'r',
':',
'"'};
211 static const WCHAR str2[] = {
's',
't',
'r',
'(',
'2',
')',
':',
'"'};
212 static const WCHAR hex[] = {
'h',
'e',
'x',
':'};
213 static const WCHAR dword[] = {
'd',
'w',
'o',
'r',
'd',
':'};
214 static const WCHAR hexp[] = {
'h',
'e',
'x',
'('};
216 static const struct data_type data_types[] = {
226 const struct data_type *
ptr;
229 for (
ptr = data_types;
ptr->tag;
ptr++) {
242 if (**lpValue==
'\0' || *
end!=
')' || *(
end+1)!=
':') {
262 for (str_idx = 0; str_idx <
len; str_idx++, val_idx++) {
263 if (
str[str_idx] ==
'\\') {
265 switch (
str[str_idx]) {
271 str[val_idx] =
str[str_idx];
274 fprintf(
stderr,
"Warning! Unrecognized escape sequence: \\%c'\n",
276 str[val_idx] =
str[str_idx];
280 str[val_idx] =
str[str_idx];
291 if (lpKeyName ==
NULL)
294 for(
i = 0; *(lpKeyName+
i) != 0;
i++)
296 if(*(lpKeyName+
i) ==
'\\')
298 lpSlash = lpKeyName+
i;
305 len = lpSlash-lpKeyName;
310 lpSlash = lpKeyName+
len;
326 if (*lpSlash !=
'\0')
328 *lpKeyPath = lpSlash;
347 DWORD dwDataType, dwParseType;
352 if ( (val_name ==
NULL) || (val_data ==
NULL) )
364 if (dwParseType ==
REG_SZ)
372 if(val_data[dwLen-1] !=
'"')
374 if (dwLen>0 && val_data[dwLen-1]==
'"')
377 val_data[dwLen]=
'\0';
379 lpbData = (
BYTE*) val_data;
381 dwLen = dwLen *
sizeof(
WCHAR);
400 dwLen *=
sizeof(
WCHAR);
434 if (stdInput ==
NULL)
492 if (
line[line_idx] ==
'@' &&
line[line_idx + 1] ==
'=') {
493 line[line_idx] =
'\0';
496 }
else if (
line[line_idx] ==
'\"') {
498 val_name =
line + line_idx;
499 while (
line[line_idx]) {
500 if (
line[line_idx] ==
'\\')
504 if (
line[line_idx] ==
'\"') {
505 line[line_idx] =
'\0';
514 if (!
line[line_idx]) {
518 if (
line[line_idx] !=
'=') {
520 line[line_idx] =
'\"';
536 val_data =
line + line_idx;
539 while (line_idx > 0 &&
isspaceW(val_data[line_idx-1])) line_idx--;
540 val_data[line_idx] =
'\0';
548 fprintf(
stderr,
"%S: ERROR Key %s not created. Value: %s, Data: %s\n",
569 if (stdInput ==
NULL) {
574 if ( stdInput[0] ==
'[')
586 if ( stdInput[0] ==
'-')
597 (( stdInput[0] ==
'@') ||
598 ( stdInput[0] ==
'\"')))
639 size_t size_remaining;
645 size_remaining = lineSize - (
s-
line);
646 if (size_remaining < 2)
650 if (new_size > lineSize)
656 s =
line + lineSize - size_remaining;
658 size_remaining = lineSize - (
s-
line);
664 size_to_get = (size_remaining >
INT_MAX ?
INT_MAX : size_remaining);
668 for(
i = 0;
i < size_to_get-1; ++
i){
675 perror(
"While reading input");
683 if(
i+2 >= size_to_get){
706 if (!
feof (
in) && !s_eol) {
712 if (
line [0] ==
'#' ||
line [0] ==
';') {
719 if (*s_eol ==
'\r' && *(s_eol+1) ==
'\n')
726 if (s_eol >
line && *(s_eol-1) ==
'\\') {
733 }
while(
c ==
' ' ||
c ==
'\t');
765 size_t CharsInBuf = -1;
777 size_t size_remaining;
783 size_remaining = lineSize - (
s-
buf);
784 if (size_remaining < 2)
788 if (new_size > lineSize)
795 s =
buf + lineSize - size_remaining;
797 size_remaining = lineSize - (
s-
buf);
803 size_to_get = (size_remaining >
INT_MAX ?
INT_MAX : size_remaining);
808 if (CharsInBuf == 0) {
810 perror (
"While reading input");
825 const WCHAR line_endings[] = {
'\r',
'\n',0};
840 if (*s_eol ==
'\r' && *(s_eol+1) ==
'\n')
848 if (*(s_eol-1) ==
'\\') {
851 if(*s_eol ==
'\r' && *(s_eol+1) ==
'\n')
870 if (*s_eol ==
'\r' && *(s_eol + 1) ==
'\n')
902 fprintf(
stderr,
"%S: Cannot display message for error %lu, status %lu\n",
924 if (required_len > *
len) {
944 if (required_size > *
size) {
945 *
size = required_size;
972 (*line_buf)[
pos++] =
'\\';
973 (*line_buf)[
pos++] =
'n';
980 (*line_buf)[
pos++] =
'\\';
984 (*line_buf)[
pos++] =
c;
988 (*line_buf)[
pos] =
'\0';
994 DWORD hex_pos, data_pos;
995 const WCHAR *hex_prefix;
996 const WCHAR hex[] = {
'h',
'e',
'x',
':',0};
998 const WCHAR concat[] = {
'\\',
'\r',
'\n',
' ',
' ',0};
999 DWORD concat_prefix, concat_len;
1000 const WCHAR newline[] = {
'\r',
'\n',0};
1006 const WCHAR hex_format[] = {
'h',
'e',
'x',
'(',
'%',
'x',
')',
':',0};
1007 hex_prefix = hex_buf;
1019 hex_pos = *line_len;
1021 data_pos = *line_len;
1022 *line_len += value_size * 3;
1034 lstrcpyW(*line_buf + hex_pos, hex_prefix);
1046 if (++
i == value_size)
1049 (*line_buf)[data_pos++] =
',';
1054 lstrcpyW(*line_buf + data_pos, concat);
1055 data_pos += concat_len;
1060 lstrcpyW(*line_buf + data_pos, newline);
1097 WCHAR **reg_key_name_buf,
DWORD *reg_key_name_size,
1103 DWORD max_sub_key_len;
1104 DWORD max_val_name_len;
1110 WCHAR key_format[] = {
'\r',
'\n',
'[',
'%',
's',
']',
'\r',
'\n',0};
1114 &max_sub_key_len,
NULL,
1119 curr_len =
strlenW(*reg_key_name_buf);
1121 max_sub_key_len + curr_len + 1);
1127 sprintfW(*line_buf, key_format, *reg_key_name_buf);
1135 DWORD val_name_size1 = *val_name_size;
1136 DWORD val_size1 = *val_size;
1138 &value_type, *val_buf, &val_size1);
1152 if ((*val_name_buf)[0]) {
1153 const WCHAR val_start[] = {
'"',
'%',
's',
'"',
'=',0};
1158 lstrcpyW(*val_name_buf, *line_buf);
1160 line_len = 3 +
lstrlenW(*val_name_buf);
1162 sprintfW(*line_buf, val_start, *val_name_buf);
1164 const WCHAR std_val[] = {
'@',
'=',0};
1170 switch (value_type) {
1175 if (val_size1 <
sizeof(
WCHAR) || val_size1 %
sizeof(
WCHAR) ||
1176 wstr[val_size1 /
sizeof(
WCHAR) - 1]) {
1177 REGPROC_export_binary(line_buf, line_buf_size, &line_len, value_type, *val_buf, val_size1, unicode);
1180 const WCHAR end[] = {
'"',
'\r',
'\n',0};
1201 WCHAR format[] = {
'd',
'w',
'o',
'r',
'd',
':',
'%',
'0',
'8',
'x',
'\r',
'\n',0};
1212 fprintf(
stderr,
"%S: warning - unsupported registry format '%ld', " 1213 "treat as binary\n",
1225 REGPROC_export_binary(line_buf, line_buf_size, &line_len, value_type, *val_buf, val_size1, unicode);
1233 (*reg_key_name_buf)[curr_len] =
'\\';
1235 DWORD buf_size = *reg_key_name_size - curr_len - 1;
1254 val_name_buf, val_name_size, val_buf, val_size,
1255 line_buf, line_buf_size, unicode);
1262 (*reg_key_name_buf)[curr_len] =
'\0';
1290 const BYTE unicode_seq[] = {0xff,0xfe};
1291 const WCHAR header[] = {
'W',
'i',
'n',
'd',
'o',
'w',
's',
' ',
'R',
'e',
'g',
'i',
's',
't',
'r',
'y',
' ',
'E',
'd',
'i',
't',
'o',
'r',
' ',
'V',
'e',
'r',
's',
'i',
'o',
'n',
' ',
'5',
'.',
'0',
'0',
'\r',
'\n'};
1292 fwrite(unicode_seq,
sizeof(
BYTE),
sizeof(unicode_seq)/
sizeof(unicode_seq[0]),
file);
1312 WCHAR *reg_key_name_buf;
1313 WCHAR *val_name_buf;
1324 reg_key_name_size *
sizeof(*reg_key_name_buf));
1326 val_name_size *
sizeof(*val_name_buf));
1331 if (reg_key_name && reg_key_name[0]) {
1338 lstrcpyW(reg_key_name_buf, reg_key_name);
1341 if (!
parseKeyName(reg_key_name, ®_key_class, &branch_name)) {
1343 fprintf(
stderr,
"%S: Incorrect registry class specification in '%s'\n",
1348 if (!branch_name[0]) {
1352 ®_key_name_buf, ®_key_name_size,
1353 &val_name_buf, &val_name_size,
1354 &val_buf, &val_size, &line_buf,
1355 &line_buf_size, unicode);
1359 ®_key_name_buf, ®_key_name_size,
1360 &val_name_buf, &val_name_size,
1361 &val_buf, &val_size, &line_buf,
1362 &line_buf_size, unicode);
1366 fprintf(
stderr,
"%S: Can't export. Registry key '%s' does not exist!\n",
1384 ®_key_name_buf, ®_key_name_size,
1385 &val_name_buf, &val_name_size,
1386 &val_buf, &val_size, &line_buf,
1387 &line_buf_size, unicode);
1410 if (
fread(
s, 2, 1, reg_file) == 1)
1412 if (
s[0] == 0xff &&
s[1] == 0xfe)
1437 if (!reg_key_name || !reg_key_name[0])
1442 fprintf(
stderr,
"%S: Incorrect registry class specification in '%s'\n",
#define ERROR_INVALID_PARAMETER
static BYTE * convertHexCSVToHex(WCHAR *str, DWORD *size)
static WCHAR * GetWideStringN(const char *strA, int chars, DWORD *len)
static BOOL parseKeyName(LPWSTR lpKeyName, HKEY *hKey, LPWSTR *lpKeyPath)
_Check_return_ _CRTIMP int __cdecl ferror(_In_ FILE *_File)
#define _setmode(fd, mode)
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
#define WideCharToMultiByte
#define ERROR_NO_MORE_ITEMS
char * strpbrk(const char *String, const char *Delimiters)
static void REGPROC_export_string(WCHAR **line_buf, DWORD *line_buf_size, DWORD *line_len, WCHAR *str, DWORD str_len)
WINE_UNICODE_INLINE WCHAR * strchrW(const WCHAR *str, WCHAR ch)
WCHAR * GetWideString(const char *strA)
#define LOCALE_USER_DEFAULT
WINE_UNICODE_INLINE int isspaceW(WCHAR wc)
int WINAPI lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
#define HKEY_CURRENT_USER
static void REGPROC_export_binary(WCHAR **line_buf, DWORD *line_buf_size, DWORD *line_len, DWORD type, BYTE *value, DWORD value_size, BOOL unicode)
static void processSetValue(WCHAR *line, BOOL is_unicode)
static HANDLE ULONG_PTR dwData
DWORD WINAPI GetLastError(VOID)
static void REGPROC_resize_binary_buffer(BYTE **buffer, DWORD *size, DWORD required_size)
static LONG setValue(WCHAR *val_name, WCHAR *val_data, BOOL is_unicode)
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
#define HKEY_CURRENT_CONFIG
static const char hex[16]
static LPSTR currentKeyName
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
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)
WINE_UNICODE_INLINE int strncmpW(const WCHAR *str1, const WCHAR *str2, int n)
static void processRegLinesA(FILE *in, char *first_chars)
GLenum GLuint GLenum GLsizei const GLchar * buf
_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)
static FILE * REGPROC_open_export_file(WCHAR *file_name, BOOL unicode)
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
static void REGPROC_write_line(FILE *file, const WCHAR *str, BOOL unicode)
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
const char * file_nameA(const char *str) DECLSPEC_HIDDEN
static void processRegEntry(WCHAR *stdInput, BOOL isUnicode)
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
REFIID LPVOID DWORD_PTR dw
static HKEY currentKeyHandle
LONG WINAPI RegEnumValueW(_In_ HKEY hKey, _In_ DWORD index, _Out_ LPWSTR value, _Inout_ PDWORD val_count, _Reserved_ PDWORD reserved, _Out_opt_ PDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ PDWORD count)
_Check_return_opt_ _CRTIMP_ALT int __cdecl ungetc(_In_ int _Ch, _Inout_ FILE *_File)
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
#define ERROR_FILE_NOT_FOUND
#define FORMAT_MESSAGE_FROM_SYSTEM
char * GetMultiByteString(const WCHAR *strW)
static char * GetMultiByteStringN(const WCHAR *strW, int chars, DWORD *len)
#define REG_FILE_HEX_LINE_LEN
#define REG_OPTION_NON_VOLATILE
INT WINAPI CompareStringW(LCID lcid, DWORD flags, LPCWSTR str1, INT len1, LPCWSTR str2, INT len2)
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
_Check_return_ _CRTIMP int __cdecl feof(_In_ FILE *_File)
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
static const WCHAR quote[]
WINE_UNICODE_INLINE WCHAR * strpbrkW(const WCHAR *str, const WCHAR *accept)
static BOOL convertHexToDWord(WCHAR *str, DWORD *dw)
static void REGPROC_print_error(void)
const WCHAR * reg_class_namesW[]
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
LONG WINAPI RegQueryInfoKeyW(HKEY hKey, LPWSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)
int parse_type(Type t, const vector< string > &tokens, int off, vector< string > &names, vector< string > &dependencies)
#define memcpy(s1, s2, n)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
int puts(const char *string)
WINE_UNICODE_INLINE WCHAR * strrchrW(const WCHAR *str, WCHAR ch)
#define ERROR_INVALID_DATA
static VOID del(LPHIST_ENTRY item)
static void processRegLinesW(FILE *in)
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
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
HLOCAL NTAPI LocalFree(HLOCAL hMem)
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)
BOOL export_registry_key(WCHAR *file_name, WCHAR *reg_key_name, DWORD format)
#define MultiByteToWideChar
char * strchr(const char *String, int ch)
static HKEY reg_class_keys[]
static LONG openKeyW(WCHAR *stdInput)
BOOL import_registry_file(FILE *reg_file)
static void REGPROC_unescape_string(WCHAR *str)
#define HKEY_CLASSES_ROOT
#define strtoulW(s1, s2, b)
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
GLenum GLenum GLvoid GLvoid * column
GLuint GLuint GLsizei GLenum type
_Check_return_ _CRTIMP int __cdecl _fileno(_In_ FILE *_File)
static void closeKey(void)
static void REGPROC_resize_char_buffer(WCHAR **buffer, DWORD *len, DWORD required_len)
static SERVICE_STATUS status
#define CHECK_ENOUGH_MEMORY(p)
#define HeapFree(x, y, z)
#define RegCloseKey(hKey)
_Check_return_opt_ _CRTIMP int __cdecl fputs(_In_z_ const char *_Str, _Inout_ FILE *_File)
void delete_registry_key(WCHAR *reg_key_name)
static DWORD getDataType(LPWSTR *lpValue, DWORD *parse_type)
_Check_return_opt_ _CRTIMP int __cdecl fgetc(_Inout_ FILE *_File)
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
#define HKEY_LOCAL_MACHINE