memorpy icon indicating copy to clipboard operation
memorpy copied to clipboard

Python 3 compatibility fixes

Open matslindh opened this issue 7 years ago • 12 comments

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.

matslindh avatar Jul 07 '18 19:07 matslindh

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 avatar Jul 30 '18 14:07 AlessandroZ

@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).

matslindh avatar Jul 30 '18 20:07 matslindh

  • 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.

AlessandroZ avatar Jul 31 '18 09:07 AlessandroZ

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.

AlessandroZ avatar Aug 13 '18 16:08 AlessandroZ

@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).

matslindh avatar Aug 14 '18 08:08 matslindh

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 ?

IsmailAlaouiAbdellaoui avatar Aug 31 '18 22:08 IsmailAlaouiAbdellaoui

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

Strangemother avatar Sep 01 '18 03:09 Strangemother

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

IsmailAlaouiAbdellaoui avatar Sep 01 '18 04:09 IsmailAlaouiAbdellaoui

any updates/fixes?

ghost avatar Oct 08 '21 19:10 ghost

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.

matslindh avatar Oct 08 '21 19:10 matslindh

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

ghost avatar Oct 09 '21 03:10 ghost

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).

matslindh avatar Oct 09 '21 09:10 matslindh