Skip to content

Commit

Permalink
Fix SyntaxWarning in Python 3.12 (#2302)
Browse files Browse the repository at this point in the history
* libcdb.py - python 3.12

Python 3.12 would complain if the \d atom is not escaped in the binary string.

/usr/lib/python3.12/site-packages/pwnlib/commandline/libcdb.py:224: SyntaxWarning: invalid escape sequence '\d'
  libc_version = re.search(b'libc[ -](\d+\.\d+)', exe.data)

* Use raw string

---------

Co-authored-by: peace-maker <[email protected]>
  • Loading branch information
xambroz and peace-maker committed Nov 24, 2023
1 parent bb1d16c commit 77957b4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pwnlib/commandline/libcdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def main(args):
exe = ELF(file, checksec=False)
log.info('%s', text.red(os.path.basename(file)))

libc_version = re.search(b'libc[ -](\d+\.\d+)', exe.data)
libc_version = re.search(br'libc[ -](\d+\.\d+)', exe.data)
if libc_version:
log.indented('%-20s %s', text.green('Version:'), libc_version.group(1).decode())

Expand Down

1 comment on commit 77957b4

@xambroz
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like raw more as well.
I believe it was failing on me when I tried, but this works python2 (rhel7/8/f39) and python3(rhel7/8/ f39)

Tested with :

import re

class Object(object):
    pass
    
exe = Object()
exe.data = open('/usr/lib64/libc.so.6','rb').read()

try:
    print("original binary")
    libc_version = re.search(b'libc[ -](\d+\.\d+)', exe.data)
    print(libc_version.group(1))

except:
    print("original fails")

try:
    print("escaped binary")
    libc_version = re.search(b'libc[ -](\\d+\\.\\d+)', exe.data)
    print(libc_version.group(1))

except:
    print("escaped binary fails")

try:
    print("binary raw")
    libc_version = re.search(br'libc[ -](\d+\.\d+)', exe.data)
    print(libc_version.group(1))

except:
    print("binary raw fails")

Please sign in to comment.