示例#1
0
文件: CBMD.py 项目: kyapp69/3DSkit
 def extract(self, data):
     offsets = {
         i: off
         for i, off in enumerate(self.regionoffsets) if off != 0
     }
     data.seek(self.commonoffset)
     if len(offsets) == 0:
         indata = BytesIO(data.read())
     else:
         indata = BytesIO(data.read(sorted(list(offsets.values()))[0]))
     filedata = BytesIO()
     compress.decompress(indata, filedata, compress.recognize(indata),
                         self.verbose)
     filedata.seek(0)
     bwrite(filedata.read(), self.outdir + 'common.cgfx')
     sortkeys = sorted(list(offsets.keys()))
     for i in offsets.keys():
         if i != max(sortkeys):
             start = offsets[i]
             end = sortkeys[sortkeys.index(i) + 1]
             data.seek(start)
             indata = BytesIO(data.read(end - start))
         else:
             data.seek(offsets[i])
             indata = BytesIO(data.read())
         filedata = BytesIO()
         compress.decompress(indata, filedata, compress.recognize(indata),
                             self.verbose)
         filedata.seek(0)
         bwrite(filedata.read(), OUT_NAMES[i])
示例#2
0
 def extract(self, data):
     offsets = {
         i: off
         for i, off in enumerate(self.regionoffsets) if off != 0
     }
     if len(offsets) == 0:
         filedata = data[self.commonoffset:]
     else:
         filedata = data[self.commonoffset:self.commonoffset +
                         sorted(list(offsets.values()))[0]]
     filedata = compress.decompress(filedata, compress.recognize(filedata),
                                    self.byteorder)
     bwrite(filedata, self.outdir + 'common.cgfx')
     sortkeys = sorted(list(offsets.keys()))
     for i in offsets.keys():
         if i != max(sortkeys):
             start = offsets[i]
             end = sortkeys[sortkeys.index(i) + 1]
             filedata = data[start:end]
         else:
             filedata = data[offsets[i]:]
         filedata = compress.decompress(filedata,
                                        compress.recognize(filedata),
                                        self.byteorder)
         bwrite(filedata, OUT_NAMES[i])
示例#3
0
def extract_files(filename, isbigendian, givenformat, verbose, opts):
    endian = '>' if isbigendian else '<'
    if os.path.isdir(filename):
        filenames = []
        for p, d, f in os.walk(filename):
            for name in f:
                filenames.append(os.path.join(p, name))
    else:
        filenames = [filename]
    for filename in filenames:
        print('\n--------%s--------' % filename)
        try:
            file = open(filename, 'rb')
        except FileNotFoundError:
            error.FileNotFoundError('File %s does not exist' % filename)
        format = unpack.recognize_file(file, givenformat)
        file.seek(0)
        if format is None:
            format = unpack.recognize_filename(filename, givenformat)
        if format not in unpack.SKIP_DECOMPRESSION:
            comp = compress.recognize(file)
            if comp == 0:
                if len(filenames) > 1:
                    err = error.InvalidInputWarning
                else:
                    err = error.InvalidInputError
                err("The given file is empty")
                continue
            if comp is not None:
                print('Compression: %s' % comp)
                print('Decompressing...')
                out = BytesIO()
                compress.decompress(file, out, comp, verbose)
                file.close()
                file = out
                print('Decompressed')
            else:
                print('No compression')
        else:
            print('No compression')
        format = unpack.recognize_file(file, givenformat)
        if format is None:
            format = unpack.recognize_filename(filename, givenformat)
        if format is None:  #still
            if len(filenames) > 1:
                err = error.UnrecognizedFormatWarning
            else:
                err = error.UnrecognizedFormatError
            err('Unrecognized format')
            continue
        print('%s file found' % format)
        print('Extracting...')
        unpack.extract(filename, file, format, endian, verbose, opts)
        print('Extracted')
