Beispiel #1
0
	def load_fsb(self, data):
		fsb = fsb5.load(data)
		ext = fsb.get_sample_extension()

		self.debug('\nHeader:')
		self.debug('\tVersion: 5.%s' % (fsb.header.version))
		self.debug('\tSample count: %i' % (fsb.header.numSamples))
		self.debug('\tNamed samples: %s' % ('Yes' if fsb.header.nameTableSize else 'No'))
		self.debug('\tSound format: %s' % (fsb.header.mode.name.capitalize()))

		return fsb, ext
Beispiel #2
0
    def load_fsb(self, data):
        fsb = fsb5.load(data)
        ext = fsb.get_sample_extension()

        self.debug('\nHeader:')
        self.debug('\tVersion: 5.%s' % (fsb.header.version))
        self.debug('\tSample count: %i' % (fsb.header.numSamples))
        self.debug('\tNamed samples: %s' %
                   ('Yes' if fsb.header.nameTableSize else 'No'))
        self.debug('\tSound format: %s' % (fsb.header.mode.name.capitalize()))

        return fsb, ext
Beispiel #3
0
def ProcessAudioClip(data, destFolder):
    # extract samples
    bindata = data.data
    index = 0
    while bindata:
        fsb = fsb5.load(bindata)
        ext = fsb.get_sample_extension()
        bindata = bindata[fsb.raw_size:]
        for sampleName, sampleData in readSamplesFromFSB5(fsb):
            outputFile = getAvailableFileName(destFolder,
                                              data.name + "--" + sampleName,
                                              ext)
            with open(outputFile, 'wb') as fh:
                fh.write(sampleData)
        index += 1
