Пример #1
0
//romhack.wikia.com/wiki/SNES_ROM_layout
ImageAddress LoROMAddress::toImageAddress() const {
    /// \todo: save-RAM (?)

    uint32_t imageAddress = 0;
    uint8_t bank = this->bank();

    if(bank == 0x7E || bank == 0x7F) {
        return ImageAddress(-1); //the address is actually a RAM address
    } else {
        //it is actually a ROM address
        imageAddress = (bank & 0x7F)*0x10000/2+bankAddress()&0x7FFF;
    }

    return ImageAddress(imageAddress);
}
Пример #2
0
//romhack.wikia.com/wiki/SNES_ROM_layout
ImageAddress HiROMAddress::toImageAddress() const {
    /// \todo: save-RAM (?)

    uint32_t imageAddress = 0;
    uint8_t bank = this->bank();

    if(bank == 0x7E || bank == 0x7F) {
        return ImageAddress(-1); //the address is actually a RAM address
    } else {
        //!TODO: save-RAM (?)
        //it is actually a ROM address

        imageAddress = m_Address & 0x3FFFFF;
        if((bank & 0x7F) < 0x40) {
            //mirrors 3 and 4 are only accepted in the upper half
            assert(bankAddress() > 0x7FFF);
        }
        imageAddress = ((bank & 0x3F)<<16)+bankAddress();
    }

    return ImageAddress(imageAddress);
}
Пример #3
0
int
main(int argc, char *argv[])
{
	if (argc < 3) {
		fprintf(stderr, "usage: verify foo.efi cert0 [... certN]\n");
		exit(1);
	}

	OpenSSL_add_all_algorithms();
	ERR_load_PKCS7_strings();
	ERR_load_crypto_strings();

	int binfd = open(argv[1], O_RDONLY);
	if (binfd < 0)
		err(1, "verify: %s", argv[1]);

	struct stat sb;
	fstat(binfd, &sb);
	void *bin = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, binfd, 0);
	size_t bin_size = sb.st_size;

	PE_COFF_LOADER_IMAGE_CONTEXT context;
	int rc = read_header(bin, sb.st_size, &context);
	if (rc < 0) {
		fprintf(stderr, "read_header(): %m\n");
		exit(1);
	}

	UINT8 sha256hash[32];
	rc = generate_hash(bin, sb.st_size, &context, sha256hash);
	if (rc < 0) {
		fprintf(stderr, "you can't handle a hash\n");
		exit(1);
	}

	WIN_CERTIFICATE_EFI_PKCS *efi_pkcs = NULL;

	if (context.SecDir->Size != 0) {
		efi_pkcs = ImageAddress(bin, bin_size,
				context.SecDir->VirtualAddress);
		if (!efi_pkcs) {
			fprintf(stderr, "signature is at invalid "
					"offset\n");
			exit(1);
		}
	}


	int found = 0;
	for (int i = 2; argv[i] != NULL; i++) {
		int fd = open(argv[i], O_RDONLY);
		if (fd < 0)
			err(1, "verify: %s", argv[i]);
		printf("adding cert from \"%s\"\n", argv[i]);

		uint8_t *cert;
		struct stat sb;

		fstat(fd, &sb);
		cert = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
		size_t cert_size = sb.st_size;
		
		rc = AuthenticodeVerify((UINT8 *)&efi_pkcs->CertData,
				efi_pkcs->Hdr.dwLength - sizeof(efi_pkcs->Hdr),
				cert, cert_size,
				sha256hash, 32);
		if (rc == 1) {
			found = 1;
			break;
		}

		char errbuf[120];
		unsigned long err = ERR_get_error();
		ERR_error_string(err, errbuf);
		printf("%s\n", errbuf);

		munmap(cert, sb.st_size);
		close(fd);
	}

	if (!found) {
		fprintf(stderr, "verify failed!\n");
		exit(1);
	}
	printf("Image verifies correctly\n");

	return 0;
}