Skip to content

Commit

Permalink
Add git blob hash to version cmd (#683)
Browse files Browse the repository at this point in the history
This is useful for finding which commit a 'standalone' GEF install was installed from.
  • Loading branch information
theguy147 committed Jul 28, 2021
1 parent 880f8b8 commit 8cb298b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
34 changes: 34 additions & 0 deletions docs/commands/version.md
@@ -0,0 +1,34 @@
## Command version ##

Print out version information about your current gdb environment.

### Usage Examples ###

When GEF is located in a directory tracked with git:

```
gef➤ version
GEF: rev:48a9fd74dd39db524fb395e7db528f85cc49d081 (Git - clean)
SHA1(/gef/rules/gef.py): 848cdc87ba7c3e99e8129ad820c9fcc0973b1e99
GDB: 9.2
GDB-Python: 3.8
```

Otherwise the command shows the `standalone` information:

```
gef➤ aslr on
GEF: (Standalone)
Blob Hash(/gef/rules/gef.py): 2939fbc037bca090422e12cf1b555bd58223dccb
SHA1(/gef/rules/gef.py): 6e6bfd03282a0d5b1eec5276fa57af0ccbac31c6
GDB: 9.2
GDB-Python: 3.8
```

The `Blob Hash` can be used to easily find the git commit(s) matching
this file revision (or whether it has been modified and does not match
any revision):

```
git log --oneline --find-object <BLOB_HASH>
```
6 changes: 4 additions & 2 deletions gef.py
Expand Up @@ -4319,11 +4319,13 @@ def do_invoke(self, argv):
gef_hash = hashlib.sha1(open(gef_fpath, "rb").read()).hexdigest()

if os.access("{}/.git".format(gef_dir), os.X_OK):
ver = subprocess.check_output('git log --format="%H" -n 1 HEAD', cwd=gef_dir, shell=True).decode("utf8").strip()
extra = "dirty" if len(subprocess.check_output('git ls-files -m', cwd=gef_dir, shell=True).decode("utf8").strip()) else "clean"
ver = subprocess.check_output("git log --format='%H' -n 1 HEAD", cwd=gef_dir, shell=True).decode("utf8").strip()
extra = "dirty" if len(subprocess.check_output("git ls-files -m", cwd=gef_dir, shell=True).decode("utf8").strip()) else "clean"
gef_print("GEF: rev:{} (Git - {})".format(ver, extra))
else:
gef_blob_hash = subprocess.check_output("git hash-object {}".format(gef_fpath), shell=True).decode().strip()
gef_print("GEF: (Standalone)")
gef_print("Blob Hash({}): {}".format(gef_fpath, gef_blob_hash))
gef_print("SHA1({}): {}".format(gef_fpath, gef_hash))
gef_print("GDB: {}".format(gdb.VERSION, ))
py_ver = "{:d}.{:d}".format(sys.version_info.major, sys.version_info.minor)
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Expand Up @@ -56,6 +56,7 @@ nav:
- Command tmux-setup: commands/tmux-setup.md
- Command trace-run: commands/trace-run.md
- Command unicorn-emulate: commands/unicorn-emulate.md
- Command version: commands/version.md
- Command vmmap: commands/vmmap.md
- Command xfiles: commands/xfiles.md
- Command xinfo: commands/xinfo.md
Expand Down

0 comments on commit 8cb298b

Please sign in to comment.