kessler / node-regedit

Read, Write, List and do all sorts of funky stuff to the windows registry using node.js and windows script host
MIT License
279 stars 45 forks source link

Invalid JSON on invalid registry values #93

Closed Spown closed 1 year ago

Spown commented 2 years ago

So I'm trying to read these values from the registry, some of which (installTime) appear to be invalid:

    regedit.arch.list([ "LDPlayer", "LDPlayer64" ].map(emu=>`HKCU\\SOFTWARE\\XuanZhi\\${emu}`), function (err, result) {
      if (!err) {
        result;
      } else {
        console.error(err);
      }
    })
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\SOFTWARE\XuanZhi]

[HKEY_CURRENT_USER\SOFTWARE\XuanZhi\LDPlayer]
"InstallDir"="C:\\games\\LDPlayer\\32\\4\\"
"Version"="0400006700"
"DataDir"="C:\\games\\LDPlayer\\32\\4\\vms"
"InstallProgress"="1"
"installTime"=hex(4):c7,01,74,61,00,00,00,00

[HKEY_CURRENT_USER\SOFTWARE\XuanZhi\LDPlayer64]
"InstallDir"="C:\\games\\LDPlayer\\64\\4\\"
"Version"="0400005300"
"DataDir"="C:\\games\\LDPlayer\\64\\4\\vms"
"InstallProgress"="1"
"installTime"=hex(4):5f,99,92,60,00,00,00,00

image

The reason is probably because they belong to a Chinese app, encoding issues or smth... irrelevant. The point is, these values create invalid JSON:

"{\"HKCU\\\\SOFTWARE\\\\XuanZhi\\\\LDPlayer\": {\"exists\": true,\"keys\": [],\"values\":{\"InstallDir\":{\"type\": \"REG_SZ\",\"value\":\"C:\\\\games\\\\LDPlayer\\\\32\\\\4\\\\\"},\"Version\":{\"type\": \"REG_SZ\",\"value\":\"0400006700\"},\"DataDir\":{\"type\": \"REG_SZ\",\"value\":\"C:\\\\games\\\\LDPlayer\\\\32\\\\4\\\\vms\"},\"InstallProgress\":{\"type\": \"REG_SZ\",\"value\":\"1\"},\"installTime\":{\"type\": \"REG_DWORD\",\"value\":,\"HKCU\\\\SOFTWARE\\\\XuanZhi\\\\LDPlayer64\": {\"exists\": true,\"keys\": [],\"values\":{\"InstallDir\":{\"type\": \"REG_SZ\",\"value\":\"C:\\\\games\\\\LDPlayer\\\\64\\\\4\\\\\"},\"Version\":{\"type\": \"REG_SZ\",\"value\":\"0400005300\"},\"DataDir\":{\"type\": \"REG_SZ\",\"value\":\"C:\\\\games\\\\LDPlayer\\\\64\\\\4\\\\vms\"},\"InstallProgress\":{\"type\": \"REG_SZ\",\"value\":\"1\"},\"installTime\":{\"type\": \"REG_DWORD\",\"value\":}"
{
    "HKCU\\SOFTWARE\\XuanZhi\\LDPlayer": {
        "exists": true,
        "keys": [],
        "values": {
            "InstallDir": {
                "type": "REG_SZ",
                "value": "C:\\games\\LDPlayer\\32\\4\\"
            },
            "Version": {
                "type": "REG_SZ",
                "value": "0400006700"
            },
            "DataDir": {
                "type": "REG_SZ",
                "value": "C:\\games\\LDPlayer\\32\\4\\vms"
            },
            "InstallProgress": {
                "type": "REG_SZ",
                "value": "1"
            },
            "installTime": {
                "type": "REG_DWORD",
                "value": 
    ,
    "HKCU\\SOFTWARE\\XuanZhi\\LDPlayer64": {
        "exists": true,
        "keys": [],
        "values": {
            "InstallDir": {
                "type": "REG_SZ",
                "value": "C:\\games\\LDPlayer\\64\\4\\"
            },
            "Version": {
                "type": "REG_SZ",
                "value": "0400005300"
            },
            "DataDir": {
                "type": "REG_SZ",
                "value": "C:\\games\\LDPlayer\\64\\4\\vms"
            },
            "InstallProgress": {
                "type": "REG_SZ",
                "value": "1"
            },
            "installTime": {
                "type": "REG_DWORD",
                "value":
}

When exporting a .reg file these values are written as hex(4). It would be nice if something similar would be happening here, like: {type: "HEX(4)", value: ["5f","99","92","60","00","00","00","00"]}. Or maybe {type: "INVALID", value: ""}. Or just omit them altogether (in my case I don't care about these values, I only need DataDir, which is valid).

I would try a PR, but I have only a vague idea what is happening in those .wsf files.

Thnx in advance.

kessler commented 2 years ago

I was unable to recreate this. Please attach a .reg file that I can use and reopen the issue

Spown commented 2 years ago

Please attach a .reg file that I can use and reopen the issue

literally the second code sample... It may as well be the case that importing/exporting the .reg file autocorrects the value. You may need to install the LDPlayer app in order to get the problem in question. The main issue is not this specific misformatting, but the inability of the.wsf serialisier to deal with any kind malformed data at all and just stopping the translation mid-sentence. It's fine if data is dropped, but at least produce a proper data structure.

thank you.

kessler commented 2 years ago

Please attach a .reg file that I can use and reopen the issue

literally the second code sample... It may as well be the case that importing/exporting the .reg file autocorrects the value. You may need to install the LDPlayer app in order to get the problem in question. The main issue is not this specific misformatting, but the inability of the.wsf serialisier to deal with any kind malformed data at all and just stopping the translation mid-sentence. It's fine if data is dropped, but at least produce a proper data structure.

thank you.

I didn't realize it was in fact a reg snippet. I will try to use it. I can't, however, install any applications to test. Also, you can try and debug this yourself if you like. First, comment this line: https://github.com/ironSource/node-regedit/blob/master/vbs/regList.wsf#L28 using a single quote. Then try to run your program. If that doesn't yield anything meaningful you can run the vb script directly (open an elevated command window):

cscript regList.wsf HKCU\SOFTWARE\XuanZhi\LDPlayer

and see what happens, maybe paste the result here.

kessler commented 1 year ago

no activity