Skip to content

SyntaxWarning with Python 3.12 #177

@elboulangero

Description

@elboulangero

With Python 3.12:

/usr/share/unicorn-magic/unicorn.py:1241: SyntaxWarning: invalid escape sequence '\.'
  elif re.search('\.ps1$', sys.argv[1]) is not None:

This change is documented at https://docs.python.org/3/whatsnew/3.12.html#other-language-changes:

A backslash-character pair that is not a valid escape sequence now generates a SyntaxWarning, instead of DeprecationWarning. For example, re.compile("\d+.\d+") now emits a SyntaxWarning ("\d" is an invalid escape sequence, use raw strings for regular expression: re.compile(r"\d+.\d+")). In a future Python version, SyntaxError will eventually be raised, instead of SyntaxWarning.

Patch (trivial):

From: Arnaud Rebillout <[email protected]>
Date: Mon, 22 Jul 2024 22:53:10 +0200
Subject: Use raw string for regex pattern

---
 unicorn.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/unicorn.py b/unicorn.py
index 496bd57..c06aacf 100755
--- a/unicorn.py
+++ b/unicorn.py
@@ -1238,7 +1238,7 @@ try:
             if len(sys.argv) > 2 and sys.argv[2] == "crt":
                 attack_type = "crt"
                 payload = sys.argv[1]
-            elif re.search('\.ps1$', sys.argv[1]) is not None:
+            elif re.search(r'\.ps1$', sys.argv[1]) is not None:
                 attack_type = "custom_ps1"
                 ps1path = sys.argv[1]
 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions