py 使用win32 api

安装 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
posted @ 2020-09-03 20:15  Ajanuw  阅读(624)  评论(0编辑  收藏  举报