Advertisement
theballaam96

GZIP Timestamp Grabber

Dec 7th, 2022
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. import datetime
  2.  
  3. with open("dk64.z64","rb") as fh: # Change filename to correspond to the ROM
  4.     file_size = len(fh.read())
  5.     dates = {}
  6.     names = []
  7.     for x in range(file_size):
  8.         fh.seek(x)
  9.         data = int.from_bytes(fh.read(3), "big")
  10.         header = int.from_bytes(fh.read(1), "big")
  11.         if data == 0x1F8B08:
  12.             # GZIP File
  13.             fh.seek(x + 4)
  14.             timestamp = int.from_bytes(fh.read(4), "little")
  15.             if timestamp != 0:
  16.                 date_time = datetime.datetime.fromtimestamp(timestamp)
  17.                 date = str(date_time).split(" ")[0]
  18.                 fh.seek(x + 10)
  19.                 if header & 8:
  20.                     filename = ""
  21.                     filename_ended = False
  22.                     while not filename_ended:
  23.                         val = int.from_bytes(fh.read(1), "big")
  24.                         if val == 0:
  25.                             filename_ended = True
  26.                         else:
  27.                             filename += bytearray([val]).decode("ascii")
  28.                             # filename += hex(val)[2:] # JP
  29.                     if filename not in names:
  30.                         names.append(filename)
  31.                 if date in dates:
  32.                     dates[date]["count"] += 1
  33.                     dates[date]["files"].append(hex(x))
  34.                 else:
  35.                     dates[date] = {
  36.                         "count": 1,
  37.                         "files": [hex(x)]
  38.                     }
  39.     print(dates)
  40.     print(names)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement