Пример #1
0
def inject_py(pid: int, python_code: AnyStr) -> None:
    if isinstance(python_code, str):
        python_code = python_code.encode()
    copied_lib = DATA_DIR / f'{urandom(3).hex()}-{python_code.hex()}'
    copy(injection_lib_path, copied_lib)
    inject(pid, str(copied_lib))
    unlink(copied_lib)
Пример #2
0
def test_inject():
    with Popen([sys.executable, '-c', 'while True: pass'],
               stdout=PIPE) as process:
        try:
            time.sleep(TIME_TO_WIT_FOR_PROCESS_TO_INIT)
            inject(process.pid, INJECTION_LIB_PATH)
            time.sleep(TIME_TO_WIT_FOR_INJECTION_TO_RUN)
            assert process.stdout.read() == STRING_PRINTED_FROM_LIB
        finally:
            process.kill()
Пример #3
0
import sys
import psutil
from pyinjector import inject

if len(sys.argv) != 3:
    print("Usage: python inject.py <process-name> <shared-library>")
    exit()

_, process_name, shared_library = sys.argv

for process in psutil.process_iter():
    if process.name() == process_name:
        print(
            f"Found {process_name} - injecting {shared_library} into PID {process.pid}"
        )
        inject(process.pid, shared_library)
        print("Injected successfully")
        exit()

print(f"Unable to find process named {process_name}")
Пример #4
0
def main(args: Optional[List[str]] = None) -> None:
    parsed_args = parse_args(args)
    inject(parsed_args.pid, parsed_args.library_path)
Пример #5
0
def test_inject_no_such_lib():
    with raises(LibraryNotFoundException):
        inject(-1, 'nosuchpath.so')
Пример #6
0
from pathlib import Path

import psutil

process = [
    proc for proc in psutil.process_iter() if proc.name() == "GeometryDash.exe"
][0]

from pyinjector import inject

inject(process.pid, str(Path(__file__).absolute().parent / 'wsXbot.dll'))