Advertisement
Guest User

Just a SAHT analyser

a guest
Feb 17th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.40 KB | None | 0 0
  1. from struct import *
  2.  
  3. FileIn = "HashTable.saht"
  4. SAHTFile = open(FileIn, mode = 'br', buffering = 0)
  5.  
  6. SAHTHeader = unpack('<4s', SAHTFile.read(4))[0]
  7. SAHTFileSize = unpack('<i', SAHTFile.read(4))[0]
  8. SAHTDataOffset = unpack('<i', SAHTFile.read(4))[0]
  9. SAHTNrEntries = unpack('<i', SAHTFile.read(4))[0]
  10.  
  11. print("The Header file is {0}.".format(SAHTHeader))
  12. print("The File Size is {0}.".format(SAHTFileSize))
  13. print("The Data Offset is {0}".format(SAHTDataOffset))
  14. if SAHTNrEntries is 1:
  15.     print("The Number Entry is {0}.".format(SAHTNrEntries))
  16. else:
  17.     print("The Number Entries are {0}".format(SAHTNrEntries))
  18. print("")
  19. print("")
  20.  
  21. for i in range(0,SAHTNrEntries):
  22.     StartingPoint = SAHTFile.tell()
  23.     SAHTHash = hex(unpack('<I', SAHTFile.read(4))[0])
  24.     print("The Hash is {0}.".format(SAHTHash))
  25.  
  26.     Buffer = unpack('<1s', SAHTFile.read(1))[0]
  27.     SAHTString = b''
  28.     SAHTString += Buffer
  29.     while Buffer != b'\x00':
  30.         # My idea behind this code is to keep unpacking the
  31.         # Buffer until the Buffer hit a Null (or None in python)
  32.         # value. Then the program would stop doing this. But, becuase
  33.         # of how the code works, it also factors in a Null, however the if
  34.         # statement catches this. Just keep this in mind when using .tell()
  35.         Buffer = unpack('<1s', SAHTFile.read(1))[0]
  36.         if Buffer != b'\x00' and Buffer != b'/':
  37.             SAHTString += Buffer
  38.         elif Buffer == b'/':
  39.             print("The fake 'directory' is {0}.".format(SAHTString))
  40.             Buffer = unpack('<1s', SAHTFile.read(1))[0]
  41.             SAHTString = b''
  42.             if Buffer != b'\x00':
  43.                 SAHTString += Buffer
  44.             else:
  45.                 pass
  46.         else:
  47.             pass
  48.     print("The file name is {0}.".format(SAHTString))
  49.  
  50.     HitNullPoint = SAHTFile.tell()
  51.     print("The actual range of data value is from {0} (Start at Hash Value) "
  52.           "to {1} (First null value after string).".format(StartingPoint, HitNullPoint))
  53.     print("Actual relative cursor location {0}.".format(HitNullPoint - StartingPoint))
  54.     if (HitNullPoint - StartingPoint) % SAHTDataOffset == 0:
  55.         pass
  56.     else:
  57.         NextHashPoint = SAHTDataOffset - ((HitNullPoint - StartingPoint) % SAHTDataOffset)
  58.         print("The distance of bytes to the next hash is {0}.".format(NextHashPoint))
  59.         SAHTFile.seek(HitNullPoint + NextHashPoint)
  60.     print("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement