From f7eee8fb5dc274fa67e35491996cd3a5867fd353 Mon Sep 17 00:00:00 2001 From: Disconnect3d Date: Tue, 3 Apr 2018 23:05:34 +0700 Subject: [PATCH] Fixes #436 - memory write regression (#437) * Fix regression made in #432 *This situation pushes me more and more to work on tests engine* * Fix eX memory write on Python 2 As string literal is unicode, in Py2 the code below would fail if `bytestr` is just a `str`, due to `'0'` being unocide literal: ``` bytestr.rjust(size*2, '0') ``` --- pwndbg/commands/windbg.py | 6 ++++-- pwndbg/memory.py | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pwndbg/commands/windbg.py b/pwndbg/commands/windbg.py index affdeda0a..fc32d6377 100644 --- a/pwndbg/commands/windbg.py +++ b/pwndbg/commands/windbg.py @@ -8,6 +8,8 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals +from builtins import str + import argparse import codecs import math @@ -172,9 +174,9 @@ def eX(size, address, data, hex=True): if address is None: return - for i,bytestr in enumerate(data): + for i, bytestr in enumerate(data): if hex: - bytestr = bytestr.rjust(size*2, '0') + bytestr = str(bytestr).rjust(size*2, '0') data = codecs.decode(bytestr, 'hex') else: data = bytestr diff --git a/pwndbg/memory.py b/pwndbg/memory.py index ce9eaf883..1a37ab60f 100644 --- a/pwndbg/memory.py +++ b/pwndbg/memory.py @@ -100,7 +100,10 @@ def write(addr, data): addr(int): Address to write data(str,bytes,bytearray): Data to write """ - gdb.selected_inferior().write_memory(addr, bytes(data, 'utf8')) + if isinstance(data, str): + data = bytes(data, 'utf8') + + gdb.selected_inferior().write_memory(addr, data) def peek(address):