pythonoptparse

How to accept backslashes in raw input


I'm writing a little program with optparse. It should format shellcode. The problem is, that python doesn't accept e.g "\x31" as argument and interpret it as "x31". Of course it is possible to build a workarround.

But is there a way to work with an input like so?:

python prog.py -t \x31\xCA

print(args) => '\x31\xCA'


Solution

  • Use quotation marks: python prog.py -t "\x31\xCA"