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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

ELF class upgrades #798

Merged
merged 13 commits into from Jan 25, 2022
Merged

ELF class upgrades #798

merged 13 commits into from Jan 25, 2022

Conversation

hugsy
Copy link
Owner

@hugsy hugsy commented Jan 20, 2022

Description/Motivation/Screenshots

Bringing some more Python3.6 joy to the Elf class and subclass, also benefiting the type hinting, which allows to delete ~100 loc of string printing. Some details:

  • Introduce new classes derived from enum.Enum or enum.Flag in the Elf, Phdr and Shdr classes
  • get_entry_point can now be deprecated in favor of gef.binary.entry_point
  • Simplified the helpers (is_arch, is_x86_*) which are way faster now (one lookup and test vs gdb.execute)
  • renamed set_arch to reset_architecture (doesn't return, the result was never used anyway)
  • we make Elf raise if the binary is corrupted (i.e. bad magic), any GDB won't process it
  • The old format of Elf.$arch : int was kept but deprecated (since they are property we can't use the decorator, so if you have ideas 馃槃 )

How Has This Been Tested?

Architecture Yes/No Comments
x86-32 鉁旓笍 Replace with 鉁旓笍 if tested
x86-64 鉁旓笍
ARM 鉁栵笍
AARCH64 鉁栵笍
MIPS 鉁栵笍
POWERPC 鉁栵笍
SPARC 鉁栵笍
RISC-V 鉁栵笍
make test 鉁旓笍

Checklist

  • My PR was done against the dev branch, not master.
  • My code follows the code style of this project.
  • My change includes a change to the documentation, if required.
  • My change adds tests as appropriate.
  • I have read and agree to the CONTRIBUTING document.

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.

quick first pass over lunch. Will have to look it over but it looks great!

gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
hugsy and others added 3 commits January 20, 2022 08:34
- updated types of Phdr attributes
- added `classproperty` decorator
- updated deprecated ELF constants
@hugsy hugsy requested a review from Grazfather January 20, 2022 17:50
hugsy and others added 4 commits January 20, 2022 11:45
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.

Two tiny comments. Looks great.

gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@theguy147 theguy147 left a comment

Choose a reason for hiding this comment

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

As a side note: I love how easy and quick it was to read the PR (considering the size of it) with the new syntax and type hints.

Just a few small remarks...

Also I wasn't able to mark this line in the review but in L8036 you still use the deprecated get_entry_point(). It should be replaced with something like

-        entry = get_entry_point()
-         if entry is None:
-            return
+        if not gef.binary:
+            return
+        entry = gef.binary.entry_point

gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Show resolved Hide resolved
Copy link
Collaborator

@daniellimws daniellimws left a comment

Choose a reason for hiding this comment

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

Tested on arm32, arm64, mipsel32 by loading and running a simple program. All works well so I think there's no issue with everything else.

Found some inconsistent whitespace but other than that all's good

gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
Co-authored-by: Daniel Lim Wee Soong <weesoong.lim@gmail.com>
@hugsy hugsy merged commit 364cf44 into dev Jan 25, 2022
@hugsy hugsy deleted the elf_upgrades branch January 25, 2022 17:23
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.

None yet

4 participants