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

Creating string values results in malformed data that certain APIs cannot read #21

Closed
dancarrollg opened this issue Sep 12, 2024 · 0 comments · Fixed by #22
Closed

Creating string values results in malformed data that certain APIs cannot read #21

dancarrollg opened this issue Sep 12, 2024 · 0 comments · Fixed by #22

Comments

@dancarrollg
Copy link
Contributor

I noticed an issue where creating a string registry value results in malformed data being written to the Windows registry

Example code using win32_registry to create a value:

RegistryKey? key;

try {
  key = Registry.openPath(RegistryHive.localMachine,
            path: r'SOFTWARE\TestApp', desiredAccessRights: AccessRights.writeOnly);
  key.createValue(RegistryValue(
          'MyValue', RegistryValueType.string, 'ThisIsAValue'));
} finally {
  key?.close();
}

This results in the following binary data getting created:
image

Each character is encoded as two bytes. However, the final null-termination character (required for REG_SZ value types) is only encoded as a single byte.

If you click ok within regedit's binary editor, and then reopen it, you can see that the value has been fixed (the final null termination is encoded with two bytes):
image

I've noticed that some API and tooling is robust to this slightly malformed data. For example, regedit itself is robust to it. Also, the .NET Registry APIs seem to read the value correctly. However, the Win32 CRegKey::QueryStringValue API returns an error when reading the value.

dancarrollg added a commit to dancarrollg/win32_registry that referenced this issue Sep 12, 2024
Fix to null-termination at the end of string values. Fixes halildurmus#21
halildurmus pushed a commit that referenced this issue Sep 12, 2024
Fix to null-termination at the end of string values. Fixes #21
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

Successfully merging a pull request may close this issue.

1 participant