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

3.8 tests failure #30

Closed StarrFox closed 3 years ago

StarrFox commented 3 years ago

Running py -m pytest --cov=pymem on python 3.8 results in a failed test for test_injection

    def test_inject_python_shellcode():
        notepad = subprocess.Popen(['notepad.exe'])

        pm = pymem.Pymem('notepad.exe')
        pm.inject_python_interpreter()

        # test already injected
        pm.inject_python_interpreter()

        assert pm.py_run_simple_string

        filepath = os.path.join(os.path.abspath('.'), 'pymem_injection.txt')
        filepath = filepath.replace("\\", "\\\\")

        shellcode = """
    f = open("{}", "w+")
    f.write("pymem_injection")
    f.close()
        """.format(filepath)
>       pm.inject_python_shellcode(shellcode)

tests\test_injection.py:38:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pymem\__init__.py:144: in inject_python_shellcode
    self.start_thread(self.py_run_simple_string, shellcode_addr)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <pymem.Pymem object at 0x000002839324DFA0>, address = 1242510712, params = 1335612407808

    def start_thread(self, address, params=None):
        """Create a new thread within the current debugged process.

        Parameters
        ----------
        address: int
            An address from where the thread starts
        params: int
            An optional address with thread parameters

        Returns
        -------
        int
            The new thread identifier
        """
        thread_id = ctypes.c_ulong(0)
        thread_h = pymem.ressources.kernel32.CreateRemoteThread(
            self.process_handle,
            None,
            0,
            address,
            params,
            0,
            None
        )
        pymem.ressources.kernel32.WaitForSingleObject(thread_h, -1)
>       pymem.logger.debug('New thread_id: 0x%08x' % thread_h)
E       TypeError: %x format: an integer is required, not NoneType

pymem\__init__.py:172: TypeError

Exact commands I ran with output: https://hastebin.com/semopotume.php

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 #32 https://github.com/srounet/Pymem/tree/fix-30/32