2015-07-31 16:41:03 +00:00
|
|
|
from struct import unpack
|
|
|
|
import os
|
|
|
|
|
2015-09-12 16:09:03 +00:00
|
|
|
def tup2int(tup):
|
|
|
|
return int('.' . join(str(x) for x in tup))
|
|
|
|
|
|
|
|
def tup2int():
|
|
|
|
SOS = SOSfile.read(2)
|
|
|
|
offset_unpacked = unpack ('< H', SOS)
|
|
|
|
offset = int('.'.join(str(x) for x in offset_unpacked))
|
|
|
|
print 'DEBUG: Inside function. Offset is:', hex(offset)
|
2015-09-07 17:24:01 +00:00
|
|
|
return offset
|
|
|
|
|
2015-07-31 16:41:03 +00:00
|
|
|
#Clear SCREEN
|
|
|
|
print("\033c");
|
|
|
|
|
|
|
|
#Is File a SOS DRIVER file?
|
2015-09-07 17:24:01 +00:00
|
|
|
|
2015-07-31 16:41:03 +00:00
|
|
|
SOSfile = open('SOSCFFA.DRIVER', 'rb')
|
2015-09-12 16:09:03 +00:00
|
|
|
SOS = SOSfile.read(8)
|
|
|
|
filetype = unpack('< 8s', SOS)
|
2015-09-07 17:24:01 +00:00
|
|
|
|
|
|
|
if 'SOS DRVR' in filetype:
|
|
|
|
print "This is a proper SOS file."
|
2015-09-12 16:09:03 +00:00
|
|
|
print "Filetype is: %s." % (filetype)
|
2015-09-07 17:24:01 +00:00
|
|
|
else:
|
|
|
|
print "This is not a proper SOS file"
|
2015-07-31 16:41:03 +00:00
|
|
|
|
2015-09-12 16:09:03 +00:00
|
|
|
def readUnpackAndint(bytes):
|
|
|
|
SOS = SOSfile.read(bytes)
|
|
|
|
offset_unpacked = unpack ('< H', SOS)
|
|
|
|
return int('.'.join(str(x) for x in offset_unpacked))
|
|
|
|
|
|
|
|
### At this point, we need the first offset to tell us where to jump to
|
|
|
|
### find the first actual driver.
|
|
|
|
|
|
|
|
# Read immediate two bytes after SOS DRVR to establish first offset value.
|
|
|
|
offset = readUnpackAndint(2)
|
|
|
|
print "The first offset value is", hex(offset)
|
|
|
|
|
|
|
|
### Now we have the offset needed to jump to the first driver. Let's seek
|
|
|
|
### to that driver using the offset. This is our first jump.
|
|
|
|
|
2015-07-31 16:41:03 +00:00
|
|
|
SOSfile.seek(offset,1)
|
2015-09-12 16:09:03 +00:00
|
|
|
print "This is our new position in the file: ", hex(SOSfile.tell())
|
|
|
|
offset = readUnpackAndint(2)
|
|
|
|
print 'New offset is: ' , hex(offset)
|
|
|
|
|
|
|
|
### I will establish an indefinite loop that will come around until we
|
|
|
|
### encounter FF which indicates the last driver. For now, I am manually
|
|
|
|
### looping to check logic.
|
|
|
|
|
|
|
|
while offset != 65535 :
|
|
|
|
SOSfile.seek(offset,1)
|
|
|
|
print "This is our new position in the file: ", hex(SOSfile.tell())
|
|
|
|
offset = readUnpackAndint(2)
|
|
|
|
print 'New offset is: ' , hex(offset)
|
2015-07-31 16:41:03 +00:00
|
|
|
|
|
|
|
SOSfile.close()
|