fix distance command (#1146)

* fix distance command

* fix unused imports
pull/1148/head
Disconnect3d 3 years ago committed by GitHub
parent 8dae55490b
commit 88c610116e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -87,12 +87,15 @@ parser.add_argument("b", type=int, help="The second address.")
@pwndbg.commands.ArgparsedCommand(parser)
def distance(a, b):
"""Print the distance between the two arguments"""
a = int(a) & pwndbg.arch.ptrmask
b = int(b) & pwndbg.arch.ptrmask
a = int(a) & pwndbg.gdblib.arch.ptrmask
b = int(b) & pwndbg.gdblib.arch.ptrmask
distance = b - a
print("%#x->%#x is %#x bytes (%#x words)" % (a, b, distance, distance // pwndbg.arch.ptrsize))
print(
"%#x->%#x is %#x bytes (%#x words)"
% (a, b, distance, distance // pwndbg.gdblib.arch.ptrsize)
)
def list_and_filter_commands(filter_str):

@ -0,0 +1,15 @@
import gdb
import pwndbg.gdblib.regs
import tests
REFERENCE_BINARY = tests.binaries.get("reference-binary.out")
def test_command_distance(start_binary):
start_binary(REFERENCE_BINARY)
rsp = pwndbg.gdblib.regs.rsp
result = gdb.execute("distance $rsp $rsp+0x10", to_string=True)
assert result == "%#x->%#x is 0x10 bytes (0x2 words)\n" % (rsp, rsp + 0x10)
Loading…
Cancel
Save