Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from struct import *
- FileIn = "HashTable.saht"
- SAHTFile = open(FileIn, mode = 'br', buffering = 0)
- SAHTHeader = unpack('<4s', SAHTFile.read(4))[0]
- SAHTFileSize = unpack('<i', SAHTFile.read(4))[0]
- SAHTDataOffset = unpack('<i', SAHTFile.read(4))[0]
- SAHTNrEntries = unpack('<i', SAHTFile.read(4))[0]
- print("The Header file is {0}.".format(SAHTHeader))
- print("The File Size is {0}.".format(SAHTFileSize))
- print("The Data Offset is {0}".format(SAHTDataOffset))
- if SAHTNrEntries is 1:
- print("The Number Entry is {0}.".format(SAHTNrEntries))
- else:
- print("The Number Entries are {0}".format(SAHTNrEntries))
- print("")
- print("")
- for i in range(0,SAHTNrEntries):
- StartingPoint = SAHTFile.tell()
- SAHTHash = hex(unpack('<I', SAHTFile.read(4))[0])
- print("The Hash is {0}.".format(SAHTHash))
- Buffer = unpack('<1s', SAHTFile.read(1))[0]
- SAHTString = b''
- SAHTString += Buffer
- while Buffer != b'\x00':
- # My idea behind this code is to keep unpacking the
- # Buffer until the Buffer hit a Null (or None in python)
- # value. Then the program would stop doing this. But, becuase
- # of how the code works, it also factors in a Null, however the if
- # statement catches this. Just keep this in mind when using .tell()
- Buffer = unpack('<1s', SAHTFile.read(1))[0]
- if Buffer != b'\x00' and Buffer != b'/':
- SAHTString += Buffer
- elif Buffer == b'/':
- print("The fake 'directory' is {0}.".format(SAHTString))
- Buffer = unpack('<1s', SAHTFile.read(1))[0]
- SAHTString = b''
- if Buffer != b'\x00':
- SAHTString += Buffer
- else:
- pass
- else:
- pass
- print("The file name is {0}.".format(SAHTString))
- HitNullPoint = SAHTFile.tell()
- print("The actual range of data value is from {0} (Start at Hash Value) "
- "to {1} (First null value after string).".format(StartingPoint, HitNullPoint))
- print("Actual relative cursor location {0}.".format(HitNullPoint - StartingPoint))
- if (HitNullPoint - StartingPoint) % SAHTDataOffset == 0:
- pass
- else:
- NextHashPoint = SAHTDataOffset - ((HitNullPoint - StartingPoint) % SAHTDataOffset)
- print("The distance of bytes to the next hash is {0}.".format(NextHashPoint))
- SAHTFile.seek(HitNullPoint + NextHashPoint)
- print("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement