mirror of
https://github.com/thecompu/Driv3rs.git
synced 2025-01-23 04:30:03 +00:00
Major rewrite of the logic and lists and dictionaries to hold found values.
This commit is contained in:
parent
55e88bf8ae
commit
a4510e2d62
65
3Slurp.py
65
3Slurp.py
@ -3,14 +3,16 @@ import os
|
||||
|
||||
def readUnpack(bytes, **options):
|
||||
if options.get("type") == 't':
|
||||
print 'DEBUG: In t'
|
||||
#print 'DEBUG: In t'
|
||||
SOS = SOSfile.read(bytes)
|
||||
return unpack('< %ss' % bytes, SOS)
|
||||
return unpack('%ss' % bytes, SOS)
|
||||
|
||||
if options.get("type") == 'b':
|
||||
print 'DEBUG: In b'
|
||||
#print 'DEBUG: In b', bytes
|
||||
SOS = SOSfile.read(bytes)
|
||||
#print 'DEBUG: In b2', bytes, SOS
|
||||
offset_unpacked = unpack ('< H', SOS)
|
||||
#print 'DEBUG: In b3', bytes, SOS
|
||||
return int('.'.join(str(x) for x in offset_unpacked))
|
||||
|
||||
#Clear SCREEN
|
||||
@ -29,29 +31,52 @@ else:
|
||||
print "This is not a proper SOS file"
|
||||
exit()
|
||||
|
||||
|
||||
### 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 = readUnpack(2, type = 'b')
|
||||
print "The first offset value is", hex(offset)
|
||||
# Read immediate two bytes after SOS DRVR to establish first rel_offset value.
|
||||
rel_offset = readUnpack(2, type = 'b')
|
||||
print "The first relative offset value is", rel_offset, hex(rel_offset)
|
||||
print SOSfile.tell()
|
||||
drivers = 0 ## This is to keep a running total of drivers.
|
||||
drivers_dict = dict() ## Intialize a dictionary to hold the drivers.
|
||||
drivers_list=[] ## Initialize a list to hold dictionaries.
|
||||
|
||||
### Begin an indefinite loop that will come around until we
|
||||
### encounter FF which indicates the last driver.
|
||||
### find all major drivers. FFFF means end of drivers.
|
||||
|
||||
while offset != 65535 :
|
||||
SOSfile.seek(offset,1)
|
||||
## print "DEBUG: This is our new position in the file: ", hex(SOSfile.tell())
|
||||
offset = readUnpack(2, type = 'b')
|
||||
if offset == 0 : ## Check to see if we're at the beginning of a new driver.
|
||||
drivers = drivers + 1 ## And add to count of found drivers.
|
||||
offset = readUnpack(2, type = 'b')
|
||||
drivers_dict ['Driver_'+str(drivers)] = dict([('Offset', hex(offset))])
|
||||
## print 'DEBUG: New offset is: ' , hex(offset)
|
||||
loop = True
|
||||
while loop : ## as long as no FF FF are encountered
|
||||
driver = {} ## Intialize a dictionary to hold vaules as we loop.
|
||||
SOSfile.seek(rel_offset,1) ## jump to next location. a + 522 = 52c
|
||||
driver['location'] = SOSfile.tell() ## add to driver dictionary 52c
|
||||
rel_offset = readUnpack(2, type = 'b') ## 0000 comment length
|
||||
if rel_offset == 0xFFFF:
|
||||
loop = False
|
||||
else :
|
||||
drivers_list.append(driver) ## add to drivers_list list
|
||||
SOSfile.seek(rel_offset,1) ## 52e + 0000 = 52e
|
||||
rel_offset = readUnpack(2, type = 'b') # result: 4a4 pos: 530
|
||||
SOSfile.seek(rel_offset,1) # 530 + 4a4 = 9d4
|
||||
rel_offset = readUnpack(2, type = 'b') # be
|
||||
|
||||
|
||||
#Loop to enter each driver to grab information from the DIB (Driver Information Block)
|
||||
|
||||
for i in range(0,len(drivers_list)):
|
||||
# print drivers_list[i], hex(drivers_list[i]['location'])
|
||||
SOSfile.seek(drivers_list[i]['location'],0)
|
||||
rel_offset = readUnpack(2, type = 'b') # will get comment length 0000
|
||||
drivers_list[i]['comment_len'] = rel_offset #store comment length
|
||||
if rel_offset != 0: #if comment length is not 0000
|
||||
comment_len = rel_offset # place length in comment_len var
|
||||
comment_txt = readUnpack(comment_len, type = 't') # comment_len bytes as text
|
||||
drivers_list[i]['comment_txt'] = comment_txt # place comment in dictionary
|
||||
else:
|
||||
drivers_list[i]['comment_txt'] = '' # else enter comment as nothing
|
||||
SOSfile.seek(rel_offset,1) # go to link field
|
||||
lnk_pointer = readUnpack(2, type = 'b') # Grab distance to next DIB.
|
||||
SOSfile.seek(2,1) # Skip Entry field
|
||||
|
||||
print drivers_list
|
||||
|
||||
SOSfile.close()
|
||||
print 'Total drivers encountered: ', drivers
|
||||
print drivers_dict
|
||||
|
Loading…
x
Reference in New Issue
Block a user