balatro-gba/scripts/get_hash.py
Rickey 955a0942f1
Add contributing guide (#334)
* Add contributing guide

* small format changes for CONTRIBUTING.md

* Update CONTRIBUTING.md

Co-authored-by: MeirGavish <meir.gavish@gmail.com>

* Update CONTRIBUTING.md with more clang-format

* Move stuff around for CONTRIBUTING

* Update VScode instructions

* Remove recommendation for formatOnSave

* Update the clang-format thing again

* Update CONTRIBUTING.md

Co-authored-by: MeirGavish <meir.gavish@gmail.com>

---------

Co-authored-by: MeirGavish <meir.gavish@gmail.com>
2025-12-21 17:27:03 -08:00

28 lines
708 B
Python

#!/usr/bin/env python3
import sys
import re
def grep_binary_offsets(path, pattern):
with open(path, "rb") as f:
data = f.read()
results = []
for match in re.finditer(rb"[ -~]{4,}", data):
s = match.group()
if re.search(pattern.encode(), s):
results.append((match.start(), s.decode("utf-8", errors="ignore")))
return results
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python get_hash.py <file>")
sys.exit(1)
file_path = sys.argv[1]
pattern = "GBALATRO_VERSION"
for offset, text in grep_binary_offsets(file_path, pattern):
version = text.split(":")[1]
print(f"git hash: {version}")