From 0068257ebe69f84fd568cb50e5d858a9fb19f2f4 Mon Sep 17 00:00:00 2001 From: Disconnect3d Date: Sun, 5 Sep 2021 23:10:15 +0200 Subject: [PATCH] Fix qemu.is_usermode and qemu.kernel Tested with: ``` qemu-x86_64 -g 1234 `which ps` gdb -nx `which ps` -ex 'target remote :1234' ``` Bug - we used `QOffsets` instead of `qOffsets`: ``` (gdb) maintenance packet QOffsets sending: "QOffsets" received: "" (gdb) maintenance packet qOffsets sending: "qOffsets" received: "Text=0000004000000000;Data=0000004000000000;Bss=0000004000000000" ``` FWIW: ``` $ qemu-x86_64 --version qemu-x86_64 version 5.2.0 (Debian 1:5.2+dfsg-9ubuntu3.1) Copyright (c) 2003-2020 Fabrice Bellard and the QEMU Project developers $ uname -a Linux dc 5.11.0-31-generic #33-Ubuntu SMP Wed Aug 11 13:19:04 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux ``` Note: ``` (gdb) maintenance packet qAttached sending: "qAttached" received: "0" ``` --- pwndbg/qemu.py | 15 ++++++--------- pwndbg/remote.py | 1 + 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/pwndbg/qemu.py b/pwndbg/qemu.py index f91c50ce9..a4693d128 100644 --- a/pwndbg/qemu.py +++ b/pwndbg/qemu.py @@ -33,18 +33,15 @@ def is_usermode(): if not pwndbg.remote.is_remote(): return False - - # If we had QEMU 2.4 or better, we could use - # - # maintenance packet QAttached: - # - # However, Ubuntu 14 still has QEMU 2.2, so we have to use - # a different command as a heuristic. - response = gdb.execute('maintenance packet QOffsets', + # There is also 'qAttached' - maybe we can use it too? + # for qemu user though it returned "0"? + # Try with: + # qemu-x86_64 -g 1234 `which ps` + # gdb -nx `which ps` -ex 'target remote :1234' + response = gdb.execute('maintenance packet qOffsets', to_string=True, from_tty=False) - return 'Text=' in response @pwndbg.memoize.reset_on_stop diff --git a/pwndbg/remote.py b/pwndbg/remote.py index 49e5f4f44..3122acc5e 100644 --- a/pwndbg/remote.py +++ b/pwndbg/remote.py @@ -11,6 +11,7 @@ import pwndbg.memoize @pwndbg.memoize.reset_on_objfile +@pwndbg.memoize.reset_on_start def is_remote(): # Example: # pwndbg> maintenance print target-stack