Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmd] Allow for filtering about maps permissions in vmmap #1111

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

ValekoZ
Copy link
Collaborator

@ValekoZ ValekoZ commented May 29, 2024

This CL allows for searching sections by their permissions. For instance, you could search for all rwx sections by typing vmmap rwx.

Copy link

🤖 Coverage update for 116e2be 🔴

Old New
Commit 757f5bb 116e2be
Score 71.5302% 71.4923% (-0.0379)

Copy link
Collaborator

@Grazfather Grazfather left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be useful. We might want to add this as a flag argument though, e.g. vmmap --perms rwx.

Maybe we could even support a 'don't care' e.g. r?? vs r--, the former allowing rw-, r-x, etc. Maybe a good idea for a followup.

gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
@ValekoZ
Copy link
Collaborator Author

ValekoZ commented Jun 2, 2024

I think if we put this behind a flag, we should do it for the other filters too?
Like --addr for searching addresses and --name for searching with the name?
I think the goal here is to make it easily useable, without too much friction (I guess that's why there is no --addr/--name?) so in order to stay consistent I think its better to keep it this way

But I think the idea of ? is great I'll do that :)

Copy link

github-actions bot commented Jun 2, 2024

🤖 Coverage update for 9ade706 🟢

Old New
Commit 757f5bb 9ade706
Score 71.5991% 71.5991% (0)

Copy link

github-actions bot commented Jun 2, 2024

🤖 Coverage update for 9394ed1 🟢

Old New
Commit 757f5bb 9394ed1
Score 71.5991% 71.5991% (0)

@ValekoZ ValekoZ added this to the next milestone Jun 3, 2024
@ValekoZ
Copy link
Collaborator Author

ValekoZ commented Jun 9, 2024

I'm marking this as draft until #1120 is merged

@ValekoZ ValekoZ marked this pull request as draft June 9, 2024 16:44
Copy link

🤖 Coverage update for 10cb8fa 🟢

Old New
Commit 5376d78 10cb8fa
Score 71.2662% 71.2662% (0)

Copy link

🤖 Coverage update for ad16e98 🟢

Old New
Commit 5376d78 ad16e98
Score 71.2662% 71.2662% (0)

Copy link

🤖 Coverage update for 3ed4e36 🟢

Old New
Commit 5376d78 3ed4e36
Score 71.2662% 71.2662% (0)

Copy link

🤖 Coverage update for ba83306 🟢

Old New
Commit 5376d78 ba83306
Score 71.2662% 71.2662% (0)

@ValekoZ ValekoZ marked this pull request as ready for review November 10, 2024 16:00
@ValekoZ ValekoZ requested review from Grazfather and hugsy November 10, 2024 16:01
Copy link
Owner

@hugsy hugsy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this filter!
Just some minor changes (mostly docs & tests)

gef.py Outdated Show resolved Hide resolved
@@ -665,6 +665,30 @@ def from_info_mem(cls, perm_str: str) -> "Permission":
if "x" in perm_str: perm |= Permission.EXECUTE
return perm

@classmethod
def from_filter_repr(cls, filter_str: str) -> List["Permission"]:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be worth adding unit test for this function alone.

gef.py Outdated Show resolved Hide resolved
@@ -10,7 +10,7 @@ place). For example, you can learn that ELF running on SPARC architectures alway
and `heap` sections set as Read/Write/Execute.

`vmmap` can accept multiple arguments, either patterns to match again mapping names, or addresses
to determine which section it belongs to:
to determine which section it belongs to, or the permissions of the sections to match:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some examples of --perms would be nice too

Comment on lines +60 to +64
res = gdb.execute("vmmap -p r?-", to_string=True)
self.assertGreater(len(res.splitlines()), 5)

res = gdb.execute("vmmap --perms r?-", to_string=True)
self.assertGreater(len(res.splitlines()), 5)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can go further in checking the output, this doesn't really check the output is as intended. Also those tests being equivalent, you can thoroughly check the strings in the 1st assert, then check that the 1st result equals the 2nd.

Suggested change
res = gdb.execute("vmmap -p r?-", to_string=True)
self.assertGreater(len(res.splitlines()), 5)
res = gdb.execute("vmmap --perms r?-", to_string=True)
self.assertGreater(len(res.splitlines()), 5)
res1 = gdb.execute("vmmap -p r?-", to_string=True)
lines1 = res.splitlines()
self.assertGreater(len(lines), 5)
for line in lines1:
perm_str = line.split()[3]
assert perm_str[0] == 'r'
assert perm_str[1] in ('w', '-')
assert perm_str[2] == '-'
res2 = gdb.execute("vmmap --perms r?-", to_string=True)
assert res1 == res2

Copy link

🤖 Coverage update for e604c6e 🟢

Old New
Commit 5376d78 e604c6e
Score 71.1786% 71.1786% (0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants