吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 630|回复: 2
收起左侧

[求助] python ctypes调用winapi回调函数的问题

[复制链接]
pythonhnm 发表于 2023-11-19 13:31
之前看到开心expz的那个恶搞程序觉着挺好玩,就想用python试一下那个改msgbox位置的功能
[Python] 纯文本查看 复制代码
import time
import tkinter
import ctypes
import threading
x1 = 0
y1 = 0
tk = tkinter.Tk()
class RECT(ctypes.Structure):
    _fields_ = [("left", ctypes.c_long),
                ("top", ctypes.c_long),
                ("right", ctypes.c_long),
                ("bottom", ctypes.c_long)]
user32 = ctypes.windll.user32
kernel32 = ctypes.windll.kernel32
handle = user32.FindWindowW(None,'tk')
print(handle)
def xyx(lMsg,wParam,lParam):
    global x1,y1
    if lMsg == 5:
        rectmsg = RECT()
        user32.GetWindowRect(wParam,rectmsg)
        w = rectmsg.right - rectmsg.left
        h = rectmsg.bottom - rectmsg.top
        if x1 <= user32.GetSystemMetrics(0) - w:
            tmpa = x1
        else:
            tmpa = user32.GetSystemMetrics(0) - w
        if x1 >= 0:
            a = tmpa
        else:
            a = 0
        if y1 <= user32.GetSystemMetrics(1) - h - 40:
            tmpb = y1
        else:
            tmpb = user32.GetSystemMetrics(1) - h - 40
        if y1 >= 0:
            b = tmpb
        else:
            b = 0
        user32.SetWindowPos(wParam,0,a,b,b,a,21)
        x1 = x1 + 21
        y1 = y1 + 21
        user32.UnhookWindowsHookEx(hHook)
    return 0
def win(weizhi):
    HOOKPROC = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int)
    global hHook
    hHook = user32.SetWindowsHookExW(5,HOOKPROC(weizhi),user32.GetWindowLongW(handle,-6),kernel32.GetCurrentThreadId())
    user32.MessageBoxTimeoutW(0,'0x00C21FE5 指定引用的 0x00C21FE5 内存。因 0xc000000e 的错误状态而无法将请求的数据放入内存。\r\r要终止程序,请单击"确定"。','winlogon.exe - 应用程序错误',16|65536,0,5000)
    print('hhh')
for _ in range(10):
    time.sleep(1)
    thread = threading.Thread(target=win,args=(xyx,))
    thread.start()

但python运行会出大问题
不知道哪里有错。。。

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

sai609 发表于 2023-11-20 07:39
报错截图在哪里?
 楼主| pythonhnm 发表于 2023-11-20 21:23
sai609 发表于 2023-11-20 07:39
报错截图在哪里?

就是越界读的时候会出现的“该内存不能为read”
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-24 18:55

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表