QQuick / Opy

Obfuscator for Python
Other
362 stars 61 forks source link

Opy failing to obfuscate code with strings that contain the # character (with obfuscate_strings = False) #12

Closed andimarafioti closed 7 years ago

andimarafioti commented 7 years ago

I'm getting errors when I obfuscate strings that contain the # character. This error happens both for single quoted strings and triple quoted strings:

type A: single quoted DISCONNECTED_MESSAGE = u"Estás utilizando esTTela sin conexión a la red. Volviendo a intentar conectar en {} <a href='LINK'><font color=#ffffff>Reintentar</font></a>" Becomes: l1ll11lllll1l1_opy_ = u"Estás utilizando esTTela sin conexión a la red. Volviendo a intentar conectar en {} <a href='LINK'><font color= Note that the quotes are not closed at the end of the string, therefore the obfuscated code fails with "SyntaxError: EOL while scanning string literal"

type B: triple quoted message_link = """<a href='LINK'><font color=#ffffff>click acá</font></a>""" Becomes: message_link = """<a href='LINK'><font color= This case is actually worse because it comments the rest of the code (though it is obfuscated).

I debugged opy trying to fix this, but I am miles away from the author in regEx knowledge. The issue arises in line 431 of opy.py:

normalContent = commentRegEx.sub (getCommentPlaceholderAndRegister, normalContent) Up until that point, the comment is correctly loaded. There it is sliced.

I think the regEx that needs to be fixed is the one found in line 229 of opy.py:

commentRegEx = re.compile (r'{0}{1}{2}.*?$'.format ( r"(?<!')", r'(?<!")', r'#' ), re.MULTILINE)

andimarafioti commented 7 years ago

Ok, this is already noted in https://github.com/QQuick/Opy/issues/10