Esempio n. 1
0
def	write_psb(mypsb):
	filename = options.output

	if os.path.isfile(filename):
		print("File '%s' exists, not over-writing" % filename)
		return

	if not options.quiet:
		print("Writing '%s'" % filename)

	# Pack our PSB object into the on-disk format
	psb_data0 = mypsb.pack()
	if options.debug:
		open(filename + '.0', 'wb').write(psb_data0)	# raw

	if filename.endswith('.psb'):
		# Write out the data as-is
		open(filename, 'wb').write(psb_data0)

	elif filename.endswith('.psb.m'):
		# Compress the PSB data
		psb_data1 = psb.compress_data(psb_data0)
		if options.debug:
			open(filename + '.1', 'wb').write(psb_data1)	# compressed

		# Encrypt the PSB data
		if options.key:
			psb_data2 = psb.unobfuscate_data(psb_data1, options.key)
		else:
			psb_data2 = psb.unobfuscate_data(psb_data1, filename)
		if options.debug:
			open(filename + '.2', 'wb').write(psb_data2)	# compressed/encrypted

		# Write out the compressed/encrypted PSB data
		open(filename, 'wb').write(psb_data2)
Esempio n. 2
0
def	load_from_psb(psb_filename):

	if not options.quiet:
		print("Reading '%s'" % psb_filename)

	# Read in the encrypted/compressed psb data
	psb_data2 = bytearray(open(psb_filename, 'rb').read())

	# Decrypt the psb data using the filename, or --key if provided.
	if options.key:
		psb_data1 = psb.unobfuscate_data(psb_data2, options.key)
	else:
		psb_data1 = psb.unobfuscate_data(psb_data2, psb_filename)
	if options.debug:
		open(psb_filename + '.1', 'wb').write(psb_data1)	# compressed

	if psb_filename.endswith('.psb'):
		# ".psb" files are not compressed, use the decrypted data
		psb_data0 = psb_data2
	else:
		# Uncompress the psb data
		psb_data0 = psb.uncompress_data(psb_data1)
		if options.debug:
			open(psb_filename + '.0', 'wb').write(psb_data0)	# raw

	# Check we have a PSB header
	header = psb.HDRLEN()
	header.unpack(psb.buffer_unpacker(psb_data0))
	if header.signature != b'PSB\x00':
		print("PSB header not found")
		return

	# Unpack the PSB structure
	mypsb = psb.PSB()
	mypsb.unpack(psb_data0)

	# Get the base filename without any .psb.m
	# '.psb.m' isn't a single extension :(
	if psb_filename.endswith('.psb'):
		base_filename = psb_filename[:-len('.psb')]
	elif psb_filename.endswith('.psb.m'):
		base_filename = psb_filename[:-len('.psb.m')]
	else:
		return


	# Read in the alldata.bin file if it exists
	bin_filename  = base_filename + '.bin'
	if os.path.isfile(bin_filename):
		if not options.quiet:
			print("Reading file %s" % bin_filename)
		bin_data = bytearray(open(bin_filename, 'rb').read())

		# Split the ADB data into each subfile.
		# The data is in compressed/encrypted form
		mypsb.split_subfiles(bin_data)

	return mypsb
Esempio n. 3
0
def load_from_psb(psb_filename):

    if not options.quiet:
        print("Reading '%s'" % psb_filename)

    # Read in the encrypted/compressed psb data
    psb_data2 = bytearray(open(psb_filename, 'rb').read())

    # Decrypt the psb data using the filename, or --key if provided.
    if options.key:
        psb_data1 = psb.unobfuscate_data(psb_data2, options.key)
    else:
        psb_data1 = psb.unobfuscate_data(psb_data2, psb_filename)
    if options.debug:
        open(psb_filename + '.1', 'wb').write(psb_data1)  # compressed

    if psb_filename.endswith('.psb'):
        # ".psb" files are not compressed, use the decrypted data
        psb_data0 = psb_data2
    else:
        # Uncompress the psb data
        psb_data0 = psb.uncompress_data(psb_data1)
        if options.debug:
            open(psb_filename + '.0', 'wb').write(psb_data0)  # raw

    # Check we have a PSB header
    header = psb.HDRLEN()
    header.unpack(psb.buffer_unpacker(psb_data0))
    if header.signature != b'PSB\x00':
        print("PSB header not found")
        return

    # Unpack the PSB structure
    mypsb = psb.PSB()
    mypsb.unpack(psb_data0)

    # Get the base filename without any .psb.m
    # '.psb.m' isn't a single extension :(
    if psb_filename.endswith('.psb'):
        base_filename = psb_filename[:-len('.psb')]
    elif psb_filename.endswith('.psb.m'):
        base_filename = psb_filename[:-len('.psb.m')]
    else:
        return

    # Read in the alldata.bin file if it exists
    bin_filename = base_filename + '.bin'
    if os.path.isfile(bin_filename):
        if not options.quiet:
            print("Reading file %s" % bin_filename)
        bin_data = bytearray(open(bin_filename, 'rb').read())

        # Split the ADB data into each subfile.
        # The data is in compressed/encrypted form
        mypsb.split_subfiles(bin_data)

    return mypsb
