From 0323e769cfd247c5dbb931c6e524bce85e3991bb Mon Sep 17 00:00:00 2001 From: Disconnect3d Date: Mon, 30 Apr 2018 20:22:47 +0700 Subject: [PATCH] Support hex data prefixed with 0x when using eX windbg command (#444) When using `eX` commands and setting data to hex value prefixed with `0x`, we get an exception: ``` pwndbg> ed 0xffb21ae4 0x55616740 Traceback (most recent call last): File "/usr/lib/python3.6/encodings/hex_codec.py", line 19, in hex_decode return (binascii.a2b_hex(input), len(input)) binascii.Error: Non-hexadecimal digit found The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/home/dc/installed/pwndbg/pwndbg/commands/__init__.py", line 109, in __call__ return self.function(*args, **kwargs) File "/home/dc/installed/pwndbg/pwndbg/commands/__init__.py", line 200, in _OnlyWhenRunning return function(*a, **kw) File "/home/dc/installed/pwndbg/pwndbg/commands/windbg.py", line 141, in ed return eX(4, address, data) File "/home/dc/installed/pwndbg/pwndbg/commands/windbg.py", line 180, in eX data = codecs.decode(bytestr, 'hex') binascii.Error: decoding with 'hex' codec failed (Error: Non-hexadecimal digit found) ``` This commit fixes this problem so that if the data input has prefix, it is stripped. --- pwndbg/commands/windbg.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pwndbg/commands/windbg.py b/pwndbg/commands/windbg.py index c578dba5b..b658590e5 100644 --- a/pwndbg/commands/windbg.py +++ b/pwndbg/commands/windbg.py @@ -175,7 +175,13 @@ def eX(size, address, data, hex=True): for i, bytestr in enumerate(data): if hex: - bytestr = str(bytestr).rjust(size*2, '0') + bytestr = str(bytestr) + + if bytestr.startswith('0x'): + bytestr = bytestr[2:] + + bytestr = bytestr.rjust(size*2, '0') + data = codecs.decode(bytestr, 'hex') else: data = bytestr