n1nj4sec / memorpy

Python library using ctypes to search/edit windows / linux / macOS / SunOS programs memory
GNU General Public License v3.0
776 stars 140 forks source link

Python 3 compatibility fixes #20

Closed matslindh closed 2 years ago

matslindh commented 6 years ago

This set of patches makes the basic functionality of memorpy work under python 3 on Windows. I've not tested it with python 2 - so there probably needs to be a few extra try/catch-es or a dependency on six.

As the platform I had this need on is Windows, I haven't tested the Linux (or other OS-es) compatibility either.

Consider this a starting PR that can be updated with other patches to make memorpy both 2 and 3 compliant.

AlessandroZ commented 6 years ago

I'm interested about this PR as well because I'm trying to update all my tools to python3 (but keeping the portability to python 2).

I think this PR should work in python 2 as well except for the line 108 and 109. I had the same problem that I solved like that.

Thanks for the merge :)

matslindh commented 6 years ago

@AlessandroZ If you have a patch I can apply I can make it part of the PR (.. or if you have commit access you can push it directly to my branch).

AlessandroZ commented 6 years ago
AlessandroZ commented 6 years ago

Change here and here to:

for res in func(b.decode('latin'), value, offset):
    yield res

If you put decode() or decode('utf-8'), you could have lots of decoding error problems. 'latin' is safer.

matslindh commented 6 years ago

@AlessandroZ It'd be great if you could submit a patch with your discoveries; I don't have the time right now to hunt down each line based on your descriptions. If you're already modifying the code, clone the PR and include the patch here and I'll add it to the PR (if you don't have maintainer access - in that case you can push directly to my branch).

IsmailAlaouiAbdellaoui commented 6 years ago

I did the change @AlessandroZ suggested from matslindh/memorpy, then I have the following error :

File "D:/test.py", line 64, in <module>
    mw=MemWorker(pid=8808)

  File "D:\Users\Miniconda3\lib\site-packages\memorpy-1.7-py3.6.egg\memorpy\MemWorker.py", line 35, in __init__
    self.process = Process.Process(name=name, pid=pid, debug=debug)

AttributeError: type object 'WinProcess' has no attribute 'Process'

Can someone point me out to a fully functional Python 3 repo ?

Strangemother commented 6 years ago

Process.Process isn't valid. It should be multiprocessing.Process

IsmailAlaouiAbdellaoui commented 6 years ago

Ok I actually got it running. Thanks btw. But then I have another issue. When I write this code :

mw=MemWorker(pid=6008)
lo=Locator(mw)
lo.feed(4) #line where error is detected

The following error is returned :

  File "D:\Users\Miniconda3\lib\site-packages\memorpy-1.7-py3.6.egg\memorpy\MemWorker.py", line 128, in parse_any_function
    index = b.find(value)

TypeError: must be str, not bytes
ghost commented 3 years ago

any updates/fixes?

matslindh commented 3 years ago

I'm guessing you're gonna have to get it further yourself; I currently have no interest in pursuing it further as our use case is currently inactive.

ghost commented 3 years ago

bummer, this would have been a great tool for analyzing malware

matslindh commented 3 years ago

My comment was in relation to this specific PR - the library itself might be moving forward (although it seems rather abandoned based on when it was last updated).