59 lines
1.6 KiB
Python
59 lines
1.6 KiB
Python
import hashlib
|
|
import zlib
|
|
import sys
|
|
import os
|
|
|
|
def calculate_git_hash(file_path):
|
|
# Read the file content
|
|
with open(file_path, 'rb') as f:
|
|
content = f.read()
|
|
|
|
# Decompress the zlib-compressed content
|
|
decompressed_content = zlib.decompress(content)
|
|
|
|
# Calculate the SHA-1 hash of the decompressed content
|
|
sha1 = hashlib.sha1(decompressed_content).hexdigest()
|
|
|
|
return sha1
|
|
|
|
|
|
def main(hash_to_find):
|
|
files_processed = 0
|
|
skipped = 0
|
|
for root, dirs, files in os.walk('./writable'):
|
|
for file in files:
|
|
# if 'objects' not in root:
|
|
# skipped += 1
|
|
# continue
|
|
if '.' in file:
|
|
continue
|
|
|
|
file_path = os.path.join(root, file)
|
|
|
|
if os.path.islink(file_path):
|
|
skipped += 1
|
|
continue
|
|
|
|
print(file_path)
|
|
try:
|
|
file_hash = calculate_git_hash(file_path)
|
|
if file_hash == hash_to_find:
|
|
print(f"File with hash {hash_to_find} found at {file_path}")
|
|
sys.exit(0)
|
|
except Exception as e:
|
|
# print(f"Error processing {file_path}: {e}")
|
|
print(f"Error processing {file_path}")
|
|
files_processed += 1
|
|
print(files_processed)
|
|
|
|
print(f'Not found. Processed: {files_processed}. Skipped: {skipped}')
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) != 2:
|
|
print("Usage: python3 find_obj_file.py <hash_to_find>")
|
|
sys.exit(1)
|
|
|
|
hash_to_find = sys.argv[1]
|
|
main(hash_to_find)
|