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

Write REG_BINARY Values from a Hex String #10

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions winregistry/winregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
QueryValueEx,
SetValueEx,
)

import struct
import binascii
from winregistry.consts import WinregType
from winregistry.models import RegEntry, RegKey
from winregistry.utils import get_access_key, parse_path
Expand Down Expand Up @@ -78,7 +79,7 @@ def read_entry(
host=self.host,
)

def write_entry(
def write_entry(
self,
reg_key: str,
name: str,
Expand All @@ -89,7 +90,19 @@ def write_entry(
if isinstance(reg_type, int):
reg_type = WinregType(reg_type)
handle = self._get_handler(reg_key, KEY_SET_VALUE, key_wow64_32key)
SetValueEx(handle, name, 0, reg_type.value, value)
if reg_type == WinregType.REG_DWORD:
new_value = int(value, 16)
elif reg_type == WinregType.REG_QWORD:
new_value = int(value, 16)
elif reg_type == WinregType.REG_BINARY:
if value[:2] == "0x" or value[:2] == "0X": # for Binary, we shall always use the format of hex string begin with 0x.
hex_string = value[2:]
else:
hex_string = value
new_value = bytes.fromhex(hex_string)
else:
new_value = value
SetValueEx(handle, name, 0, reg_type.value, new_value)

def delete_entry(
self,
Expand Down