Skip to content

Commit c48d60b

Browse files
committed
Fixed pyproject.toml
1 parent d048c27 commit c48d60b

27 files changed

+1011
-386
lines changed

build.py

+6-37
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,9 @@
1-
from distutils.command.build_ext import build_ext
2-
from distutils.core import Distribution
3-
from distutils.core import Extension
4-
from distutils.errors import CCompilerError
5-
from distutils.errors import DistutilsExecError
6-
from distutils.errors import DistutilsPlatformError
7-
8-
ext_modules = [
9-
Extension("memscan.memscan",
10-
sources=["./memscan/memscan.c"],
11-
),
12-
]
13-
14-
15-
class BuildFailed(Exception):
16-
pass
17-
18-
19-
class ExtBuilder(build_ext):
20-
21-
def run(self):
22-
try:
23-
build_ext.run(self)
24-
except (DistutilsPlatformError, FileNotFoundError):
25-
raise BuildFailed('File not found. Could not compile C extension.')
26-
27-
def build_extension(self, ext):
28-
try:
29-
build_ext.build_extension(self, ext)
30-
except (CCompilerError, DistutilsExecError, DistutilsPlatformError, ValueError):
31-
raise BuildFailed('Could not compile C extension.')
1+
from setuptools.extension import Extension
322

3+
custom_extension = Extension(
4+
"memmod.memscan",
5+
sources=["memmod/memscan.c"],
6+
)
337

348
def build(setup_kwargs):
35-
"""
36-
This function is mandatory in order to build the extensions.
37-
"""
38-
setup_kwargs.update(
39-
{"ext_modules": ext_modules, "cmdclass": {"build_ext": ExtBuilder}}
40-
)
9+
setup_kwargs.update({ "ext_modules": [custom_extension], })

examples/assaultcube.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from memmod import Process
2+
3+
import struct
4+
import sys
5+
6+
proc = Process(name="native_client")
7+
base = proc.find_module(proc.name)
8+
assert base != None, "Failed to locate base module!"
9+
heap = proc.find_module("heap")
10+
assert heap != None, "Failed to locate heap module!"
11+
12+
entity_list_addr = proc.resolve_pointer_chain(base.start + 0x1c4540)
13+
print("Entity list addr:", hex(entity_list_addr))
14+
15+
player = 0
16+
for i in range(5):
17+
entity_addr = proc.resolve_pointer_chain(entity_list_addr + i * 8)
18+
name = proc.read(entity_addr + 0x219, 20)
19+
if name[0] == 0:
20+
continue
21+
dead = int.from_bytes(proc.read(entity_addr + 0x7a, 1), sys.byteorder)
22+
23+
print(name.decode(), hex(entity_addr), dead)
24+
print(struct.unpack("i", proc.read(entity_addr + 0x6c, 4)))
25+
print(struct.unpack("d", proc.read(entity_addr + 0x10, 8)))
26+
print(struct.unpack("H", proc.read(entity_addr + 0x67, 2)))
27+
print(struct.unpack("H", proc.read(entity_addr + 0x69, 2)))
28+
29+
"""
30+
x = bytes(0x350)
31+
while True:
32+
_x = proc.read(player, 0x350)
33+
for i in range(0x350):
34+
if x[i] is not _x[i]:
35+
print(i, x[i])
36+
x = _x
37+
"""

findcppvector.py renamed to examples/findcppvector.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def list_to_dict(pointers: list[ScanResult]) -> dict[int, int]:
3636
continue
3737

3838
size = int(size / 8)
39-
if not(size >= 200 and size <= 300):
39+
if not(size > 100 and size < 300):
4040
continue
4141

4242
valid = True

examples/key.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from memmod import Process
2+
from Xlib import XK
3+
4+
from time import sleep
5+
6+
proc = Process(name = "firefox")
7+
win = proc.get_x11_window()[0]
8+
9+
while True:
10+
proc.send_key(win, XK.string_to_keysym("A"))
11+
sleep(1)

