/****************************************************************************** * 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. * * line - registry file unwrapped line. Should have the registry value name and * complete registry value data. */ static void processSetValue(WCHAR* line, BOOL is_unicode) { WCHAR* val_name; /* registry value name */ WCHAR* val_data; /* registry value data */ int line_idx = 0; /* current character under analysis */ LONG res; /* get value name */ while ( isspaceW(line[line_idx]) ) line_idx++; if (line[line_idx] == '@' && line[line_idx + 1] == '=') { line[line_idx] = '\0'; val_name = line; line_idx++; } else if (line[line_idx] == '\"') { line_idx++; val_name = line + line_idx; while (line[line_idx]) { if (line[line_idx] == '\\') /* skip escaped character */ { line_idx += 2; } else { if (line[line_idx] == '\"') { line[line_idx] = '\0'; line_idx++; break; } else { line_idx++; } } } while ( isspaceW(line[line_idx]) ) line_idx++; if (!line[line_idx]) { output_message(STRING_UNEXPECTED_EOL, line); return; } if (line[line_idx] != '=') { line[line_idx] = '\"'; output_message(STRING_UNRECOGNIZED_LINE, line); return; } } else { output_message(STRING_UNRECOGNIZED_LINE, line); return; } line_idx++; /* skip the '=' character */ while ( isspaceW(line[line_idx]) ) line_idx++; val_data = line + line_idx; /* trim trailing blanks */ line_idx = strlenW(val_data); while (line_idx > 0 && isspaceW(val_data[line_idx-1])) line_idx--; val_data[line_idx] = '\0'; REGPROC_unescape_string(val_name); res = setValue(val_name, val_data, is_unicode); if ( res != ERROR_SUCCESS ) output_message(STRING_SETVALUE_FAILED, val_name, currentKeyName); }
/****************************************************************************** * Sets the value with name val_name to the data in val_data for the currently * opened key. * * Parameters: * val_name - name of the registry value * val_data - registry value data */ HRESULT setValue(LPTSTR val_name, LPTSTR val_data) { HRESULT hRes; DWORD dwDataType, dwParseType; LPBYTE lpbData; BYTE convert[KEY_MAX_LEN]; BYTE *bBigBuffer = 0; DWORD dwLen; if ((val_name == NULL) || (val_data == NULL)) return ERROR_INVALID_PARAMETER; /* Get the data type stored into the value field */ dwDataType = getDataType(&val_data, &dwParseType); // if (dwParseType == REG_EXPAND_SZ) { // } // if (dwParseType == REG_SZ || dwParseType == REG_EXPAND_SZ) { /* no conversion for string */ if (dwParseType == REG_SZ) { /* no conversion for string */ dwLen = _tcslen(val_data); if (dwLen > 0 && val_data[dwLen-1] == _T('"')) { dwLen--; val_data[dwLen] = _T('\0'); } dwLen++; dwLen *= sizeof(TCHAR); REGPROC_unescape_string(val_data); lpbData = val_data; } else if (dwParseType == REG_DWORD) { /* Convert the dword types */ dwLen = convertHexToDWord(val_data, convert); lpbData = convert; } else { /* Convert the hexadecimal types */ int b_len = _tcslen(val_data)+2/3; if (b_len > KEY_MAX_LEN) { bBigBuffer = HeapAlloc (GetProcessHeap(), 0, b_len * sizeof(TCHAR)); if (bBigBuffer == NULL) { return ERROR_REGISTRY_IO_FAILED; } CHECK_ENOUGH_MEMORY(bBigBuffer); dwLen = convertHexCSVToHex(val_data, bBigBuffer, b_len); lpbData = bBigBuffer; } else { dwLen = convertHexCSVToHex(val_data, convert, KEY_MAX_LEN); lpbData = convert; } } hRes = RegSetValueEx(currentKeyHandle, val_name, 0, /* Reserved */dwDataType, lpbData, dwLen); _tprintf(_T(" Value: %s, Data: %s\n"), val_name, lpbData); if (bBigBuffer) HeapFree(GetProcessHeap(), 0, bBigBuffer); return hRes; }
/****************************************************************************** * This function is a wrapper for the setValue function. It prepares the * land and clean the area once completed. * Note: this function modifies the line parameter. * * line - registry file unwrapped line. Should have the registry value name and * complete registry value data. */ void processSetValue(LPTSTR line) { LPTSTR val_name; /* registry value name */ LPTSTR val_data; /* registry value data */ int line_idx = 0; /* current character under analysis */ HRESULT hRes = 0; /* get value name */ if (line[line_idx] == _T('@') && line[line_idx + 1] == _T('=')) { line[line_idx] = _T('\0'); val_name = line; line_idx++; } else if (line[line_idx] == _T('\"')) { line_idx++; val_name = line + line_idx; while (TRUE) { if (line[line_idx] == _T('\\')) { /* skip escaped character */ line_idx += 2; } else { if (line[line_idx] == _T('\"')) { line[line_idx] = _T('\0'); line_idx++; break; } else { line_idx++; } } } if (line[line_idx] != _T('=')) { line[line_idx] = _T('\"'); _tprintf(_T("Warning! uncrecognized line:\n%s\n"), line); return; } } else { _tprintf(_T("Warning! unrecognized line:\n%s\n"), line); return; } line_idx++; /* skip the '=' character */ val_data = line + line_idx; REGPROC_unescape_string(val_name); _tprintf(_T("Key: %s, Value: %s, Data: %s\n"), currentKeyName, val_name, val_data); hRes = setValue(val_name, val_data); if (hRes != ERROR_SUCCESS) { _tprintf(_T("ERROR Key %s not created. Value: %s, Data: %s\n"), currentKeyName, val_name, val_data); } }
/****************************************************************************** * 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. * * line - registry file unwrapped line. Should have the registry value name and * complete registry value data. */ static void processSetValue(WCHAR* line, BOOL is_unicode) { WCHAR* val_name; /* registry value name */ WCHAR* val_data; /* registry value data */ int line_idx = 0; /* current character under analysis */ LONG res; /* get value name */ while ( isspaceW(line[line_idx]) ) line_idx++; if (line[line_idx] == '@' && line[line_idx + 1] == '=') { line[line_idx] = '\0'; val_name = line; line_idx++; } else if (line[line_idx] == '\"') { line_idx++; val_name = line + line_idx; while (line[line_idx]) { if (line[line_idx] == '\\') /* skip escaped character */ { line_idx += 2; } else { if (line[line_idx] == '\"') { line[line_idx] = '\0'; line_idx++; break; } else { line_idx++; } } } while ( isspaceW(line[line_idx]) ) line_idx++; if (!line[line_idx]) { fprintf(stderr, "%s: warning: unexpected EOL\n", getAppName()); return; } if (line[line_idx] != '=') { char* lineA; line[line_idx] = '\"'; lineA = GetMultiByteString(line); fprintf(stderr,"%s: warning: unrecognized line: '%s'\n", getAppName(), lineA); HeapFree(GetProcessHeap(), 0, lineA); return; } } else { char* lineA = GetMultiByteString(line); fprintf(stderr,"%s: warning: unrecognized line: '%s'\n", getAppName(), lineA); HeapFree(GetProcessHeap(), 0, lineA); return; } line_idx++; /* skip the '=' character */ while ( isspaceW(line[line_idx]) ) line_idx++; val_data = line + line_idx; /* trim trailing blanks */ line_idx = strlenW(val_data); while (line_idx > 0 && isspaceW(val_data[line_idx-1])) line_idx--; val_data[line_idx] = '\0'; REGPROC_unescape_string(val_name); res = setValue(val_name, val_data, is_unicode); if ( res != ERROR_SUCCESS ) { char* val_nameA = GetMultiByteString(val_name); char* val_dataA = GetMultiByteString(val_data); fprintf(stderr,"%s: ERROR Key %s not created. Value: %s, Data: %s\n", getAppName(), currentKeyName, val_nameA, val_dataA); HeapFree(GetProcessHeap(), 0, val_nameA); HeapFree(GetProcessHeap(), 0, val_dataA); } }
/****************************************************************************** * Sets the value with name val_name to the data in val_data for the currently * opened key. * * Parameters: * val_name - name of the registry value * val_data - registry value data */ static LONG setValue(WCHAR* val_name, WCHAR* val_data, BOOL is_unicode) { LONG res; DWORD dwDataType, dwParseType; LPBYTE lpbData; DWORD dwData, dwLen; WCHAR del[] = {'-',0}; if ( (val_name == NULL) || (val_data == NULL) ) return ERROR_INVALID_PARAMETER; if (lstrcmpW(val_data, del) == 0) { res=RegDeleteValueW(currentKeyHandle,val_name); return (res == ERROR_FILE_NOT_FOUND ? ERROR_SUCCESS : res); } /* Get the data type stored into the value field */ dwDataType = getDataType(&val_data, &dwParseType); if (dwParseType == REG_SZ) /* no conversion for string */ { REGPROC_unescape_string(val_data); /* Compute dwLen after REGPROC_unescape_string because it may * have changed the string length and we don't want to store * the extra garbage in the registry. */ dwLen = lstrlenW(val_data); if(val_data[dwLen-1] != '"') return ERROR_INVALID_DATA; if (dwLen>0 && val_data[dwLen-1]=='"') { dwLen--; val_data[dwLen]='\0'; } lpbData = (BYTE*) val_data; dwLen++; /* include terminating null */ dwLen = dwLen * sizeof(WCHAR); /* size is in bytes */ } else if (dwParseType == REG_DWORD) /* Convert the dword types */ { if (!convertHexToDWord(val_data, &dwData)) return ERROR_INVALID_DATA; lpbData = (BYTE*)&dwData; dwLen = sizeof(dwData); } else if (dwParseType == REG_BINARY) /* Convert the binary data */ { lpbData = convertHexCSVToHex(val_data, &dwLen); if (!lpbData) return ERROR_INVALID_DATA; if((dwDataType == REG_MULTI_SZ || dwDataType == REG_EXPAND_SZ) && !is_unicode) { LPBYTE tmp = lpbData; lpbData = (LPBYTE)GetWideStringN((char*)lpbData, dwLen, &dwLen); dwLen *= sizeof(WCHAR); HeapFree(GetProcessHeap(), 0, tmp); } } else /* unknown format */ { fprintf(stderr,"%s: ERROR, unknown data format\n", getAppName()); return ERROR_INVALID_DATA; } res = RegSetValueExW( currentKeyHandle, val_name, 0, /* Reserved */ dwDataType, lpbData, dwLen); if (dwParseType == REG_BINARY) HeapFree(GetProcessHeap(), 0, lpbData); return res; }
/****************************************************************************** * Sets the value with name val_name to the data in val_data for the currently * opened key. * * Parameters: * val_name - name of the registry value * val_data - registry value data */ static LONG setValue(WCHAR* val_name, WCHAR* val_data, BOOL is_unicode) { LONG res; DWORD dwDataType, dwParseType; LPBYTE lpbData; DWORD dwData, dwLen; WCHAR del[] = {'-',0}; if ( (val_name == NULL) || (val_data == NULL) ) return ERROR_INVALID_PARAMETER; if (lstrcmpW(val_data, del) == 0) { res=RegDeleteValueW(currentKeyHandle,val_name); return (res == ERROR_FILE_NOT_FOUND ? ERROR_SUCCESS : res); } /* Get the data type stored into the value field */ dwDataType = getDataType(&val_data, &dwParseType); if (dwParseType == REG_SZ) /* no conversion for string */ { dwLen = REGPROC_unescape_string(val_data); if(!dwLen || val_data[dwLen-1] != '"') return ERROR_INVALID_DATA; val_data[dwLen-1] = '\0'; /* remove last quotes */ lpbData = (BYTE*) val_data; dwLen = dwLen * sizeof(WCHAR); /* size is in bytes */ } else if (dwParseType == REG_DWORD) /* Convert the dword types */ { if (!convertHexToDWord(val_data, &dwData)) return ERROR_INVALID_DATA; lpbData = (BYTE*)&dwData; dwLen = sizeof(dwData); } else if (dwParseType == REG_BINARY) /* Convert the binary data */ { lpbData = convertHexCSVToHex(val_data, &dwLen); if (!lpbData) return ERROR_INVALID_DATA; if((dwDataType == REG_MULTI_SZ || dwDataType == REG_EXPAND_SZ) && !is_unicode) { LPBYTE tmp = lpbData; lpbData = (LPBYTE)GetWideStringN((char*)lpbData, dwLen, &dwLen); dwLen *= sizeof(WCHAR); HeapFree(GetProcessHeap(), 0, tmp); } } else /* unknown format */ { output_message(STRING_UNKNOWN_DATA_FORMAT, reg_type_to_wchar(dwDataType)); return ERROR_INVALID_DATA; } res = RegSetValueExW( currentKeyHandle, val_name, 0, /* Reserved */ dwDataType, lpbData, dwLen); if (dwParseType == REG_BINARY) HeapFree(GetProcessHeap(), 0, lpbData); return res; }