forked from DFHack/dfhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.py
More file actions
135 lines (96 loc) · 4.19 KB
/
Copy pathprocess.py
File metadata and controls
135 lines (96 loc) · 4.19 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from ctypes import *
from dftypes import libdfhack
from util import check_pointer_cache
libdfhack.Process_readQuad.argtypes = [ c_void_p, c_uint, POINTER(c_ulong) ]
libdfhack.Process_writeQuad.argtypes = [ c_void_p, c_uint, c_ulong ]
libdfhack.Process_readDWord.argtypes = [ c_void_p, c_uint, POINTER(c_uint) ]
libdfhack.Process_writeDWord.argtypes = [ c_void_p, c_uint, c_uint ]
libdfhack.Process_readWord.argtypes = [ c_void_p, c_uint, POINTER(c_ushort) ]
libdfhack.Process_writeWord.argtypes = [ c_void_p, c_uint, c_ushort ]
libdfhack.Process_readByte.argtypes = [ c_void_p, c_uint, POINTER(c_ubyte) ]
libdfhack.Process_writeByte.argtypes = [ c_void_p, c_uint, c_ubyte ]
libdfhack.Process_readFloat.argtypes = [ c_void_p, c_uint, POINTER(c_float) ]
libdfhack.Process_read.argtypes = [ c_void_p, c_uint, c_uint ]
libdfhack.Process_read.restype = c_void_p
libdfhack.Process_write.argtypes = [ c_void_p, c_uint, c_uint, POINTER(c_ubyte) ]
libdfhack.Process_getThreadIDs.restype = c_void_p
class Process(object):
def __init__(self, ptr):
self._p_ptr = ptr
def attach(self):
return libdfhack.Process_attach(self._p_ptr) > 0
def detach(self):
return libdfhack.Process_detach(self._p_ptr) > 0
def suspend(self):
return libdfhack.Process_suspend(self._p_ptr) > 0
def async_suspend(self):
return libdfhack.Process_asyncSuspend(self._p_ptr) > 0
def resume(self):
return libdfhack.Process_resume(self._p_ptr) > 0
def force_resume(self):
return libdfhack.Process_forceresume(self._p_ptr) > 0
def read_quad(self, address):
q = c_ulong(0)
if libdfhack.Process_readQuad(self._p_ptr, address, byref(q)) > 0:
return long(q.value)
else:
return -1
def write_quad(self, address, value):
return libdfhack.Process_writeQuad(self._p_ptr, address, value) > 0
def read_dword(self, address):
d = c_uint(0)
if libdfhack.Process_readDWord(self._p_ptr, address, byref(d)) > 0:
return int(d.value)
else:
return -1
def write_dword(self, address, value):
return libdfhack.Process_writeDWord(self._p_ptr, address, value) > 0
def read_word(self, address):
s = c_ushort(0)
if libdfhack.Process_readWord(self._p_ptr, address, byref(s)) > 0:
return int(s.value)
else:
return -1
def write_word(self, address, value):
return libdfhack.Process_writeWord(self._p_ptr, address, value) > 0
def read_byte(self, address):
b = c_ubyte(0)
if libdfhack.Process_readByte(self._p_ptr, address, byref(b)) > 0:
return int(b.value)
else:
return -1
def write_byte(self, address, value):
return libdfhack.Process_writeByte(self._p_ptr, address, value) > 0
def read_float(self, address):
f = c_float(0)
if libdfhack.Process_readFloat(self._p_ptr, address, byref(f)) > 0:
return float(f.value)
else:
return -1
def read(self, address, length):
return check_pointer_cache(libdfhack.Process_read(self._p_ptr, address, length))
def write(self, address, length, buffer):
libdfhack.Process_write(self._p_ptr, address, length, byref(buffer))
def get_thread_ids(self):
return check_pointer_cache(libdfhack.Process_getThreadIDs(self._p_ptr))
def set_and_wait(self, state):
return libdfhack.Process_SetAndWait(self._p_ptr, state) > 0
@property
def is_suspended(self):
return libdfhack.Process_isSuspended(self._p_ptr) > 0
@property
def is_attached(self):
return libdfhack.Process_isAttached(self._p_ptr) > 0
@property
def is_identified(self):
return libdfhack.Process_isIdentified(self._p_ptr) > 0
@property
def is_snapshot(self):
return libdfhack.Process_isSnapshot(self._p_ptr) > 0
@property
def pid(self):
p = c_int(0)
if libdfhack.Process_getPID(self._p_ptr, byref(p)) > 0:
return int(p.value)
else:
return -1