examples/search_func.py

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
from dataclasses import dataclass
2+
from memmod import Process, Module
3+
from capstone import Cs, CS_ARCH_X86, CS_MODE_64, CsInsn
4+
5+
import cxxfilt
6+
import sys
7+
8+
proc = Process(name=sys.argv[1])
9+
base = proc.find_module(proc.name)
10+
base_proc = proc.find_module(proc.name, mode='r-xp')
11+
assert base != None, "Failed to load base module!"
12+
assert base_proc != None, "Failed to load base module!"
13+
14+
symbols = base.get_symbols()
15+
symbols_f = list(filter(lambda x: x.entry['st_info']['type'] == 'STT_FUNC' and x.entry['st_value'] != 0, symbols))
16+
symbols_f = list(reversed(sorted(symbols_f, key=lambda x: x.entry['st_value'])))
17+
symbols = list(filter(lambda x: x.entry['st_info']['type'] == 'STT_OBJECT', symbols))
18+
19+
20+
binary = proc.read(base_proc.start, base_proc.size)
21+
md = Cs(CS_ARCH_X86, CS_MODE_64)
22+
23+
func = {}
24+
25+
def get_function_name(address) -> str:
26+
for f in symbols_f:
27+
if f.entry['st_value'] < address - base.start:
28+
return cxxfilt.demangle(f.name)
29+
return ""
30+
31+
32+
"""
33+
for instruction in md.disasm(binary, base_proc.start):
34+
if instruction.mnemonic != 'call':
35+
continue
36+
if '[' not in instruction.op_str:
37+
continue
38+
if 'rip' not in instruction.op_str:
39+
continue
40+
if '+' not in instruction.op_str:
41+
continue
42+
43+
offset = int(instruction.op_str[instruction.op_str.find('+')+1:instruction.op_str.find(']')], 16)
44+
rip = instruction.address+instruction.size
45+
got = rip + offset
46+
47+
address = int.from_bytes(proc.read(got, 8), sys.byteorder)
48+
if address not in func:
49+
mod = proc.find_module_with_address(address)
50+
51+
if mod == None:
52+
continue
53+
54+
func[address] = {
55+
"module": mod,
56+
"got": got,
57+
"address": address,
58+
"offset": address - mod.start,
59+
"calls": [ instruction.address ]
60+
}
61+
else:
62+
func[address]["calls"].append(instruction.address)
63+
64+
for f in func.values():
65+
print(f["module"].path, '+', hex(f["offset"]), hex(f["address"]), len(f["calls"]))
66+
"""
67+
68+
69+
for instruction in md.disasm(binary, base_proc.start):
70+
if instruction.mnemonic != 'call':
71+
continue
72+
73+
op_str = instruction.op_str
74+
if '[' in op_str:
75+
continue
76+
if '+' in op_str:
77+
continue
78+
if not op_str[0].isdigit():
79+
continue
80+
81+
address = int(op_str, 16)
82+
83+
if not base_proc.contains_address(address):
84+
continue
85+
86+
if address not in func:
87+
func[address] = {
88+
"address": address,
89+
"offset": address - base_proc.start,
90+
"calls": [ instruction.address ]
91+
}
92+
else:
93+
func[address]["calls"].append(instruction.address)
94+
95+
for f in func.values():
96+
print("%s+%x (%x) %d %s" % (base_proc.path, f["offset"], f["address"], len(f["calls"]), get_function_name(f["address"])))
97+
print(len(func))
98+
99+
# /usr/bin/supertux2+1b4930 (5573d99e4930) 6 Player::set_on_ground(bool)
File renamed without changes.

examples/supertux.py

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
for i, r in enumerate(results):
1515
print(i, r.address, hex(r.value))
1616

17-
sys.exit()
1817

1918
# Hello World
2019
puts = proc.get_libc_function("puts")

gui/extensions/test.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from gi.repository import Adw, Gio, Gtk, Gdk
2+
from pathlib import Path
3+
4+
from memmod import Process
5+
6+
info = "A small test script to check if this is working"
7+
name = "Test"
8+
9+
10+
BASE_DIR = Path(__file__).resolve().parent
11+
@Gtk.Template(filename=str(BASE_DIR.joinpath('test.ui')))
12+
class Test(Gtk.Box):
13+
__gtype_name__ = 'Test'
14+
15+
liststore = Gtk.Template.Child()
16+
17+
def __init__(self, proc: Process, **kwargs):
18+
super().__init__(**kwargs)
19+
20+
for m in proc.modules:
21+
self.liststore.append(["%x" % m.start, "%x" % m.end, m.mode, "%x" % m.offset, "%d:%d" % (m.major, m.minor), m.inode, m.path])
22+
23+
def init():
24+
print("hello")
25+
26+
def get_widget(proc: Process):
27+
return Test(proc)

