Rename chain command to plist (print list) (#1817)

pull/1819/head
Disconnect3d 2 years ago committed by GitHub
parent 8d9c440231
commit 26f7c442bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -615,7 +615,6 @@ def load_commands() -> None:
import pwndbg.commands.auxv
import pwndbg.commands.branch
import pwndbg.commands.canary
import pwndbg.commands.chain
import pwndbg.commands.checksec
import pwndbg.commands.comments
import pwndbg.commands.config
@ -651,6 +650,7 @@ def load_commands() -> None:
import pwndbg.commands.patch
import pwndbg.commands.peda
import pwndbg.commands.pie
import pwndbg.commands.plist
import pwndbg.commands.probeleak
import pwndbg.commands.procinfo
import pwndbg.commands.radare2

@ -13,7 +13,7 @@ parser = argparse.ArgumentParser(
This command traverses the linked list beginning at a given element, dumping its
contents and the contents of all the elements that come after it in the list.
Traversal is configurable and can handle multiple types of chains, but will
Traversal is configurable and can handle multiple types of linked lists, but will
always stop when a cycle is detected.
The path to the first element can be any GDB expression that evaluates to either
@ -48,7 +48,7 @@ struct node node_b = { 1, &node_c };
struct node node_a = { 0, &node_b };
```
pwndbg> chain node_a next
pwndbg> plist node_a next
0x4000011050 <node_a>: {
value = 0,
next = 0x4000011040 <node_b>
@ -77,7 +77,7 @@ struct inner_a_node inner_a_node_b = { 1, { &inner_a_node_c.inner } };
struct inner_a_node inner_a_node_a = { 0, { &inner_a_node_b.inner } };
```
pwndbg> chain inner_a_node_a -i inner next
pwndbg> plist inner_a_node_a -i inner next
0x4000011070 <inner_a_node_a>: {
value = 0,
inner = {
@ -113,7 +113,7 @@ struct inner_b_node inner_b_node_b = { 1, { &inner_b_node_c } };
struct inner_b_node inner_b_node_a = { 0, { &inner_b_node_b } };
```
pwndbg> chain inner_b_node_a -i inner next
pwndbg> plist inner_b_node_a -i inner next
0x4000011090 <inner_b_node_a>: {
value = 0,
inner = {
@ -138,10 +138,10 @@ pwndbg> chain inner_b_node_a -i inner next
parser.add_argument(
"path",
type=str,
help="The first element of the chain",
help="The first element of the linked list",
)
parser.add_argument(
"next", type=str, help="The name of the field pointing to the next element in the chain"
"next", type=str, help="The name of the field pointing to the next element in the list"
)
parser.add_argument(
"-s",
@ -167,8 +167,8 @@ parser.add_argument(
)
@pwndbg.commands.ArgparsedCommand(parser, command_name="chain")
def chain(path, next, sentinel, inner_name, field_name) -> None:
@pwndbg.commands.ArgparsedCommand(parser, command_name="plist")
def plist(path, next, sentinel, inner_name, field_name) -> None:
# Have GDB parse the path for us and check if it's valid.
try:
first = gdb.parse_and_eval(path)
@ -222,7 +222,7 @@ def chain(path, next, sentinel, inner_name, field_name) -> None:
return
# Resolve the pointer to the next structure, wherever it may be, and make
# sure that we can use it to traverse the chain.
# sure that we can use it to traverse the linked list.
next_ptr_loc = first
next_ptr_name = next
try:
@ -373,8 +373,8 @@ def chain(path, next, sentinel, inner_name, field_name) -> None:
print(f"{target_address:#x} {symbol}: {value}")
except gdb.error as e:
print(message.error(f"Cannot dereference 0x{address:#x} for chain link #{i + 1}: {e}"))
print(message.error("Is the chain corrupted or is the sentinel value wrong?"))
print(message.error(f"Cannot dereference 0x{address:#x} for list link #{i + 1}: {e}"))
print(message.error("Is the linked list corrupted or is the sentinel value wrong?"))
return

@ -15,9 +15,9 @@ def startup(start_binary):
gdb.execute("up")
def test_command_chain_flat_no_flags(start_binary):
def test_command_plist_flat_no_flags(start_binary):
"""
Tests the chain for a non-nested linked list
Tests the plist for a non-nested linked list
"""
startup(start_binary)
@ -37,13 +37,13 @@ def test_command_chain_flat_no_flags(start_binary):
}"""
)
result_str = gdb.execute("chain node_a next", to_string=True)
result_str = gdb.execute("plist node_a next", to_string=True)
assert expected_out.match(result_str) is not None
def test_command_chain_flat_field(start_binary):
def test_command_plist_flat_field(start_binary):
"""
Tests the chain command for a non-nested linked list with field flag
Tests the plist command for a non-nested linked list with field flag
"""
startup(start_binary)
@ -55,13 +55,13 @@ def test_command_chain_flat_field(start_binary):
"""
)
result_str = gdb.execute("chain node_a next -f value", to_string=True)
result_str = gdb.execute("plist node_a next -f value", to_string=True)
assert expected_out.match(result_str) is not None
def test_command_chain_flat_sentinel(start_binary):
def test_command_plist_flat_sentinel(start_binary):
"""
Tests the chain command for a non-nested linked list with field flag
Tests the plist command for a non-nested linked list with field flag
"""
startup(start_binary)
@ -78,13 +78,13 @@ def test_command_chain_flat_sentinel(start_binary):
}"""
)
result_str = gdb.execute(f"chain node_a next -s {sentinel}", to_string=True)
result_str = gdb.execute(f"plist node_a next -s {sentinel}", to_string=True)
assert expected_out.match(result_str) is not None
def test_command_chain_nested_direct(start_binary):
def test_command_plist_nested_direct(start_binary):
"""
Tests the chain for a nested linked list pointing to the outer structure
Tests the plist for a nested linked list pointing to the outer structure
"""
startup(start_binary)
@ -110,13 +110,13 @@ def test_command_chain_nested_direct(start_binary):
}"""
)
result_str = gdb.execute("chain inner_b_node_a -i inner next", to_string=True)
result_str = gdb.execute("plist inner_b_node_a -i inner next", to_string=True)
assert expected_out.match(result_str) is not None
def test_command_chain_nested_indirect(start_binary):
def test_command_plist_nested_indirect(start_binary):
"""
Tests the chain for a nested linked list pointing to the inner structure
Tests the plist for a nested linked list pointing to the inner structure
"""
startup(start_binary)
@ -142,5 +142,5 @@ def test_command_chain_nested_indirect(start_binary):
}"""
)
result_str = gdb.execute("chain inner_a_node_a -i inner next", to_string=True)
result_str = gdb.execute("plist inner_a_node_a -i inner next", to_string=True)
assert expected_out.match(result_str) is not None
Loading…
Cancel
Save