Menu

#45 Cannot parse registry values when name contains ':'

open
nobody
None
5
2012-10-31
2012-10-31
No

A NullPointerException occurs in RegEscapeTool.decode(String) if a value name contains the ':' (colon) character. Specifically, the value type cannot be determined, so type.toString() causes the exception.

The root cause is in the use of IniParser to parse the exported reg file. The colon character is defined as a parser operator (along with '=') in the default constructor for IniParser. This example value (from HKLM\SOFTWARE\Microsoft\WIndows NT\CurrentVersion\KnownFunctionTableDlls on XP SP3) fails to parse in this way:
"c:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\mscordacwks.dll"=dword:00000000
IniParser interprets everything after the "c:" as part of the value data, so RegEscapeTool.type(String) attempts to match this String against a Registry.Type:
\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\mscordacwks.dll"=dword
This is not a valid type, so the call to the null Type reference throws NPE.

A solution would be to define a new protected constructor for IniParser and create a RegParser subclass:
protected IniParser(String operators, String comments)
{
super(operators, comments);
}

And the new RegParser:

package org.ini4j.spi;

import org.ini4j.Config;

public class RegParser extends IniParser {

private static final String COMMENTS = ";";
private static final String OPERATORS = "=";

public RegParser()
{
super(OPERATORS, COMMENTS);
}

public static RegParser newInstance()
{
return ServiceFinder.findService(RegParser.class);
}

public static RegParser newInstance(Config config)
{
RegParser instance = newInstance();

instance.setConfig(config);

return instance;
}
}

The method Reg.load(Reader) would then use RegParser.newInstance instead of IniParser,newInstance.

Discussion


Log in to post a comment.