Esempio n. 4
0
def	write_psb(mypsb, filename):
	if not mypsb or not filename:
		return

	if os.path.isfile(filename):
		print("File '%s' exists, not over-writing" % filename)
		return

	if global_vars.verbose:
		print("Writing '%s'" % filename)

	# Pack our PSB object into the on-disk format
	psb_data0 = mypsb.pack()
	if global_vars.verbose > global_vars.debug_level:
		open(filename + '.0', 'wb').write(psb_data0)	# raw

	if filename.endswith('.psb'):
		# Write out the data as-is
		open(filename, 'wb').write(psb_data0)

	elif filename.endswith('.psb.m'):
		# Compress the PSB data
		psb_data1 = psb.compress_data(psb_data0)
		if global_vars.verbose > global_vars.debug_level:
			open(filename + '.1', 'wb').write(psb_data1)	# compressed

		# Encrypt the PSB data using the filename as the key
		psb_data2 = psb.unobfuscate_data(psb_data1, filename)
		if global_vars.verbose > global_vars.debug_level:
			open(filename + '.2', 'wb').write(psb_data2)	# compressed/encrypted

		# Write out the compressed/encrypted PSB data
		open(filename, 'wb').write(psb_data2)
def write_psb(mypsb, filename):
    if not mypsb or not filename:
        return

    if os.path.isfile(filename):
        print("File '%s' exists, not over-writing" % filename)
        return

    if global_vars.verbose:
        print("Writing '%s'" % filename)

    # Pack our PSB object into the on-disk format
    psb_data0 = mypsb.pack()
    if global_vars.verbose > global_vars.debug_level:
        open(filename + '.0', 'wb').write(psb_data0)  # raw

    if filename.endswith('.psb'):
        # Write out the data as-is
        open(filename, 'wb').write(psb_data0)

    elif filename.endswith('.psb.m'):
        # Compress the PSB data
        psb_data1 = psb.compress_data(psb_data0)
        if global_vars.verbose > global_vars.debug_level:
            open(filename + '.1', 'wb').write(psb_data1)  # compressed

        # Encrypt the PSB data using the filename as the key
        psb_data2 = psb.unobfuscate_data(psb_data1, filename)
        if global_vars.verbose > global_vars.debug_level:
            open(filename + '.2',
                 'wb').write(psb_data2)  # compressed/encrypted

        # Write out the compressed/encrypted PSB data
        open(filename, 'wb').write(psb_data2)
Esempio n. 6
0
def write_psb(mypsb):
    filename = options.output

    if os.path.isfile(filename):
        print("File '%s' exists, not over-writing" % filename)
        return

    if not options.quiet:
        print("Writing '%s'" % filename)

    # Pack our PSB object into the on-disk format
    psb_data0 = mypsb.pack()
    if options.debug:
        open(filename + '.0', 'wb').write(psb_data0)  # raw

    if filename.endswith('.psb'):
        # Write out the data as-is
        open(filename, 'wb').write(psb_data0)

    elif filename.endswith('.psb.m'):
        # Compress the PSB data
        psb_data1 = psb.compress_data(psb_data0)
        if options.debug:
            open(filename + '.1', 'wb').write(psb_data1)  # compressed

        # Encrypt the PSB data
        if options.key:
            psb_data2 = psb.unobfuscate_data(psb_data1, options.key)
        else:
            psb_data2 = psb.unobfuscate_data(psb_data1, filename)
        if options.debug:
            open(filename + '.2',
                 'wb').write(psb_data2)  # compressed/encrypted

        # Write out the compressed/encrypted PSB data
        open(filename, 'wb').write(psb_data2)