- http://timgolden.me.uk/pywin32-docs/contents.html
- https://docs.python.org/3/library/ctypes.html#ctypes.WinDLL
安装 pywin32
pip install pywin32 -i https://pypi.tuna.tsinghua.edu.cn/simple
使用
main.py
import win32api
import win32com.client
win32api.MessageBox(0, "body", "caption", 0)
speack = win32com.client.Dispatch("SAPI.SpVoice")
speack.Speak("abc")
λ python main.py
外部读写内存
from ctypes import *
PROCESS_ALL_ACCESS = 2097151
kernel32 = windll.kernel32
hProcess = kernel32.OpenProcess(PROCESS_ALL_ACCESS, False, 10256)
print("hProcess: ", hProcess)
if hProcess == 0:
print("OpenProcess error.")
exit()
val = c_uint32(0)
if kernel32.ReadProcessMemory(hProcess, 0x4B3724, byref(val), sizeof(val), 0) == 0:
print("ReadProcessMemory error.")
exit()
print("Current HP: ", val.value)
newval = c_uint32(100)
if kernel32.WriteProcessMemory(hProcess, 0x4B3724, byref(newval), sizeof(newval), 0) == 0:
print("WriteProcessMemory error.")
exit()
if kernel32.ReadProcessMemory(hProcess, 0x4B3724, byref(val), sizeof(val), 0) == 0:
print("ReadProcessMemory error.")
exit()
print("New HP: ", newval.value)
kernel32.CloseHandle(hProcess)
λ python main.py
hProcess: 496
Current HP: 42
New HP: 100