Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2015
542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.84 KB | None | 0 0
  1. import os,sys,struct,zlib
  2.  
  3. def get_data(filename):
  4.     totalbytes = os.path.getsize(filename)
  5.     infile = open(filename, 'rb')
  6.     totalfiledata = infile.read(totalbytes)
  7.     return totalfiledata
  8.  
  9. if __name__ == '__main__':
  10.     for filename in os.listdir('.'):
  11.         if filename.find('.arc') != -1:
  12.             print 'Extracting %s' % filename
  13.             filedata = get_data(filename)
  14.             filecnt = struct.unpack('<H',filedata[0x6:0x8])[0]
  15.             if not os.path.isdir(filename.rsplit('.',1)[0]):
  16.                 os.mkdir(filename.rsplit('.',1)[0])
  17.  
  18.             for i in range(0xc,0xc+(filecnt*0x50),0x50):
  19.                 filename1 = filedata[i:filedata.find('\x00',i)]
  20.                 #print 'Extracting %s' % filename1
  21.                 filelen = struct.unpack('<I',filedata[i+0x44:i+0x48])[0]
  22.                 filedecomplen = struct.unpack('<H',filedata[i+0x48:i+0x4a])[0]
  23.                 filedecomplen = filedecomplen << 8
  24.                 filedecomplen = filedecomplen | struct.unpack('<B',filedata[i+0x4a:i+0x4b])[0]
  25.                 filepos = struct.unpack('<I',filedata[i+0x4c:i+0x50])[0]
  26.  
  27.                 file = filedata[filepos:filepos+filelen]
  28.                 if filelen != filedecomplen:
  29.                     file = zlib.decompress(file)
  30.  
  31.                 filepath = filename1.split('\\')
  32.                 currpath = filename.rsplit('.',1)[0]
  33.                                      
  34.                 for i in range(0,len(filepath)-1):
  35.                     if filepath[i] != '':
  36.                         if not os.path.isdir(currpath + '\\' + filepath[i]):
  37.                             os.mkdir(currpath + '\\' + filepath[i])
  38.                     currpath += '\\' + filepath[i]
  39.  
  40.  
  41.                 outfile = open(currpath + '\\' + filepath[len(filepath)-1],'wb')
  42.                 outfile.write(file)
  43.                 outfile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement