mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 22:43:01 +00:00
Francois Gouget : Make the dword and binary data parsing both more flexible and stricter. <fgouget at codeweavers.com>
Jason Edmeades : Fix importing of .reg hex. <jason.edmeades at googlemail.com> svn path=/trunk/; revision=31082
This commit is contained in:
parent
50ac6f77f8
commit
e2181b108c
2 changed files with 50 additions and 62 deletions
|
@ -157,16 +157,14 @@ void get_file_name(CHAR **command_line, CHAR *file_name)
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Converts a hex representation of a DWORD into a DWORD.
|
* Converts a hex representation of a DWORD into a DWORD.
|
||||||
*/
|
*/
|
||||||
DWORD convertHexToDWord(char *str, BYTE *buf)
|
static BOOL convertHexToDWord(char* str, DWORD *dw)
|
||||||
{
|
{
|
||||||
DWORD dw;
|
char dummy;
|
||||||
char xbuf[9];
|
if (strlen(str) > 8 || sscanf(str, "%lx%c", dw, &dummy) != 1) {
|
||||||
|
fprintf(stderr,"%s: ERROR, invalid hex value\n", getAppName());
|
||||||
memcpy(xbuf,str,8);
|
return FALSE;
|
||||||
xbuf[8]='\0';
|
}
|
||||||
sscanf(xbuf,"%08lx",&dw);
|
return TRUE;
|
||||||
memcpy(buf,&dw,sizeof(DWORD));
|
|
||||||
return sizeof(DWORD);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
|
@ -219,46 +217,45 @@ char* convertHexToDWORDStr(BYTE *buf, ULONG bufLen)
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Converts a hex comma separated values list into a hex list.
|
* Converts a hex comma separated values list into a binary string.
|
||||||
* The Hex input string must be in exactly the correct form.
|
|
||||||
*/
|
*/
|
||||||
DWORD convertHexCSVToHex(char *str, BYTE *buf, ULONG bufLen)
|
static BYTE* convertHexCSVToHex(char *str, DWORD *size)
|
||||||
{
|
{
|
||||||
char *s = str; /* Pointer to current */
|
char *s;
|
||||||
char *b = (char*) buf; /* Pointer to result */
|
BYTE *d, *data;
|
||||||
|
|
||||||
size_t strLen = strlen(str);
|
/* The worst case is 1 digit + 1 comma per byte */
|
||||||
size_t strPos = 0;
|
*size=(strlen(str)+1)/2;
|
||||||
DWORD byteCount = 0;
|
data=HeapAlloc(GetProcessHeap(), 0, *size);
|
||||||
|
CHECK_ENOUGH_MEMORY(data);
|
||||||
|
|
||||||
memset(buf, 0, bufLen);
|
s = str;
|
||||||
|
d = data;
|
||||||
/*
|
*size=0;
|
||||||
* warn the user if we are here with a string longer than 2 bytes that does
|
while (*s != '\0') {
|
||||||
* not contains ",". It is more likely because the data is invalid.
|
|
||||||
*/
|
|
||||||
if ( ( strLen > 2) && ( strchr(str, ',') == NULL) )
|
|
||||||
fprintf(stderr,"%s: WARNING converting CSV hex stream with no comma, "
|
|
||||||
"input data seems invalid.\n", getAppName());
|
|
||||||
if (strLen > 3*bufLen)
|
|
||||||
fprintf(stderr,"%s: ERROR converting CSV hex stream. Too long\n",
|
|
||||||
getAppName());
|
|
||||||
|
|
||||||
while (strPos < strLen) {
|
|
||||||
char xbuf[3];
|
|
||||||
UINT wc;
|
UINT wc;
|
||||||
|
char dummy;
|
||||||
|
|
||||||
memcpy(xbuf,s,2); xbuf[2]='\0';
|
if (s[1] != ',' && s[1] != '\0' && s[2] != ',' && s[2] != '\0') {
|
||||||
sscanf(xbuf,"%02x",&wc);
|
fprintf(stderr,"%s: ERROR converting CSV hex stream. Invalid sequence at '%s'\n",
|
||||||
if (byteCount < bufLen)
|
getAppName(), s);
|
||||||
*b++ =(unsigned char)wc;
|
HeapFree(GetProcessHeap(), 0, data);
|
||||||
|
return NULL;
|
||||||
s+=3;
|
}
|
||||||
strPos+=3;
|
if (sscanf(s, "%x%c", &wc, &dummy) < 1 || dummy != ',') {
|
||||||
byteCount++;
|
fprintf(stderr,"%s: ERROR converting CSV hex stream. Invalid value at '%s'\n",
|
||||||
|
getAppName(), s);
|
||||||
|
HeapFree(GetProcessHeap(), 0, data);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
*d++ =(BYTE)wc;
|
||||||
|
(*size)++;
|
||||||
|
/* Skip one or two digits and any comma */
|
||||||
|
while (*s && *s!=',') s++;
|
||||||
|
if (*s) s++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return byteCount;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
|
@ -417,11 +414,9 @@ static BOOL parseKeyName(LPSTR lpKeyName, HKEY *hKey, LPSTR *lpKeyPath)
|
||||||
LONG setValue(LPSTR val_name, LPSTR val_data)
|
LONG setValue(LPSTR val_name, LPSTR val_data)
|
||||||
{
|
{
|
||||||
LONG res;
|
LONG res;
|
||||||
DWORD dwDataType, dwParseType = REG_BINARY;
|
DWORD dwDataType, dwParseType;
|
||||||
LPBYTE lpbData;
|
LPBYTE lpbData;
|
||||||
BYTE convert[KEY_MAX_LEN];
|
DWORD dwData, dwLen;
|
||||||
BYTE *bBigBuffer = 0;
|
|
||||||
DWORD dwLen;
|
|
||||||
|
|
||||||
if ( (val_name == NULL) || (val_data == NULL) )
|
if ( (val_name == NULL) || (val_data == NULL) )
|
||||||
return ERROR_INVALID_PARAMETER;
|
return ERROR_INVALID_PARAMETER;
|
||||||
|
@ -449,21 +444,16 @@ LONG setValue(LPSTR val_name, LPSTR val_data)
|
||||||
}
|
}
|
||||||
else if (dwParseType == REG_DWORD) /* Convert the dword types */
|
else if (dwParseType == REG_DWORD) /* Convert the dword types */
|
||||||
{
|
{
|
||||||
dwLen = convertHexToDWord(val_data, convert);
|
if (!convertHexToDWord(val_data, &dwData))
|
||||||
lpbData = convert;
|
return ERROR_INVALID_DATA;
|
||||||
|
lpbData = (BYTE*)&dwData;
|
||||||
|
dwLen = sizeof(dwData);
|
||||||
}
|
}
|
||||||
else if (dwParseType == REG_BINARY) /* Convert the binary data */
|
else if (dwParseType == REG_BINARY) /* Convert the binary data */
|
||||||
{
|
{
|
||||||
size_t b_len = strlen (val_data)+2/3;
|
lpbData = convertHexCSVToHex(val_data, &dwLen);
|
||||||
if (b_len > KEY_MAX_LEN) {
|
if (!lpbData)
|
||||||
bBigBuffer = HeapAlloc (GetProcessHeap(), 0, b_len);
|
return ERROR_INVALID_DATA;
|
||||||
CHECK_ENOUGH_MEMORY(bBigBuffer);
|
|
||||||
dwLen = convertHexCSVToHex(val_data, bBigBuffer, (ULONG) b_len);
|
|
||||||
lpbData = bBigBuffer;
|
|
||||||
} else {
|
|
||||||
dwLen = convertHexCSVToHex(val_data, convert, KEY_MAX_LEN);
|
|
||||||
lpbData = convert;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else /* unknown format */
|
else /* unknown format */
|
||||||
{
|
{
|
||||||
|
@ -479,8 +469,8 @@ LONG setValue(LPSTR val_name, LPSTR val_data)
|
||||||
lpbData,
|
lpbData,
|
||||||
dwLen);
|
dwLen);
|
||||||
|
|
||||||
if (bBigBuffer)
|
if (dwParseType == REG_BINARY)
|
||||||
HeapFree (GetProcessHeap(), 0, bBigBuffer);
|
HeapFree(GetProcessHeap(), 0, lpbData);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,6 @@ void processRegLines(FILE *in, CommandAPI command);
|
||||||
*/
|
*/
|
||||||
char* getToken(char** str, const char* delims);
|
char* getToken(char** str, const char* delims);
|
||||||
void get_file_name(CHAR **command_line, CHAR *filename);
|
void get_file_name(CHAR **command_line, CHAR *filename);
|
||||||
DWORD convertHexToDWord(char *str, BYTE *buf);
|
|
||||||
DWORD convertHexCSVToHex(char *str, BYTE *buf, ULONG bufLen);
|
|
||||||
LPSTR convertHexToHexCSV( BYTE *buf, ULONG len);
|
LPSTR convertHexToHexCSV( BYTE *buf, ULONG len);
|
||||||
LPSTR convertHexToDWORDStr( BYTE *buf, ULONG len);
|
LPSTR convertHexToDWORDStr( BYTE *buf, ULONG len);
|
||||||
LPSTR getRegKeyName(LPSTR lpLine);
|
LPSTR getRegKeyName(LPSTR lpLine);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue