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

Use info proc mapping #1046

Merged
merged 20 commits into from
Jan 20, 2024
Merged

Use info proc mapping #1046

merged 20 commits into from
Jan 20, 2024

Conversation

hugsy
Copy link
Owner

@hugsy hugsy commented Jan 13, 2024

Description

Use info proc mapping as a first memory layout enumeration technique.

Removed maintenance info sections which is not about memory layout

Checklist

  • My code follows the code style of this project.
  • My change includes a change to the documentation, if required.
  • If my change adds new code, adequate tests have been added.
  • I have read and agree to the CONTRIBUTING document.

@hugsy hugsy changed the title Use info proc mapping Use info proc mapping Jan 13, 2024
@hugsy hugsy added this to the 2024.05 milestone Jan 13, 2024
@hugsy
Copy link
Owner Author

hugsy commented Jan 17, 2024

Putting on hold for now because gdb on 20.04 uses a different format for info proc mappings:

gef➤  info proc mappings
process 150478
Mapped address spaces:

          Start Addr           End Addr       Size     Offset objfile
      0x555555554000     0x555555555000     0x1000        0x0 /tmp/default.out
      0x555555555000     0x555555556000     0x1000     0x1000 /tmp/default.out
      0x555555556000     0x555555557000     0x1000     0x2000 /tmp/default.out
      0x555555557000     0x555555558000     0x1000     0x2000 /tmp/default.out
      0x555555558000     0x555555559000     0x1000     0x3000 /tmp/default.out
      0x7ffff7dc9000     0x7ffff7deb000    0x22000        0x0 /usr/lib/x86_64-linux-gnu/libc-2.31.so
      0x7ffff7deb000     0x7ffff7f63000   0x178000    0x22000 /usr/lib/x86_64-linux-gnu/libc-2.31.so
      0x7ffff7f63000     0x7ffff7fb1000    0x4e000   0x19a000 /usr/lib/x86_64-linux-gnu/libc-2.31.so
[...]

as opposed to 22.04

gef➤  info proc mappings
process 399031
Mapped address spaces:

          Start Addr           End Addr       Size     Offset  Perms  objfile
      0x555555554000     0x555555555000     0x1000        0x0  r--p   /tmp/default.out
      0x555555555000     0x555555556000     0x1000     0x1000  r-xp   /tmp/default.out
      0x555555556000     0x555555557000     0x1000     0x2000  r--p   /tmp/default.out
      0x555555557000     0x555555558000     0x1000     0x2000  r--p   /tmp/default.out
      0x555555558000     0x555555559000     0x1000     0x3000  rw-p   /tmp/default.out
      0x7ffff7c00000     0x7ffff7c28000    0x28000        0x0  r--p   /usr/lib/x86_64-linux-gnu/libc.so.6
      0x7ffff7c28000     0x7ffff7dbd000   0x195000    0x28000  r-xp   /usr/lib/x86_64-linux-gnu/libc.so.6
      0x7ffff7dbd000     0x7ffff7e15000    0x58000   0x1bd000  r--p   /usr/lib/x86_64-linux-gnu/libc.so.6
[...]

i.e. missing perms for 20.04

Maybe go ahead with the change to ubuntu 24.04?

@Grazfather
Copy link
Collaborator

Maybe we can check for the Perms header and use that to determine which columns to use?

@hugsy hugsy requested a review from Grazfather January 19, 2024 20:41
gef.py Show resolved Hide resolved
gef.py Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
tests/api/gef_memory.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
Repository owner deleted a comment from github-actions bot Jan 19, 2024
Copy link

🤖 Coverage update for 6ed4b51 🟢

Old New
Commit b56bf9d 6ed4b51
Score 71.6206% 71.7779% (0.1573)

@hugsy hugsy requested a review from Grazfather January 19, 2024 23:33
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.

Looks good. Just some nitpicks.

size = int(parts[2], 16)
int(parts[3], 16)
assert end_addr == start_addr + size
assert len(parts[4]) == 4, parts[4]
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's with this second part of the assertion? That's the error message. We could probably give a better explanation (or drop it altogether)

Copy link
Owner Author

Choose a reason for hiding this comment

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

Bad debug print, fixed

tests/base.py Outdated
@property
def gdb_version(self) -> Tuple[int, int]:
res = tuple(
map(int, re.search(r"(\d+)[^\d]+(\d+)", self._gdb.VERSION).groups())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this for a version with just 2 numbers? We might want something like r"(\d+)\D(\d+)". I don't think we need number + non-digits, and \D is the same as [^\d]

Copy link
Owner Author

Choose a reason for hiding this comment

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

TBH the intent is also to let things blow here because this is the same pattern we use and trust in gef. Having it fail here could hint issue with that in gef itself.

tests/base.py Outdated Show resolved Hide resolved
res = tuple(
map(int, re.search(r"(\d+)[^\d]+(\d+)", self._gdb.VERSION).groups())
)
assert len(res) >= 2
Copy link
Collaborator

Choose a reason for hiding this comment

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

The groups call will fail if there aren't exactly two matches. re.search will return None if the version string doesn't match against the regex, and then groups() will raise an AttributeError.

You could instead assert that .search returns a match, and then check the length of groups (it will always be 2), or just drop this stuff.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should drop this. The search.groups() will already raise the exception. This assert is impossible to fail.

tests/base.py Outdated
Comment on lines 113 to 115
res = tuple(
map(int, re.search(r"(\d+)[^\d]+(\d+)", self._gdb.VERSION).groups())
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
res = tuple(
map(int, re.search(r"(\d+)[^\d]+(\d+)", self._gdb.VERSION).groups())
)
res = [int(d) for d in re.search(r"(\d+)\D(\d+)", self._gdb.VERSION).groups()]

Copy link
Owner Author

Choose a reason for hiding this comment

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

Sure ok

@Grazfather
Copy link
Collaborator

Can we split out the CI / coverage changes into its own PR?

@hugsy
Copy link
Owner Author

hugsy commented Jan 20, 2024

Can we split out the CI / coverage changes into its own PR?

Done, see #1050

## Description

Restore the coverage comment functionality for PRs to a workable state

The reason it's broken is because of different security permissions
between actions triggered by `pull_request` and `pull_request_target`.

This will need to be improved carefully by testing non-project commitors
successfully trigger the action.
@hugsy hugsy merged commit c9a8b18 into main Jan 20, 2024
5 checks passed
Copy link

🤖 Coverage update for 62fd178 🟢

Old New
Commit b56bf9d 62fd178
Score 71.6206% 71.7779% (0.1573)

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

Successfully merging this pull request may close these issues.

2 participants