Skip to content

Commit 64706df

Browse files
committed
fix typing issues, run black
1 parent 92c00ac commit 64706df

File tree

8 files changed

+48
-42
lines changed

8 files changed

+48
-42
lines changed

memobj/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@
33
from .allocation import Allocation, Allocator
44
from .object import MemoryObject
55
from .process import Process, WindowsProcess
6-
from .property import *
6+
from . import property
77

88
logger = logging.getLogger(__name__)
99
logger.addHandler(logging.NullHandler())
1010

1111
del logging
1212
del logger
13+
14+
15+
__all__ = [
16+
"Allocation",
17+
"Allocator",
18+
"MemoryObject",
19+
"Process",
20+
"WindowsProcess",
21+
"property",
22+
]

memobj/hook.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@
66
from collections.abc import Callable
77

88
import regex
9-
from iced_x86 import (BlockEncoder, Code, Decoder, FlowControl, Instruction,
10-
MemoryOperand, Register)
9+
from iced_x86 import (
10+
BlockEncoder,
11+
Code,
12+
Decoder,
13+
FlowControl,
14+
Instruction,
15+
MemoryOperand,
16+
Register,
17+
)
1118
from iced_x86._iced_x86_py import Register as RegisterType
1219

1320
from memobj.allocation import Allocation, Allocator

memobj/process/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
from .module import Module
33
from .windows.module import WindowsModule
44
from .windows.process import WindowsProcess
5+
6+
7+
__all__ = ["Process", "Module", "WindowsModule", "WindowsProcess"]

memobj/process/windows/module.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"""
1818

1919
import ctypes
20-
from typing import TYPE_CHECKING, Iterator, Self
20+
from typing import TYPE_CHECKING, Self
21+
from collections.abc import Iterator
2122

2223
from memobj.process import Module
2324

@@ -120,7 +121,7 @@ def get_all_modules(cls, process: "WindowsProcess") -> list[Self]:
120121
process=process,
121122
)
122123
)
123-
124+
124125
return modules
125126

126127
def get_symbol_with_name(self, name: str) -> int:

memobj/process/windows/process.py

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,31 @@
33
import functools
44
import typing
55
from pathlib import Path
6-
from typing import Self, Union
6+
from typing import Self
77

88
import regex
99

1010
from memobj.allocation import Allocator
1111
from memobj.process import Process
1212
from memobj.process.windows.module import WindowsModule
13-
from memobj.process.windows.utils import \
14-
WindowsMemoryProtection # TODO: what was this going to be used for?
15-
from memobj.process.windows.utils import (LUID, LUID_AND_ATTRIBUTES,
16-
PROCESSENTRY32, TOKEN_PRIVILEGES,
17-
CheckWindowsOsError,
18-
SingleLUIDAndAttributes,
19-
WindowsMemoryBasicInformation,
20-
WindowsModuleInfo)
13+
from memobj.process.windows.utils import (
14+
WindowsMemoryProtection,
15+
) # TODO: what was this going to be used for?
16+
from memobj.process.windows.utils import (
17+
LUID,
18+
LUID_AND_ATTRIBUTES,
19+
PROCESSENTRY32,
20+
TOKEN_PRIVILEGES,
21+
CheckWindowsOsError,
22+
SingleLUIDAndAttributes,
23+
WindowsMemoryBasicInformation,
24+
)
2125

2226

23-
# TODO: update everything that uses modules to use the new WindowsModule
2427
class WindowsProcess(Process):
2528
def __init__(self, process_handle: int):
2629
self.process_handle = process_handle
2730

28-
# TODO: why are we getting debug privileges for our own process?
2931
@staticmethod
3032
def _get_debug_privileges():
3133
with CheckWindowsOsError():
@@ -411,25 +413,6 @@ def get_modules(
411413
else:
412414
return WindowsModule.get_all_modules(self)
413415

414-
# def get_module_name(self, module: WindowsModuleInfo) -> str:
415-
# with CheckWindowsOsError():
416-
# # https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getmodulebasenamew
417-
# # I just assume MAX_PATH is good enough
418-
# name_buffer = ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH)
419-
420-
# success = ctypes.windll.psapi.GetModuleBaseNameW(
421-
# self.process_handle,
422-
# ctypes.c_void_p(module.lpBaseOfDll),
423-
# ctypes.byref(name_buffer),
424-
# ctypes.wintypes.MAX_PATH,
425-
# )
426-
427-
# if success == 0:
428-
# raise ValueError(f"GetModuleBaseNameW failed for {module}")
429-
430-
# return name_buffer.value
431-
432-
# TODO: return module here
433416
def get_module_named(self, name: str) -> WindowsModule:
434417
return WindowsModule.from_name(self, name)
435418

memobj/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import struct
33
import time
44
from enum import Enum
5-
from typing import Callable, Generic, TypeVar
5+
from typing import Generic, TypeVar
6+
from collections.abc import Callable
67

78
# TODO: remove when dropping 3.11 support
89
T = TypeVar("T")
@@ -14,6 +15,7 @@ class ValueWaiter(Generic[T]):
1415
Args:
1516
callback (Callable[[], T]): the callable to wait for changes from
1617
"""
18+
1719
def __init__(self, callback: Callable[[], T]):
1820
self.callback = callback
1921

tests/conftest.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
from memobj import Process, WindowsProcess
77

88

9-
def pytest_addoption(parser):
10-
parser.addoption("--run-manual", action="store_true", default=False, help="run manual tests")
11-
12-
139
@pytest.fixture(scope="session")
1410
def process() -> Process:
1511
"""

tests/manual/test_dll_injection.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88

99

1010
def test_dll_injection():
11-
dll_path = (Path(__file__).parent / "test_inject/target/release/test_inject.dll").resolve()
12-
exe_path = (Path(__file__).parent / "test_inject/target/release/inject_target.exe").resolve()
11+
dll_path = (
12+
Path(__file__).parent / "test_inject/target/release/test_inject.dll"
13+
).resolve()
14+
exe_path = (
15+
Path(__file__).parent / "test_inject/target/release/inject_target.exe"
16+
).resolve()
1317

1418
if not dll_path.exists():
1519
pytest.skip(f"Test DLL not found at {dll_path}")

0 commit comments

Comments
 (0)