Beispiel #4
0
def extract_asset_item(pid, obj, dist):
    data = obj.read()
    if obj.type == "AudioClip":
        print(obj.type, data.name)
        bindata = data.data
        while bindata:
            fsb = fsb5.load(bindata)
            ext = fsb.get_sample_extension()
            bindata = bindata[fsb.raw_size:]
            for filename, buffer in read_samples_from_fsb(fsb):
                filename = data.name + "--" + filename + '.' + ext
                save_text(filename, dist, buffer)

    elif obj.type == "Texture2D":
        print(obj.type, data.name, "[" + str(data.format) + "]")
        filename = data.name + ".png"
        if data.format in ETC_SERIES:
            bindata = build_pkm_header(data.width, data.height,
                                       data.format) + data.image_data
            pkmname = data.name + ".pkm"
            pkmpath = os.path.join(dist, pkmname)
            save_binary(pkmname, dist, bindata)
            if os.path.isfile(pkmpath):
                os.system("%s %s %s" % (ETCPACK, pkmpath, dist))
                os.remove(pkmpath)
            ppmpath = os.path.join(dist, data.name + ".ppm")
            if os.path.isfile(ppmpath):
                image = Image.open(ppmpath)
                os.remove(ppmpath)
        else:
            image = data.image
        if not image:
            print("WARNING: %s is an empty image" % filename)
            return
        image = image.transpose(Image.ROTATE_180)
        image = image.transpose(Image.FLIP_LEFT_RIGHT)  # 左右对换
        if not os.path.isdir(dist):
            os.makedirs(dist)
        image.save(os.path.join(dist, filename), format='png')

    elif obj.type == "MovieTexture":
        print(obj.type, data.name)
        filename = data.name + ".ogv"
        save_binary(filename, dist, data.movie_data)

    # elif obj.type=="Shader":
    # 	print(obj.type,":",data.name)
    # 	filename=data.name+".cg"
    # 	putFile(filename,savepath,data.script)

    elif obj.type == "Mesh":
        print(obj.type, ":", data.name)
        try:
            meshdata = unitypack.export.OBJMesh(data).export()
            filename = data.name + ".obj"
            save_binary(filename, dist, meshdata)
        except NotImplementedError as e:
            print("WARNING: Could not extract %r (%s)" % (data, e))
            meshdata = pickle.dumps(data._obj)
            filename = data.name + ".Mesh.pickle"
            save_binary(filename, dist, meshdata)

    elif obj.type == "Font":
        print(obj.type, ":", data.name)
        filename = data.name + ".ttf"
        save_binary(filename, dist, data.data)

    elif obj.type == "TextAsset":
        print(obj.type, ":", data.name)
        filename = data.name
        if isinstance(data.script, bytes):
            save_binary(filename, dist, data.script, mode="wb")
        else:
            save_text(filename, dist, data.script, mode="w", encoding="utf-8")
    def handleFile(self, filepath, filedir):
        subdirname = filepath.replace(self.apkExtractedPath, "")
        filedirpath = filedir.replace(self.apkExtractedPath, "")
        while (subdirname[0] == "/" or subdirname[0] == "\\"):
            subdirname = subdirname[1:]
        if (filedirpath == ""):
            filedirpath = "."
        while (filedirpath[0] == "/" or filedirpath[0] == "\\"):
            filedirpath = filedirpath[1:]
        savepath = os.path.join(self.assetsExtractTo, subdirname)
        os.makedirs(savepath, exist_ok=True)
        filedirpath = os.path.join(self.assetsExtractTo, filedirpath)
        os.makedirs(filedirpath, exist_ok=True)
        # savepath=os.path.dirname(filepath);
        with open(filepath, 'rb') as file:
            bundle = unitypack.load(file)
            for asset in bundle.assets:
                for id, obj in asset.objects.items():
                    try:
                        data = obj.read()

                        if obj.type == "AudioClip":
                            print(obj.type, ":", data.name)
                            # extract samples
                            bindata = data.data
                            index = 0
                            while bindata:
                                fsb = fsb5.load(bindata)
                                ext = fsb.get_sample_extension()
                                bindata = bindata[fsb.raw_size:]
                                for sampleName, sampleData in readSamplesFromFSB5(
                                        fsb):
                                    filenameWrite = data.name + "--" + sampleName + '.' + ext
                                    putFile(filenameWrite, savepath,
                                            sampleData)
                                index += 1

                        elif obj.type == "Texture2D":
                            print(obj.type + "[" + str(data.format) + "]:",
                                  data.name)
                            filename = data.name + ".png"
                            if data.format in ETC_SERIES:
                                bindata = getPKMHeader(
                                    data.width, data.height,
                                    data.format) + data.image_data
                                putFile('temp.pkm', currentWorkDir, bindata)
                                subprocess.call([
                                    "./etcpack", "./temp.pkm", currentWorkDir
                                ])
                                image = Image.open('./temp.ppm')
                            else:
                                image = data.image
                                if image is None:
                                    print("WARNING: %s is an empty image" %
                                          (filename))
                                    continue
                            img = ImageOps.flip(image)
                            output = io.BytesIO()
                            img.save(output, format="png")
                            putFile(filename, savepath, output.getvalue())

                        elif obj.type == "MovieTexture":
                            print(obj.type, ":", data.name)
                            filename = data.name + ".ogv"
                            putFile(filename, savepath, data.movie_data)

                        # elif obj.type=="Shader":
                        # 	print(obj.type,":",data.name)
                        # 	filename=data.name+".cg"
                        # 	putFile(filename,savepath,data.script)

                        elif obj.type == "Mesh":
                            print(obj.type, ":", data.name)
                            try:
                                meshdata = unitypack.export.OBJMesh(d).export()
                                filename = data.name + ".obj"
                                putFile(filename, savepath, meshdata)
                            except NotImplementedError as e:
                                print("WARNING: Could not extract %r (%s)" %
                                      (d, e))
                                meshdata = pickle.dumps(data._obj)
                                filename = data.name + ".Mesh.pickle"
                                putFile(filename, savepath, meshdata)

                        elif obj.type == "Font":
                            print(obj.type, ":", data.name)
                            filename = data.name + ".ttf"
                            putFile(filename, savepath, data.data)

                        elif obj.type == "TextAsset":
                            print(obj.type, ":", data.name)
                            # toSavePath=savepath
                            toSavePath = filedirpath
                            if isinstance(data.script, bytes):
                                filename, mode = data.name, "wb"
                                putFile(filename,
                                        toSavePath,
                                        data.script,
                                        mode=mode)
                            else:
                                filename, mode = data.name, "w"
                                putTextFile(filename,
                                            toSavePath,
                                            data.script,
                                            mode=mode,
                                            encoding="utf-8")
                    except Exception as e:
                        print("WARNING: Error while processing %r (%s)" %
                              (filepath, e))
def handle_fsb(data):
    fsb = fsb5.load(data)
    for sample in fsb.samples:
        # assume 1 sample
        return fsb.rebuild_sample(sample).tobytes()