Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
ca98e234
Commit
ca98e234
authored
Jun 15, 2017
by
Hugh McMaster
Committed by
Alexandre Julliard
Jun 15, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
regedit: Perform key operations in the state machine.
Signed-off-by:
Hugh McMaster
<
hugh.mcmaster@outlook.com
>
Signed-off-by:
Alexandre Julliard
<
julliard@winehq.org
>
parent
ec878008
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
77 deletions
+73
-77
regproc.c
programs/regedit/regproc.c
+73
-77
No files found.
programs/regedit/regproc.c
View file @
ca98e234
...
...
@@ -136,6 +136,8 @@ enum parser_state
HEADER
,
/* parsing the registry file version header */
PARSE_WIN31_LINE
,
/* parsing a Windows 3.1 registry line */
LINE_START
,
/* at the beginning of a registry line */
KEY_NAME
,
/* parsing a key name */
DELETE_KEY
,
/* deleting a registry key */
SET_VALUE
,
/* adding a value to the registry */
NB_PARSER_STATES
};
...
...
@@ -159,6 +161,8 @@ typedef WCHAR *(*parser_state_func)(struct parser *parser, WCHAR *pos);
static
WCHAR
*
header_state
(
struct
parser
*
parser
,
WCHAR
*
pos
);
static
WCHAR
*
parse_win31_line_state
(
struct
parser
*
parser
,
WCHAR
*
pos
);
static
WCHAR
*
line_start_state
(
struct
parser
*
parser
,
WCHAR
*
pos
);
static
WCHAR
*
key_name_state
(
struct
parser
*
parser
,
WCHAR
*
pos
);
static
WCHAR
*
delete_key_state
(
struct
parser
*
parser
,
WCHAR
*
pos
);
static
WCHAR
*
set_value_state
(
struct
parser
*
parser
,
WCHAR
*
pos
);
static
const
parser_state_func
parser_funcs
[
NB_PARSER_STATES
]
=
...
...
@@ -166,6 +170,8 @@ static const parser_state_func parser_funcs[NB_PARSER_STATES] =
header_state
,
/* HEADER */
parse_win31_line_state
,
/* PARSE_WIN31_LINE */
line_start_state
,
/* LINE_START */
key_name_state
,
/* KEY_NAME */
delete_key_state
,
/* DELETE_KEY */
set_value_state
,
/* SET_VALUE */
};
...
...
@@ -348,21 +354,20 @@ static BOOL REGPROC_unescape_string(WCHAR *str, WCHAR **unparsed)
return
ret
;
}
static
HKEY
parse
KeyName
(
LPWSTR
lpKeyName
,
LPWSTR
*
lpKeyP
ath
)
static
HKEY
parse
_key_name
(
WCHAR
*
key_name
,
WCHAR
**
key_p
ath
)
{
unsigned
int
i
;
if
(
lpKeyName
==
NULL
)
return
0
;
if
(
!
key_name
)
return
0
;
*
lpKeyPath
=
strchrW
(
lpKeyN
ame
,
'\\'
);
if
(
*
lpKeyPath
)
(
*
lpKeyP
ath
)
++
;
*
key_path
=
strchrW
(
key_n
ame
,
'\\'
);
if
(
*
key_path
)
(
*
key_p
ath
)
++
;
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
reg_class_keys
);
i
++
)
{
int
len
=
lstrlenW
(
reg_class_namesW
[
i
]);
if
(
!
strncmpW
(
lpKeyN
ame
,
reg_class_namesW
[
i
],
len
)
&&
(
lpKeyName
[
len
]
==
0
||
lpKeyN
ame
[
len
]
==
'\\'
))
if
(
!
strncmpW
(
key_n
ame
,
reg_class_namesW
[
i
],
len
)
&&
(
key_name
[
len
]
==
0
||
key_n
ame
[
len
]
==
'\\'
))
{
return
reg_class_keys
[
i
];
}
...
...
@@ -500,36 +505,36 @@ static LONG setValue(WCHAR* val_name, WCHAR* val_data, BOOL is_unicode)
return
res
;
}
static
void
closeKey
(
void
)
{
if
(
currentKeyHandle
)
{
HeapFree
(
GetProcessHeap
(),
0
,
currentKeyName
);
currentKeyName
=
NULL
;
RegCloseKey
(
currentKeyHandle
);
currentKeyHandle
=
NULL
;
}
}
/******************************************************************************
*
A helper function for processRegEntry() that opens the current key
.
* Th
at key must be closed by calling closeK
ey().
*
Opens the registry key given by the input path
.
* Th
is key must be closed by calling close_k
ey().
*/
static
LONG
openKeyW
(
WCHAR
*
stdInput
)
{
HKEY
keyClass
;
WCHAR
*
keyPath
;
DWORD
dwDisp
;
HKEY
key_class
;
WCHAR
*
key_path
;
LONG
res
;
/* Sanity checks */
if
(
stdInput
==
NULL
)
return
ERROR_INVALID_PARAMETER
;
closeKey
();
/* Get the registry class */
if
(
!
(
keyClass
=
parseKeyName
(
stdInput
,
&
keyP
ath
)))
if
(
!
stdInput
||
!
(
key_class
=
parse_key_name
(
stdInput
,
&
key_p
ath
)))
return
ERROR_INVALID_PARAMETER
;
res
=
RegCreateKeyExW
(
keyClass
,
/* Class */
keyPath
,
/* Sub Key */
0
,
/* MUST BE 0 */
NULL
,
/* object type */
REG_OPTION_NON_VOLATILE
,
/* option, REG_OPTION_NON_VOLATILE ... */
KEY_ALL_ACCESS
,
/* access mask, KEY_ALL_ACCESS */
NULL
,
/* security attribute */
&
currentKeyHandle
,
/* result */
&
dwDisp
);
/* disposition, REG_CREATED_NEW_KEY or
REG_OPENED_EXISTING_KEY */
res
=
RegCreateKeyExW
(
key_class
,
key_path
,
0
,
NULL
,
REG_OPTION_NON_VOLATILE
,
KEY_ALL_ACCESS
,
NULL
,
&
currentKeyHandle
,
NULL
);
if
(
res
==
ERROR_SUCCESS
)
{
...
...
@@ -545,19 +550,6 @@ static LONG openKeyW(WCHAR* stdInput)
}
/******************************************************************************
* Close the currently opened key.
*/
static
void
closeKey
(
void
)
{
if
(
currentKeyHandle
)
{
HeapFree
(
GetProcessHeap
(),
0
,
currentKeyName
);
RegCloseKey
(
currentKeyHandle
);
currentKeyHandle
=
NULL
;
}
}
/******************************************************************************
* This function is a wrapper for the setValue function. It prepares the
* land and cleans the area once completed.
* Note: this function modifies the line parameter.
...
...
@@ -600,38 +592,6 @@ error:
output_message
(
STRING_INVALID_LINE_SYNTAX
);
}
/******************************************************************************
* This function receives the currently read entry and performs the
* corresponding action.
* isUnicode affects parsing of REG_MULTI_SZ values
*/
static
void
processRegEntry
(
WCHAR
*
stdInput
,
BOOL
isUnicode
)
{
if
(
stdInput
[
0
]
==
'['
)
/* We are reading a new key */
{
WCHAR
*
keyEnd
;
closeKey
();
/* Close the previous key */
/* Get rid of the square brackets */
stdInput
++
;
keyEnd
=
strrchrW
(
stdInput
,
']'
);
if
(
keyEnd
)
*
keyEnd
=
'\0'
;
else
return
;
/* delete the key if we encounter '-' at the start of reg key */
if
(
stdInput
[
0
]
==
'-'
)
delete_registry_key
(
stdInput
+
1
);
else
if
(
openKeyW
(
stdInput
)
!=
ERROR_SUCCESS
)
output_message
(
STRING_OPEN_KEY_FAILED
,
stdInput
);
}
else
if
(
currentKeyHandle
&&
((
stdInput
[
0
]
==
'@'
)
||
/* reading a default @=data pair */
(
stdInput
[
0
]
==
'\"'
)))
/* reading a new value=data pair */
{
processSetValue
(
stdInput
,
isUnicode
);
}
}
enum
reg_versions
{
REG_VERSION_31
,
REG_VERSION_40
,
...
...
@@ -765,11 +725,12 @@ static WCHAR *line_start_state(struct parser *parser, WCHAR *pos)
switch
(
*
p
)
{
case
'['
:
set_state
(
parser
,
KEY_NAME
);
return
p
+
1
;
case
'@'
:
case
'"'
:
processRegEntry
(
p
,
parser
->
is_unicode
);
set_state
(
parser
,
LINE_START
);
return
line
;
processSetValue
(
p
,
parser
->
is_unicode
);
return
p
;
case
' '
:
case
'\t'
:
break
;
...
...
@@ -782,6 +743,41 @@ static WCHAR *line_start_state(struct parser *parser, WCHAR *pos)
return
p
;
}
/* handler for parser KEY_NAME state */
static
WCHAR
*
key_name_state
(
struct
parser
*
parser
,
WCHAR
*
pos
)
{
WCHAR
*
p
=
pos
,
*
key_end
;
if
(
*
p
==
' '
||
*
p
==
'\t'
||
!
(
key_end
=
strrchrW
(
p
,
']'
)))
goto
done
;
*
key_end
=
0
;
if
(
*
p
==
'-'
)
{
set_state
(
parser
,
DELETE_KEY
);
return
p
+
1
;
}
else
if
(
openKeyW
(
p
)
!=
ERROR_SUCCESS
)
output_message
(
STRING_OPEN_KEY_FAILED
,
p
);
done:
set_state
(
parser
,
LINE_START
);
return
p
;
}
/* handler for parser DELETE_KEY state */
static
WCHAR
*
delete_key_state
(
struct
parser
*
parser
,
WCHAR
*
pos
)
{
WCHAR
*
p
=
pos
;
if
(
*
p
==
'H'
)
delete_registry_key
(
p
);
set_state
(
parser
,
LINE_START
);
return
p
;
}
/* handler for parser SET_VALUE state */
static
WCHAR
*
set_value_state
(
struct
parser
*
parser
,
WCHAR
*
pos
)
{
...
...
@@ -1348,7 +1344,7 @@ BOOL export_registry_key(WCHAR *file_name, WCHAR *reg_key_name, DWORD format)
lstrcpyW
(
reg_key_name_buf
,
reg_key_name
);
/* open the specified key */
if
(
!
(
reg_key_class
=
parse
KeyN
ame
(
reg_key_name
,
&
branch_name
)))
{
if
(
!
(
reg_key_class
=
parse
_key_n
ame
(
reg_key_name
,
&
branch_name
)))
{
output_message
(
STRING_INCORRECT_REG_CLASS
,
reg_key_name
);
exit
(
1
);
}
...
...
@@ -1455,7 +1451,7 @@ void delete_registry_key(WCHAR *reg_key_name)
if
(
!
reg_key_name
||
!
reg_key_name
[
0
])
return
;
if
(
!
(
key_class
=
parse
KeyN
ame
(
reg_key_name
,
&
key_name
)))
{
if
(
!
(
key_class
=
parse
_key_n
ame
(
reg_key_name
,
&
key_name
)))
{
output_message
(
STRING_INCORRECT_REG_CLASS
,
reg_key_name
);
exit
(
1
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment