Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-109: Fix issue with getting module handle from injected dlls #152

Merged
merged 1 commit into from
Nov 1, 2024

Conversation

monkeyman192
Copy link
Contributor

@monkeyman192 monkeyman192 commented Nov 1, 2024

closes #109

Tested this by using the following code:

import os.path as op
import os
import subprocess
import sys
import pymem
import pymem.process

# Python version to inject
PYTHON_VERSION = "39"
PYTHON_VERSION2 = "310"

_ver = sys.version_info
running_python_version = f"{_ver.major}{_ver.minor}"

notepad = subprocess.Popen(['notepad.exe'])
pm = pymem.Pymem('notepad.exe')

# Make sure that the running version is different to the one getting injected.
assert PYTHON_VERSION != running_python_version

# This assumes that python has been installed in the "usual" location (ie. default as per the installer).
python_dll_path = op.join(op.expanduser("~"), f"AppData\\Local\\Programs\\Python\\Python{PYTHON_VERSION}\\python{PYTHON_VERSION}.dll")
python_dll_path2 = op.join(op.expanduser("~"), f"AppData\\Local\\Programs\\Python\\Python{PYTHON_VERSION2}\\python{PYTHON_VERSION2}.dll")

handle = pymem.process.inject_dll_from_path(pm.process_handle, python_dll_path)
assert handle is not None
print(handle)

handle = pymem.process.inject_dll_from_path(pm.process_handle, python_dll_path2)
assert handle is not None
print(handle)

os.kill(pm.process_id, 9)

This code was run using a python 3.13 interpreter, however it could be anything other than 3.9 or 3.10 (versions can be changed around to accommodate the running version... They just need to be different from it)

@StarrFox
Copy link
Collaborator

StarrFox commented Nov 1, 2024

Looks good to me, thank you for your contribution!

@StarrFox StarrFox merged commit 3ca52a4 into srounet:master Nov 1, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pymem.process.inject_dll returns local handle instead of remote
2 participants