-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathFunction.py
82 lines (72 loc) · 2.51 KB
/
Function.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#! /usr/bin/env python
# -*- coding: utf-8 -*-#
# -------------------------------------------------------------------------------
# Name: function.py
# Author: Xilyfe
# Date: 2023/1/2
# Description:
# -------------------------------------------------------------------------------
import pymem
import ctypes
from pymem.ptypes import RemotePointer
from Libs import WINDOWS_LIBRARY
init_Library = WINDOWS_LIBRARY()
class RECT(ctypes.Structure):
_fields_ = [
('Left', ctypes.c_long),
('Top', ctypes.c_long),
('Right', ctypes.c_long),
('Bottom', ctypes.c_long)]
def FindWindowPid(className, windowName):
'''
:func: 通过窗口取进程id
:param className: 类名称
:param windowName: 窗口名称
:return: 列表 [窗口句柄, 线程id, 进程id]
'''
hwnd = init_Library.findWindow(className, windowName)
pid = ctypes.wintypes.DWORD()
thre = init_Library.getThreadProcessId(hwnd, ctypes.byref(pid))
return (hwnd, thre, pid.value)
def GetWinRect(hwnd):
'''
:func: 通过句柄去窗口大小
:param hwnd: 句柄
:return: 列表 [左边界, 上边界, 右边界, 下边界]
'''
try:
f = ctypes.windll.dwmapi.DwmGetWindowAttribute
except WindowsError:
f = None
if f:
rect = ctypes.wintypes.RECT()
f(ctypes.wintypes.HWND(hwnd), ctypes.wintypes.DWORD(9), ctypes.byref(rect), ctypes.sizeof(rect))
return rect.left, rect.top, rect.right, rect.bottom
class WinTool():
def __init__(self, name):
'''
:param game: 进程名
'''
self.Game = pymem.Pymem(name)
def Get_moduladdr(self, dll):
'''
:func: 通过dll名称获取dll在窗口的内存地址
:param dll: dll名称
:return: dll内存地址
'''
modules = list(self.Game.list_modules())
for module in modules:
if module.name == dll:
return module.lpBaseOfDll
def GetPointerAddress(self, base, offsets):
'''
:param base: 内存基址
:param offsets: 偏移列表
:return: 内存地址
'''
remote_pointer = RemotePointer(self.Game.process_handle, base)
for offset in offsets:
if offset != offsets[-1]:
remote_pointer = RemotePointer(self.Game.process_handle, remote_pointer.value + offset)
else:
return remote_pointer.value + offset