0
votes

i made a script to decode a file made a few years ago, and I've run into an issue whilst doing my second decode test.

My code:

#!/usr/bin/python
# -*- coding: utf-8 -*-
from decoder.encodings import *

#Toontown Online Encoded Script Decoder

"""
##########################################
# Decoder was built to decompile         #
# Team Pawz Multihack v2.0               #
##########################################
"""
input = "Text can be located here: http://pastebin.com/rdeAhyar ";
def decode():
    print input.decode('latin_1')
decode()

When i execute the code i get

SyntaxError: EOL while scanning string literal

SyntaxError: EOL while scanning string literal

Press any key to continue . . .

If this helps i'm using the version of Python distributed within Panda3D.

1
The problem is not in the code you've shown. Maybe you meant to replace the input value with the paste from the link? How? Are you sure there is nothing in that text that ends a string literal? Which would explain the error you are seeing. You also have to make sure backslashes are escaped or you are using a raw string literal. - BlackJack
It wouldn't allow me to post the input on stackoverflow so i put it on the pastebin link inside of the code where it says "Text can be located here:" Its a long piece of encoded code i've been trying to decode for the past few months. - Crowded
You may consider putting a complete runnable example into the paste bin instead of splitting up the two parts, leaving us to wonder how to combine those two pieces. Which can be done in different ways making it hard to reproduce your particular problem. Why do you want to paste binary data into source code anyway? It's easier to put it into its own file and read that in binary mode. - BlackJack
Here is the decoder with the encoded code within the input box. pastebin.com/ECCzm200 Once you put it in a text editor such as Notepad++, or Notepad in general, it is easier to look at what i did. If i need to go more in detail i'll try (I'm a newbie, should have said that, but i don't learn from book.. i learn from source codes) - Crowded
With that code I can't reproduce your problem. It parses fine without the SyntaxError. Please show an example that actually shows the problem, reproducible by others. - BlackJack

1 Answers

1
votes

The problem is embedding binary data in source code by simply pasting it. The error appears on Windows because Windows sees a byte value of 26 (hex 1A) as the end of text files and stops reading text files right before this byte value. Linux is not affected by this, that's the reason I was unable to reproduce the problem.

Observe the difference in file size and the amount of bytes a ”full” read() returns under Windows:

>>> os.path.getsize('test.py')
49297L
>>> len(open('test.py', 'r').read()) # text mode
1100
>>> len(open('test.py', 'rb').read()) # binary mode
49297

The solution is not to embed the binary data in the source code but load it from an extra file. Make sure to open it in binary mode instead of text mode.

Or you have to encode the binary data so it doesn't contain ”exotic” byte values any more. Base64 encoding is a good candidate for this.