Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.IO.IOException: Invalid key specification in .reg, line 3 #2

Open
Lavshyak opened this issue Nov 5, 2024 · 1 comment
Open

Comments

@Lavshyak
Copy link

Lavshyak commented Nov 5, 2024

In Cklutz.RegFile 1.0.9 nuget.org and in cloned this repository.

using RegFile;

using var reader = new RegFileReader("C:\\CodeProjects\\NET\\RegCSVToReg\\FullReester.reg");
var commands = reader.Read(); //exception
System.IO.IOException: Invalid key specification in C:\CodeProjects\NET\RegCSVToReg\FullReester.reg, line 3
   at RegFile.RegFileExtensions.ParseException(SourceLocation location, String msg)
   at RegFile.RegFileExtensions.SplitIntoHiveAndSubKey(ReadOnlySpan`1 span, SourceLocation sourceLocation)
   at RegFile.RegFileReader.Read()
   at Program.<Main>$(String[] args) in C:\CodeProjects\NET\RegCSVToReg\RegCSVToReg\Program.cs:line 4

first part of FullReester.reg (exported by windows 10 registry editor) (line 3 is [HKEY_LOCAL_MACHINE]):

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE]

[HKEY_LOCAL_MACHINE\BCD00000000]

[HKEY_LOCAL_MACHINE\BCD00000000\Description]
"KeyName"="BCD00000000"
"System"=dword:00000001
"TreatAsSystem"=dword:00000001
"GuidCache"=hex:23,1e,b1,3d,97,2b,db,01,0a,27,00,00,10,ec,00,0c,29,13,24,13,76,\
  00,00,00

[HKEY_LOCAL_MACHINE\BCD00000000\Objects]

SplitIntoHiveAndSubKey method tries to split HKEY_LOCAL_MACHINE, but there is no sub key.

@Lavshyak
Copy link
Author

Lavshyak commented Nov 5, 2024

possible fiix (.net8 windows target, nullable enabled):

RegistrySubKeyCommand.cs:11
public string? SubKey { get; set; }

RegFileReader.cs:117
(var hive, string? subKeyName) = subkey.SplitIntoHiveAndSubKey(sourceLocation);

RegFileExtensions:14

public static (RegistryHive, string?) SplitIntoHiveAndSubKey(this ReadOnlySpan<char> span, SourceLocation sourceLocation)
        {
            int pos = span.IndexOf('\\');
            if (pos == -1)
            {
                var hive1 = StringToHive(span.ToString());
                if(hive1.HasValue)
                    return (hive1.Value, null);
                
                throw sourceLocation.ParseException("Invalid key specification");
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant