[winreg] support options and opened disposition in CreateKeyEx and OpenKey[Ex]
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 36k
- PR 合并指标
- PR 指标待抓取
描述
winreg.CreateKeyEx() should support the dwOptions and lpdwDisposition parameters of RegCreateKeyExW(), and winreg.OpenKey[Ex]() should support the ulOptions parameter of RegOpenKeyExW(). Also, the REG_LINK data type should be handled as a null-terminated Unicode string instead of as binary data.
The lpdwDisposition parameter can be supported indirectly by a new create_only parameter. If create_only is true and the opened disposition is REG_OPENED_EXISTING_KEY, close the handle and raise FileExistsError.
The dwOptions and ulOptions parameters can be supported as a new options parameter. Currently ulOptions is supported as a parameter named reserved, but RegOpenKeyExW() has been documented to support it since 2015. Unofficially, RegOpenKeyExW() first implemented support for REG_OPTION_OPEN_LINK in NT 4.0 (1996). The misnamed reserved parameter has to be retained for compatibility, but options should override it.
For example:
CreateKeyEx(key, sub_key, reserved=0, access=KEY_WRITE, options=0, create_only=False)
OpenKeyEx(key, sub_key, reserved=0, access=KEY_READ, options=0)
RegCreateKeyExW() supports the following options:
REG_OPTION_VOLATILE: create a dynamic key in memory that's never persisted to a hive file. This is useful for keys that should always be newly created for each session (e.g. "HKCU\Volatile Environment") or for test cases that shouldn't permanently modify a hive.REG_OPTION_CREATE_LINK: create a key symbolic link. The NT target path has to be set as aREG_LINKvalue named "SymbolicLinkValue". The registry API supports creating and modifying symbolic links, but deleting a symbolic link requires NTAPINtDeleteKey(KeyHandle).REG_OPTION_OPEN_LINK: open a symbolic link to modify its target path or to delete it viaNtDeleteKey().REG_OPTION_BACKUP_RESTORE: use backup semantics. If "SeBackupPrivilege" is enabled for the thread or process, then the open is granted read access and system security (SACL) access. If "SeRestorePrivilege" is enabled, then the open is granted write access, delete access, security access, and system security access. All access is granted if both privileges are enabled. If neither privilege is enabled, the call fails with access denied.REG_OPTION_DONT_VIRTUALIZE: disable open, read, and write virtualization for non-admin, interactive logons in legacy 32-bit processes. This isn't relevant to a 32-bit "python[w].exe" process or any 32-bit application that has a "requestedExecutionLevel" in its manifest.
RegOpenKeyExW() supports the following options:
REG_OPTION_OPEN_LINKREG_OPTION_BACKUP_RESTOREREG_OPTION_DONT_VIRTUALIZE
Linked PRs
- gh-129903
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 winreg.CreateKeyEx()、winreg.OpenKey() 和 winreg.OpenKeyEx() 入口点开始,将它们的参数与 RegCreateKeyExW() 和 RegOpenKeyExW() 进行比较。确认请求的选项、create_only 行为以及 REG_LINK 的 Unicode 处理,然后运行相关的 winreg 测试,以验证新键、现有键和符号链接的情况。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- operating-systems
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100