memorpy
memorpy copied to clipboard
Python 3 compatibility fixes
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.
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 :)
@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).
- Import sys
- Get python version used
- Where you removed the ord() function to work with python 3, call (like this - use another name if you want) a custom function which keeps the ord function for python 2 version like this one.
- Do exactly the same thing for the ch function here where nothing is done if python 2 is used otherwise ch is called:
def char(byte):
if python_version == 2:
return byte
else:
return chr(byte)
Should be ok like that.
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.
@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).
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 ?
Process.Process isn't valid. It should be multiprocessing.Process
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
any updates/fixes?
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.
bummer, this would have been a great tool for analyzing malware
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).