示例#4
0
 def extract(self):
     data = self.data
     ptr = self.ptr
     for i, entry in enumerate(self.fatb):
         if entry.isfolder:
             outpath = self.outdir + str(i) + os.path.sep
             try:
                 os.mkdir(outpath)
             except:
                 pass
             os.makedirs(outpath)
             for j, subentry in enumerate(entry.subentries):
                 start = subentry.start + self.dataoffset
                 end = start + subentry.length
                 filedata = data[start:end]
                 comp = compress.recognize(filedata)
                 ext = get_ext(filedata)
                 outname = outpath + str(j) + ext
                 if comp == 'LZ11':
                     filedata = compress.decompress(filedata, comp,
                                                    self.byteorder)
                     ext = get_ext(filedata)
                     outname = outpath + 'dec_' + str(j) + ext
                 bwrite(filedata, outname)
         else:
             subentry = entry.subentries[0]
             start = subentry.start + self.dataoffset
             end = start + subentry.length
             filedata = data[start:end]
             comp = compress.recognize(filedata)
             ext = get_ext(filedata)
             outname = self.outdir + str(i) + ext
             if comp == 'LZ11':
                 filedata = compress.decompress(filedata, comp)
                 ext = get_ext(filedata)
                 outname = self.outdir + 'dec_' + str(i) + ext
             bwrite(filedata, outname)
示例#5
0
文件: 3DSkit.py 项目: Tyulis/3DSkit
def decompress_file(inname, outname, verbose):
	file = open(inname, 'rb')
	if outname is None:
		sname = list(inname.partition('.'))
		sname[0] += '_dec'
		outname = (''.join(sname)).replace('.cmp', '')
	out = open(outname, 'wb+')
	compression = compress.recognize(file)
	if compression is None:
		error.UnsupportedCompressionError('This file is not compressed, or 3DSkit currently does not support its compression')
	else:
		print('Compression: %s' % compression)
	print('Decompression...')
	compress.decompress(file, out, compression, verbose)
	file.close()
	print('Decompressed!')
示例#6
0
文件: GARC.py 项目: kyapp69/3DSkit
 def extract(self):
     data = self.data
     for i, entry in enumerate(self.fatb):
         if entry.isfolder:
             outpath = self.outdir + str(i) + os.path.sep
             try:
                 os.mkdir(outpath)
             except:
                 pass
             for j, subentry in enumerate(entry.subentries):
                 if subentry is None:
                     continue
                 start = subentry.start + self.dataoffset
                 data.seek(start)
                 filedata = BytesIO(data.read(subentry.length))
                 if not self.skipdec:
                     comp = compress.recognize(filedata)
                     filedata.seek(0)
                     ext = get_ext(filedata)
                     outname = outpath + str(j) + ext
                     if comp == 'LZ11':
                         outname = outpath + 'dec_' + str(j) + ext
                         out = open(outname, 'wb+')
                         result = compress.decompress(
                             filedata, out, comp, self.verbose)
                         if result == 901:  #Ugly
                             outname = outpath + str(j) + ext
                             print('For %s' % outname)
                             filedata.seek(0)
                             bwrite(filedata.read(), outname)
                     else:
                         ext = get_ext(filedata)
                         outname = outpath + str(j) + ext
                         bwrite(filedata.read(), outname)
                 else:
                     ext = get_ext(filedata)
                     outname = outpath + str(j) + ext
                     bwrite(filedata.read(), outname)
         else:
             subentry = entry.subentries[0]
             start = subentry.start + self.dataoffset
             data.seek(start)
             filedata = BytesIO(data.read(subentry.length))
             if not self.skipdec:
                 comp = compress.recognize(filedata)
                 filedata.seek(0)
                 ext = get_ext(filedata)
                 outname = self.outdir + str(i) + ext
                 if comp == 'LZ11':
                     outname = self.outdir + 'dec_%d%s' % (i, ext)
                     out = open(outname, 'wb+')
                     result = compress.decompress(filedata, out, comp,
                                                  self.verbose)
                     out.close()
                     if result == 901:  #Ugly
                         os.remove(outname)
                         outname = self.outdir + str(i) + ext
                         print('For %s' % outname)
                         filedata.seek(0)
                         bwrite(filedata.read(), outname)
                 else:
                     ext = get_ext(filedata)
                     outname = self.outdir + str(i) + ext
                     bwrite(filedata.read(), outname)
             else:
                 ext = get_ext(filedata)
                 outname = self.outdir + str(i) + ext
                 bwrite(filedata.read(), outname)