Exemplo n.º 1
0
AbstractFile *duplicateAbstractFile2(AbstractFile * file,
				     AbstractFile * backing,
				     const unsigned int *key,
				     const unsigned int *iv,
				     AbstractFile * certificate)
{
	uint32_t signatureBE;
	uint32_t signatureLE;
	AbstractFile *orig;
	AbstractFile *newFile;

	file->seek(file, 0);
	file->read(file, &signatureBE, sizeof(signatureBE));
	signatureLE = signatureBE;
	FLIPENDIAN(signatureBE);
	FLIPENDIANLE(signatureLE);
	file->seek(file, 0);

	if (signatureBE == SIGNATURE_8900) {
		orig = createAbstractFileFrom8900(file);
		newFile = duplicate8900File(orig, backing);
		if (certificate != NULL)
			replaceCertificate8900(newFile, certificate);
		return duplicateAbstractFile(orig, newFile);
	} else if (signatureLE == IMG2_SIGNATURE) {
		orig = createAbstractFileFromImg2(file);
		return duplicateAbstractFile(orig,
					     duplicateImg2File(orig, backing));
	} else if (signatureLE == IMG3_SIGNATURE) {
		AbstractFile2 *newFile;
		AbstractFile2 *img3;

		img3 = (AbstractFile2 *) createAbstractFileFromImg3(file);
		if (key != NULL)
			img3->setKey(img3, key, iv);

		newFile =
		    (AbstractFile2 *) duplicateImg3File((AbstractFile *) img3,
							backing);
		if (key != NULL)
			img3->setKey(newFile, key, iv);

		if (certificate != NULL)
			replaceCertificateImg3((AbstractFile *) newFile,
					       certificate);
		return duplicateAbstractFile((AbstractFile *) img3,
					     (AbstractFile *) newFile);
	} else if (signatureBE == COMP_SIGNATURE) {
		orig = createAbstractFileFromComp(file);
		return duplicateAbstractFile(orig,
					     duplicateCompFile(orig, backing));
	} else {
		file->close(file);
		return backing;
	}
}
Exemplo n.º 2
0
void replaceCertificateAbstractFile(AbstractFile* file, AbstractFile* certificate) {
	uint32_t signatureBE;
	uint32_t signatureLE;
	AbstractFile* f;
	
	file->seek(file, 0);
	file->read(file, &signatureBE, sizeof(signatureBE));
	signatureLE = signatureBE;
	FLIPENDIAN(signatureBE);
	FLIPENDIANLE(signatureLE);
	file->seek(file, 0);

	if(signatureLE == IMG3_SIGNATURE) {
		f = createAbstractFileFromImg3(file);
		replaceCertificateImg3(f, certificate);
		f->close(f);
	}
}