srounet / Pymem

A python library for windows, providing the needed functions to start working on your own with memory editing.
MIT License
303 stars 45 forks source link

Nonetype error running inject_python_shellcode #32

Closed Abystus closed 3 years ago

Abystus commented 3 years ago

OS: Windows 10 Pro (64 bit) Python: 3.8.5 (64 bit) Process: notepad.exe (64 bit) Error #: 6

image

Based on code found here.

Script:

from pymem import Pymem
import os
import subprocess

notepad = subprocess.Popen(['notepad.exe'])

pm = Pymem('notepad.exe')

pm.inject_python_interpreter()
filepath = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'pymem_injection.txt')
filepath = filepath.replace("\\", "\\\\")
shellcode = """
f = open("{}", "w+")
f.write("pymem_injection")
f.close()
""".format(filepath)

import ctypes
ctypes.windll.kernel32.SetLastError(0)
try:
    pm.inject_python_shellcode(shellcode)
except:
    pass
last_error = ctypes.windll.kernel32.GetLastError()
print(f"last_error={last_error}")

notepad.kill()

image

srounet commented 3 years ago

I m reproducing it within AppVeyor pipeline, something have changed after python 3.6 and affects python 3.7 and 3.8 at least. Need further investigations.

I've started a branch for this issue and the #30 https://github.com/srounet/Pymem/tree/fix-30/32