Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 2.7 compatibility #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

rxseger
Copy link

@rxseger rxseger commented Aug 29, 2016

Adds an import for (the beginning of) Python 2.7 compatibility. Without this change, Python 2 fails with:

TLCS-900 $ python -V
Python 2.7.12
TLCS-900 $ python dis.py 
  File "dis.py", line 77
    clear = lambda: print("\n" * 120)
                        ^
SyntaxError: invalid syntax

with this change, python dis.py runs successfully and shows the help usage, although attempting to disassemble with Python 2 fails with a different error:

TLCS-900 $ python dis.py -i /tmp/in -o /tmp/x
Traceback (most recent call last):
  File "dis.py", line 281, in <module>
    ib = InputBuffer(f, file_len, bounds)
  File "dis.py", line 116, in __init__
    self.access = bytearray(math.ceil(available / 8))
TypeError: 'float' object is not iterable

Haven't investigated this second error yet, I went ahead and installed Python 3.5.2 instead and was able to disassemble successfully, but this print_function import is a start towards Python 2 compatibility, hopefully it may be useful.

@Victorious3
Copy link
Owner

I'll pull if you manage to fix the other incompatibilities, although, I'm curious, what are you planning to use this for? It never quite got all the functionality I wanted it to have and then I eventually abandoned it because I got stuck on something else. If this has a legitimate use I might want to come back to it.

…t is not iterable

28 / 8 in Python 2 is 3 (integer), but in Python 3 is 3.5 (float),
and type(math.ceil(3.5)) is float in Python 2 but int in Python 3.
Force floating-point division and add integer cast so it works in both.
Fixes this Python 2.7.12 error when disassembling:

Traceback (most recent call last):
  File "dis.py", line 281, in <module>
    ib = InputBuffer(f, file_len, bounds)
  File "dis.py", line 116, in __init__
    self.access = bytearray(math.ceil(available / 8))
TypeError: 'float' object is not iterable
@rxseger
Copy link
Author

rxseger commented Aug 30, 2016

Added a fix for the float not iterable error (bytearray(float) fails in both Python 3 and 2 but 2 was passing an int), but there's still more errors not ready to pull yet, next is:

Traceback (most recent call last):
  File "dis.py", line 284, in <module>
    insn = Insn(executor, ib, ob, ENTRY_POINT)
  File "dis.py", line 203, in __init__
    threading.Thread.__init__(self, daemon = True)
TypeError: __init__() got an unexpected keyword argument 'daemon'

although, I'm curious, what are you planning to use this for?

I pulled a chip from an old DVD player which has a Toshiba TMP91C219F (16-bit TLCS-900/L1 series) micro, just was curious to see what the firmware looked like. Ran into difficulties dumping the complete ROM because of the cumbersome parallel interface, but I did manage to read the first few bytes, if you're curious it disassembles to:

Instructions: 
    Section at 0: 
        0 : 06 07          | EI 7
        2 : 47 00 12 C2 00 | LD XSP, 12718592
        7 : 42 80 00 80 00 | LD XDE, 8388736
        12: 41 24 48 FF 80 | LD XBC, 2164213796
        17: 07             | RETI 
Done in 0.0 seconds.

(which I think seems to be reasonably correct, modulo my dumping errors). Thanks for making this disassembler, couldn't find any free alternatives (IDA Pro has Toshiba TLCS 900 support but it is quite expensive)

@Victorious3 Victorious3 changed the title Add future import for print_function Python 2.7 compatibility Aug 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants