Skip to content

Commit

Permalink
Adapt to rtfd
Browse files Browse the repository at this point in the history
  • Loading branch information
in1nit1t committed Jan 20, 2023
1 parent 07ac9ed commit a077e99
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 51 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
html_static_path = ['_static']

# -- autodoc settings --------------------------------------------------------
autodoc_mock_imports = ['win32process']
autodoc_mock_imports = ['win32process', 'ctypes']
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ build-backend = "setuptools.build_meta"

[project]
name = "uniref"
version = "0.1.0"
version = "0.1.1"
authors = [
{ name="in1t", email="[email protected]" },
]
description = "Unity reflection framework"
readme = "README.en.md"
readme = "README.md"
requires-python = ">=3.7"
license = {file = "LICENSE"}
keywords = ["Unity", "mono", "il2cpp", "reflection", "patch"]
Expand Down
101 changes: 53 additions & 48 deletions src/uniref/util/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,58 +89,63 @@ def scan_uint64(self, value: int, va_start: int = 0, va_end: int = -1) -> List[i


class CMemoryScanner:
_util = cdll.LoadLibrary(str(Path(os.path.abspath(__file__)).parent.parent / "bin/win/util64.dll"))

_SearchChar = _util.SearchChar
_SearchChar.argtypes = [c_uint32, c_byte, c_bool, c_uint64, c_uint64, c_void_p]
_SearchChar.restype = c_uint64
def __init__(self, pid: int, bit_long: int) -> None:
self._process_id = pid
self._bit_long = bit_long
self._injector = WinInjector()
self._init_proc()

def _init_proc(self):
_util = cdll.LoadLibrary(str(Path(os.path.abspath(__file__)).parent.parent / "bin/win/util64.dll"))

_SearchUChar = _util.SearchUChar
_SearchUChar.argtypes = [c_uint32, c_ubyte, c_bool, c_uint64, c_uint64, c_void_p]
_SearchUChar.restype = c_uint64
self._SearchChar = _util.SearchChar
self._SearchChar.argtypes = [c_uint32, c_byte, c_bool, c_uint64, c_uint64, c_void_p]
self._SearchChar.restype = c_uint64

_SearchInt16 = _util.SearchInt16
_SearchInt16.argtypes = [c_uint32, c_int16, c_bool, c_uint64, c_uint64, c_void_p]
_SearchInt16.restype = c_uint64
self._SearchUChar = _util.SearchUChar
self._SearchUChar.argtypes = [c_uint32, c_ubyte, c_bool, c_uint64, c_uint64, c_void_p]
self._SearchUChar.restype = c_uint64

_SearchUInt16 = _util.SearchUInt16
_SearchUInt16.argtypes = [c_uint32, c_uint16, c_bool, c_uint64, c_uint64, c_void_p]
_SearchUInt16.restype = c_uint64
self._SearchInt16 = _util.SearchInt16
self._SearchInt16.argtypes = [c_uint32, c_int16, c_bool, c_uint64, c_uint64, c_void_p]
self._SearchInt16.restype = c_uint64

_SearchInt32 = _util.SearchInt32
_SearchInt32.argtypes = [c_uint32, c_int32, c_bool, c_uint64, c_uint64, c_void_p]
_SearchInt32.restype = c_uint64
self._SearchUInt16 = _util.SearchUInt16
self._SearchUInt16.argtypes = [c_uint32, c_uint16, c_bool, c_uint64, c_uint64, c_void_p]
self._SearchUInt16.restype = c_uint64

_SearchUInt32 = _util.SearchUInt32
_SearchUInt32.argtypes = [c_uint32, c_uint32, c_bool, c_uint64, c_uint64, c_void_p]
_SearchUInt32.restype = c_uint64
self._SearchInt32 = _util.SearchInt32
self._SearchInt32.argtypes = [c_uint32, c_int32, c_bool, c_uint64, c_uint64, c_void_p]
self._SearchInt32.restype = c_uint64

_SearchInt64 = _util.SearchInt64
_SearchInt64.argtypes = [c_uint32, c_int64, c_bool, c_uint64, c_uint64, c_void_p]
_SearchInt64.restype = c_uint64
self._SearchUInt32 = _util.SearchUInt32
self._SearchUInt32.argtypes = [c_uint32, c_uint32, c_bool, c_uint64, c_uint64, c_void_p]
self._SearchUInt32.restype = c_uint64

_SearchUInt64 = _util.SearchUInt64
_SearchUInt64.argtypes = [c_uint32, c_uint64, c_bool, c_uint64, c_uint64, c_void_p]
_SearchUInt64.restype = c_uint64
self._SearchInt64 = _util.SearchInt64
self._SearchInt64.argtypes = [c_uint32, c_int64, c_bool, c_uint64, c_uint64, c_void_p]
self._SearchInt64.restype = c_uint64

_SearchFloat = _util.SearchFloat
_SearchFloat.argtypes = [c_uint32, c_float, c_bool, c_uint64, c_uint64, c_void_p]
_SearchFloat.restype = c_uint64
self._SearchUInt64 = _util.SearchUInt64
self._SearchUInt64.argtypes = [c_uint32, c_uint64, c_bool, c_uint64, c_uint64, c_void_p]
self._SearchUInt64.restype = c_uint64

_SearchDouble = _util.SearchDouble
_SearchDouble.argtypes = [c_uint32, c_double, c_bool, c_uint64, c_uint64, c_void_p]
_SearchDouble.restype = c_uint64
self._SearchFloat = _util.SearchFloat
self._SearchFloat.argtypes = [c_uint32, c_float, c_bool, c_uint64, c_uint64, c_void_p]
self._SearchFloat.restype = c_uint64

_ResFree = _util.ResFree
_ResFree.argtypes = [c_void_p]
self._SearchDouble = _util.SearchDouble
self._SearchDouble.argtypes = [c_uint32, c_double, c_bool, c_uint64, c_uint64, c_void_p]
self._SearchDouble.restype = c_uint64

def __init__(self, pid: int, bit_long: int) -> None:
self._process_id = pid
self._bit_long = bit_long
self._injector = WinInjector()
self._ResFree = _util.ResFree
self._ResFree.argtypes = [c_void_p]

self._util = _util

def _res_free(self, ptr: int):
CMemoryScanner._ResFree(ptr)
self._ResFree(ptr)

def _do_scan(self, elem_type: int, target: Any, writeable: bool, va_start: int = 0, va_end: int = -1):
if va_end <= 0:
Expand All @@ -151,25 +156,25 @@ def _do_scan(self, elem_type: int, target: Any, writeable: bool, va_start: int =
raise ValueError("va_start > va_end")

if elem_type == TYPE_CHAR:
scan_func = CMemoryScanner._SearchChar
scan_func = self._SearchChar
elif elem_type == TYPE_UCHAR:
scan_func = CMemoryScanner._SearchUChar
scan_func = self._SearchUChar
elif elem_type == TYPE_INT16:
scan_func = CMemoryScanner._SearchInt16
scan_func = self._SearchInt16
elif elem_type == TYPE_UINT16:
scan_func = CMemoryScanner._SearchUInt16
scan_func = self._SearchUInt16
elif elem_type == TYPE_INT32:
scan_func = CMemoryScanner._SearchInt32
scan_func = self._SearchInt32
elif elem_type == TYPE_UINT32:
scan_func = CMemoryScanner._SearchUInt32
scan_func = self._SearchUInt32
elif elem_type == TYPE_INT64:
scan_func = CMemoryScanner._SearchInt64
scan_func = self._SearchInt64
elif elem_type == TYPE_UINT64:
scan_func = CMemoryScanner._SearchUInt64
scan_func = self._SearchUInt64
elif elem_type == TYPE_FLOAT:
scan_func = CMemoryScanner._SearchFloat
scan_func = self._SearchFloat
elif elem_type == TYPE_DOUBLE:
scan_func = CMemoryScanner._SearchDouble
scan_func = self._SearchDouble
else:
raise ValueError("Element type unsupported")
res = c_void_p()
Expand Down
1 change: 1 addition & 0 deletions src/uniref/util/winapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from functools import wraps
from platform import architecture

from ctypes import windll
from uniref.define.struct import *
from uniref.define.constant import *

Expand Down

0 comments on commit a077e99

Please sign in to comment.