Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import struct
- import glob
- import sys
- hdr_index = [] #Read the index file data
- with open('hdrspec.csv','rb') as f:
- for line in f:
- line = line.translate(None,'\r\n')
- line = line.split(',')
- line[1] = int(line[1])
- hdr_index.append(line)
- def dat_pack(filename):
- for filename1, hdrlen in hdr_index: #Find header length
- if filename1 == filename + '.DAT':
- break
- else:
- print 'File not in index.'
- quit()
- with open(filename + '.DAT','wb') as f: #Write new .DAT file
- f.write('LB DAT\x1A\x00') #Secret code
- f.write(struct.pack('<I',hdrlen)) #Header length
- f.write('\x00'*4) #Format spec
- start_of_data = hdrlen*4 + 0x14 #Data start position
- pos = start_of_data #Position counter
- f.write(struct.pack('<I',start_of_data)) #Write 1st file location
- for f1 in glob.glob(filename + '\\' + '*.dat'): #Loop thru .dat files
- pos += os.path.getsize(f1) #Increment position counter
- f.write(struct.pack('<I',pos)) #Write position of next file
- while f.tell() < start_of_data: #Write 00 until start of data
- f.write('\x00'*4)
- for f1 in glob.glob(filename + '\\' + '*.dat'): #Loop again
- with open(f1,'rb') as g: #Write each file in succession
- f.write(g.read())
- dat_pack(sys.argv[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement