Add git blob hash to version cmd (#683)

This is useful for finding which commit a 'standalone' GEF install was installed from.
This commit is contained in:
theguy147
2021-07-28 09:24:15 -04:00
committed by GitHub
parent 880f8b83d4
commit 8cb298b9b5
3 changed files with 39 additions and 2 deletions
+34
View File
@@ -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>
```
+4 -2
View File
@@ -4319,11 +4319,13 @@ class VersionCommand(GenericCommand):
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)
+1
View File
@@ -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