gui/extensions/test.ui

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<interface>
3+
<requires lib="gtk" version="4.0"/>
4+
<requires lib="adw" version="1.0"/>
5+
6+
7+
<object class="GtkListStore" id="liststore">
8+
<columns>
9+
<column type="gchararray"/>
10+
<column type="gchararray"/>
11+
12+
<column type="gchararray"/>
13+
14+
<column type="gchararray"/>
15+
16+
<column type="gchararray"/>
17+
18+
<column type="gint"/>
19+
20+
<column type="gchararray"/>
21+
</columns>
22+
</object>
23+
24+
25+
<template class="Test" parent="GtkBox">
26+
<property name="orientation">vertical</property>
27+
28+
29+
<child>
30+
31+
<object class="GtkScrolledWindow">
32+
<property name="has-frame">1</property>
33+
<property name="hexpand">1</property>
34+
<property name="vexpand">1</property>
35+
<child>
36+
<object class="GtkTreeView" id="view">
37+
<property name="model">liststore</property>
38+
<signal name="row-activated" handler="action_open"/>
39+
<child>
40+
<object class="GtkTreeViewColumn">
41+
<property name="sizing">autosize</property>
42+
<property name="title">Start</property>
43+
<child>
44+
<object class="GtkCellRendererText"/>
45+
<attributes>
46+
<attribute name="text">0</attribute>
47+
</attributes>
48+
</child>
49+
</object>
50+
</child>
51+
<child>
52+
<object class="GtkTreeViewColumn">
53+
<property name="sizing">autosize</property>
54+
<property name="title">End</property>
55+
<child>
56+
<object class="GtkCellRendererText"/>
57+
<attributes>
58+
<attribute name="text">1</attribute>
59+
</attributes>
60+
</child>
61+
</object>
62+
</child>
63+
<child>
64+
<object class="GtkTreeViewColumn">
65+
<property name="sizing">autosize</property>
66+
<property name="title">Mode</property>
67+
<child>
68+
<object class="GtkCellRendererText"/>
69+
<attributes>
70+
<attribute name="text">2</attribute>
71+
</attributes>
72+
</child>
73+
</object>
74+
</child>
75+
<child>
76+
<object class="GtkTreeViewColumn">
77+
<property name="sizing">autosize</property>
78+
<property name="title">Offset</property>
79+
<child>
80+
<object class="GtkCellRendererText"/>
81+
<attributes>
82+
<attribute name="text">3</attribute>
83+
</attributes>
84+
</child>
85+
</object>
86+
</child>
87+
<child>
88+
<object class="GtkTreeViewColumn">
89+
<property name="sizing">autosize</property>
90+
<property name="title">major:minor</property>
91+
<child>
92+
<object class="GtkCellRendererText"/>
93+
<attributes>
94+
<attribute name="text">4</attribute>
95+
</attributes>
96+
</child>
97+
</object>
98+
</child>
99+
<child>
100+
<object class="GtkTreeViewColumn">
101+
<property name="sizing">autosize</property>
102+
<property name="title">inode</property>
103+
<child>
104+
<object class="GtkCellRendererText"/>
105+
<attributes>
106+
<attribute name="text">5</attribute>
107+
</attributes>
108+
</child>
109+
</object>
110+
</child>
111+
<child>
112+
<object class="GtkTreeViewColumn">
113+
<property name="sizing">autosize</property>
114+
<property name="title">path</property>
115+
<child>
116+
<object class="GtkCellRendererText"/>
117+
<attributes>
118+
<attribute name="text">6</attribute>
119+
</attributes>
120+
</child>
121+
</object>
122+
</child>
123+
</object>
124+
125+
</child>
126+
</object>
127+
</child>
128+
129+
130+
</template>
131+
</interface>

0 commit comments

Comments
 (0)