gdabah / distorm

Powerful Disassembler Library For x86/AMD64
Other
1.26k stars 238 forks source link

ctypes byref takes one argument #19

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Test script test_distorm.py
#!/usr/bin/env python

import sys
from distorm3 import Decode, Decode32Bits

l = Decode(0x100, open(sys.argv[1], "rb").read(), Decode32Bits)

2. Test file: any flat binary x86 code

3. ./test_distorm.py test_file

What is the expected output? What do you see instead?
The expected output is to run without syntax errors. I get:
Traceback (most recent call last):
  File "./test_distorm.py", line 6, in <module>
    l = Decode(0x100, open(sys.argv[1], "rb").read(), Decode32Bits)
  File "/usr/local/lib/python2.6/dist-packages/distorm3/__init__.py", line 444, in Decode
    return list( DecodeGenerator(offset, code, type) )
  File "/usr/local/lib/python2.6/dist-packages/distorm3/__init__.py", line 412, in DecodeGenerator
    p_code     = byref(code_buf, instruction_off)
TypeError: byref() takes exactly one argument (2 given)
[Note: it should say 408 instead of 412 this is the patched version with the 
patch commented out so line numbers are offset by 4]

What version of the product are you using? On what operating system?
distorm3 from the download section as well as svn revision 166 produce this 
error.
I am using Python 2.6.5 on an Ubuntu 10.04 LTS x86_64.

Please provide any additional information below.
I found another old issue and a fix for it that states that byref can take an 
optional offset argument, this doesn't seem to be true.

FIX:
This is a very quick (and dumb) fix. I replaced the problem line 408 in 
__init__.py:
p_code = byref(code_buf, instrcution_off)
with:
code_buf = create_string_buffer(code[instruction_off:])
p_code = byref(code_buf)

Original issue reported on code.google.com by codrutze...@gmail.com on 9 Jan 2011 at 10:03

GoogleCodeExporter commented 9 years ago
After checking on the python ctypes docs 
(http://docs.python.org/library/ctypes.html#ctypes.byref) and the changelog it 
seems that the offset argument should be available starting from Python 2.6. 
I've tested this in an old VM running OpenSUSE 11.2 with Python 2.6.2 and it 
works fine. So this doesn't seem to be a problem with distorm so I guess this 
issue can be closed.
Sorry for the inconvenience, I should have checked this on another platform 
before posting the bug.

Original comment by codrutze...@gmail.com on 11 Jan 2011 at 5:05

GoogleCodeExporter commented 9 years ago
Hey there,
if you take a look at the header of the __init__.py it reads as following:
"# Compatiable with Python2.6 and above." specifically because of that reason 
you found. I believe most people should be running Python 2.6 by now at least, 
obviously I'm half wrong...

Thanks for your comment anyway.

Original comment by distorm@gmail.com on 12 Jan 2011 at 8:40

GoogleCodeExporter commented 9 years ago
Won't be fixed - to support Python 2.5 and below.

Original comment by distorm@gmail.com on 12 Jan 2011 at 8:42

GoogleCodeExporter commented 9 years ago
Hi,

Like I said, I was/am using Python 2.6.5 (>2.6) and got a syntax error. I did 
see the comment about the minimum version required, that is why I thought this 
may be a bug (since I was using a version that should work). However, after 
removing all the .egg files I have installed it works fine. At the moment it 
would seem that one of the modules I installed may have broken something (now I 
have to figure out which one). :(

Again, sorry for the false alarm.

Original comment by codrutze...@gmail.com on 12 Jan 2011 at 1:29

GoogleCodeExporter commented 9 years ago
Maybe I should change it back then or something. I will check it out later.

Original comment by distorm@gmail.com on 13 Jan 2011 at 2:58