test_hook.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:PythonForWindows 作者: hakril 项目源码 文件源码
def test_self_iat_hook_fail_return():
    """Test hook fail in single(self) thread"""
    pythondll_mod = [m for m in windows.current_process.peb.modules if m.name.startswith("python") and m.name.endswith(".dll")][0]
    RegOpenKeyExA = [n for n in pythondll_mod.pe.imports['advapi32.dll'] if n.name == "RegOpenKeyExA"][0]

    @windows.hooks.RegOpenKeyExACallback
    def open_reg_hook_fail(hKey, lpSubKey, ulOptions, samDesired, phkResult, real_function):
        return 0x11223344

    x = RegOpenKeyExA.set_hook(open_reg_hook_fail)
    import _winreg
    open_args = (0x12345678, "MY_KEY_VALUE")
    with pytest.raises(WindowsError) as ar:
        _winreg.OpenKey(*open_args)
    assert ar.value.winerror == 0x11223344
    x.disable()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号