edat: Remove redundant logging

This commit is contained in:
Megamouse 2021-05-19 20:19:59 +02:00
parent 7832acbceb
commit 1dc00ccedd

View file

@ -93,7 +93,7 @@ bool decrypt(int hash_mode, int crypto_mode, int version, unsigned char *in, uns
} }
else else
{ {
edat_log.error("EDAT: Unknown crypto algorithm!"); edat_log.error("Unknown crypto algorithm!");
return false; return false;
} }
@ -111,7 +111,7 @@ bool decrypt(int hash_mode, int crypto_mode, int version, unsigned char *in, uns
} }
else else
{ {
edat_log.error("EDAT: Unknown hashing algorithm!"); edat_log.error("Unknown hashing algorithm!");
return false; return false;
} }
} }
@ -295,7 +295,7 @@ s64 decrypt_block(const fs::file* in, u8* out, EDAT_HEADER *edat, NPD_HEADER *np
// Call main crypto routine on this data block. // Call main crypto routine on this data block.
if (!decrypt(hash_mode, crypto_mode, (npd->version == 4), enc_data.get(), dec_data.get(), length, key_result, iv, hash, hash_result)) if (!decrypt(hash_mode, crypto_mode, (npd->version == 4), enc_data.get(), dec_data.get(), length, key_result, iv, hash, hash_result))
{ {
edat_log.error("EDAT: Block at offset 0x%llx has invalid hash!", offset); edat_log.error("Block at offset 0x%llx has invalid hash!", offset);
return -1; return -1;
} }
} }
@ -311,7 +311,7 @@ s64 decrypt_block(const fs::file* in, u8* out, EDAT_HEADER *edat, NPD_HEADER *np
{ {
if (res < 0) if (res < 0)
{ {
edat_log.error("EDAT: Decompression failed!"); edat_log.error("Decompression failed!");
return -1; return -1;
} }
} }
@ -339,7 +339,7 @@ int decrypt_data(const fs::file* in, const fs::file* out, EDAT_HEADER *edat, NPD
u64 res = decrypt_block(in, data.get(), edat, npd, crypt_key, i, total_blocks, size_left); u64 res = decrypt_block(in, data.get(), edat, npd, crypt_key, i, total_blocks, size_left);
if (res == umax) if (res == umax)
{ {
edat_log.error("EDAT: Decrypt Block failed!"); edat_log.error("Decrypt Block failed!");
return 1; return 1;
} }
size_left -= res; size_left -= res;
@ -364,7 +364,7 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs:
{ {
if (edat->flags & 0x7EFFFFFE) if (edat->flags & 0x7EFFFFFE)
{ {
edat_log.error("EDAT: Bad header flags!"); edat_log.error("Bad header flags!");
return 1; return 1;
} }
} }
@ -372,7 +372,7 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs:
{ {
if (edat->flags & 0x7EFFFFE0) if (edat->flags & 0x7EFFFFE0)
{ {
edat_log.error("EDAT: Bad header flags!"); edat_log.error("Bad header flags!");
return 1; return 1;
} }
} }
@ -380,13 +380,13 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs:
{ {
if (edat->flags & 0x7EFFFFC0) if (edat->flags & 0x7EFFFFC0)
{ {
edat_log.error("EDAT: Bad header flags!"); edat_log.error("Bad header flags!");
return 1; return 1;
} }
} }
else else
{ {
edat_log.error("EDAT: Unknown version!"); edat_log.error("Unknown version!");
return 1; return 1;
} }
@ -406,7 +406,7 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs:
hash_mode |= 0x01000000; hash_mode |= 0x01000000;
if (verbose) if (verbose)
edat_log.warning("EDAT: DEBUG data detected!"); edat_log.warning("DEBUG data detected!");
} }
// Setup header key and iv buffers. // Setup header key and iv buffers.
@ -417,12 +417,12 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs:
if (!decrypt(hash_mode, crypto_mode, (npd->version == 4), header, empty_header, 0xA0, header_key, header_iv, key, header_hash)) if (!decrypt(hash_mode, crypto_mode, (npd->version == 4), header, empty_header, 0xA0, header_key, header_iv, key, header_hash))
{ {
if (verbose) if (verbose)
edat_log.warning("EDAT: Header hash is invalid!"); edat_log.warning("Header hash is invalid!");
// If the header hash test fails and the data is not DEBUG, then RAP/RIF/KLIC key is invalid. // If the header hash test fails and the data is not DEBUG, then RAP/RIF/KLIC key is invalid.
if ((edat->flags & EDAT_DEBUG_DATA_FLAG) != EDAT_DEBUG_DATA_FLAG) if ((edat->flags & EDAT_DEBUG_DATA_FLAG) != EDAT_DEBUG_DATA_FLAG)
{ {
edat_log.error("EDAT: RAP/RIF/KLIC key is invalid!"); edat_log.error("RAP/RIF/KLIC key is invalid!");
return 1; return 1;
} }
} }
@ -432,7 +432,7 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs:
if (((edat->flags & EDAT_COMPRESSED_FLAG) != 0)) if (((edat->flags & EDAT_COMPRESSED_FLAG) != 0))
{ {
if (verbose) if (verbose)
edat_log.warning("EDAT: COMPRESSED data detected!"); edat_log.warning("COMPRESSED data detected!");
} }
const int block_num = static_cast<int>((edat->file_size + edat->block_size - 1) / edat->block_size); const int block_num = static_cast<int>((edat->file_size + edat->block_size - 1) / edat->block_size);
@ -467,7 +467,7 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs:
if (!decrypt(hash_mode, crypto_mode, (npd->version == 4), metadata.get(), empty_metadata.get(), metadata_size, header_key, header_iv, key, metadata_hash)) if (!decrypt(hash_mode, crypto_mode, (npd->version == 4), metadata.get(), empty_metadata.get(), metadata_size, header_key, header_iv, key, metadata_hash))
{ {
if (verbose) if (verbose)
edat_log.warning("EDAT: Metadata section hash is invalid!"); edat_log.warning("Metadata section hash is invalid!");
} }
// Checking ECDSA signatures. // Checking ECDSA signatures.
@ -497,7 +497,7 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs:
memcpy(signature_r + 01, metadata_signature, 0x14); memcpy(signature_r + 01, metadata_signature, 0x14);
memcpy(signature_s + 01, metadata_signature + 0x14, 0x14); memcpy(signature_s + 01, metadata_signature + 0x14, 0x14);
if ((!memcmp(signature_r, zero_buf, 0x15)) || (!memcmp(signature_s, zero_buf, 0x15))) if ((!memcmp(signature_r, zero_buf, 0x15)) || (!memcmp(signature_s, zero_buf, 0x15)))
edat_log.warning("EDAT: Metadata signature is invalid!"); edat_log.warning("Metadata signature is invalid!");
else else
{ {
// Setup signature hash. // Setup signature hash.
@ -514,9 +514,9 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs:
if (!ecdsa_verify(signature_hash, signature_r, signature_s)) if (!ecdsa_verify(signature_hash, signature_r, signature_s))
{ {
edat_log.warning("EDAT: Metadata signature is invalid!"); edat_log.warning("Metadata signature is invalid!");
if (((edat->block_size + 0ull) * block_num) > 0x100000000) if (((edat->block_size + 0ull) * block_num) > 0x100000000)
edat_log.warning("EDAT: *Due to large file size, metadata signature status may be incorrect!"); edat_log.warning("*Due to large file size, metadata signature status may be incorrect!");
} }
} }
@ -528,7 +528,7 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs:
memcpy(signature_s + 01, header_signature + 0x14, 0x14); memcpy(signature_s + 01, header_signature + 0x14, 0x14);
if ((!memcmp(signature_r, zero_buf, 0x15)) || (!memcmp(signature_s, zero_buf, 0x15))) if ((!memcmp(signature_r, zero_buf, 0x15)) || (!memcmp(signature_s, zero_buf, 0x15)))
edat_log.warning("EDAT: Header signature is invalid!"); edat_log.warning("Header signature is invalid!");
else else
{ {
// Setup header signature hash. // Setup header signature hash.
@ -539,7 +539,7 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs:
sha1(header_buf, 0xD8, signature_hash); sha1(header_buf, 0xD8, signature_hash);
if (!ecdsa_verify(signature_hash, signature_r, signature_s)) if (!ecdsa_verify(signature_hash, signature_r, signature_s))
edat_log.warning("EDAT: Header signature is invalid!"); edat_log.warning("Header signature is invalid!");
} }
} }
@ -616,9 +616,9 @@ bool validate_npd_hashes(const char* file_name, const u8* klicensee, NPD_HEADER
if (verbose) if (verbose)
{ {
if (title_hash_result) if (title_hash_result)
edat_log.notice("EDAT: NPD title hash is valid!"); edat_log.notice("NPD title hash is valid!");
else else
edat_log.warning("EDAT: NPD title hash is invalid!"); edat_log.warning("NPD title hash is invalid!");
} }
const bool dev_hash_result = validate_dev_klic(klicensee, npd); const bool dev_hash_result = validate_dev_klic(klicensee, npd);
@ -661,7 +661,7 @@ bool extract_all_data(const fs::file* input, const fs::file* output, const char*
unsigned char npd_magic[4] = {0x4E, 0x50, 0x44, 0x00}; //NPD0 unsigned char npd_magic[4] = {0x4E, 0x50, 0x44, 0x00}; //NPD0
if (memcmp(&NPD.magic, npd_magic, 4)) if (memcmp(&NPD.magic, npd_magic, 4))
{ {
edat_log.error("EDAT: %s has invalid NPD header or already decrypted.", input_file_name); edat_log.error("%s has invalid NPD header or already decrypted.", input_file_name);
return true; return true;
} }
@ -708,7 +708,7 @@ bool extract_all_data(const fs::file* input, const fs::file* output, const char*
// Ignore header validation in DEBUG data. // Ignore header validation in DEBUG data.
if ((EDAT.flags & EDAT_DEBUG_DATA_FLAG) != EDAT_DEBUG_DATA_FLAG) if ((EDAT.flags & EDAT_DEBUG_DATA_FLAG) != EDAT_DEBUG_DATA_FLAG)
{ {
edat_log.error("EDAT: NPD hash validation failed!"); edat_log.error("NPD hash validation failed!");
return true; return true;
} }
} }
@ -723,7 +723,7 @@ bool extract_all_data(const fs::file* input, const fs::file* output, const char*
// Make sure we don't have an empty RIF key. // Make sure we don't have an empty RIF key.
if (!key) if (!key)
{ {
edat_log.error("EDAT: A valid RAP file is needed for this EDAT file! (local activation)"); edat_log.error("A valid RAP file is needed for this EDAT file! (local activation)");
return true; return true;
} }
} }
@ -734,7 +734,7 @@ bool extract_all_data(const fs::file* input, const fs::file* output, const char*
// Make sure we don't have an empty RIF key. // Make sure we don't have an empty RIF key.
if (!key) if (!key)
{ {
edat_log.error("EDAT: A valid RAP file is needed for this EDAT file! (network activation)"); edat_log.error("A valid RAP file is needed for this EDAT file! (network activation)");
return true; return true;
} }
} }
@ -758,14 +758,14 @@ bool extract_all_data(const fs::file* input, const fs::file* output, const char*
input->seek(0); input->seek(0);
if (check_data(reinterpret_cast<uchar*>(&key), &EDAT, &NPD, input, verbose)) if (check_data(reinterpret_cast<uchar*>(&key), &EDAT, &NPD, input, verbose))
{ {
edat_log.error("EDAT: Data parsing failed!"); edat_log.error("Data parsing failed!");
return true; return true;
} }
input->seek(0); input->seek(0);
if (decrypt_data(input, output, &EDAT, &NPD, reinterpret_cast<uchar*>(&key), verbose)) if (decrypt_data(input, output, &EDAT, &NPD, reinterpret_cast<uchar*>(&key), verbose))
{ {
edat_log.error("EDAT: Data decryption failed!"); edat_log.error("Data decryption failed!");
return true; return true;
} }
@ -796,13 +796,13 @@ bool VerifyEDATHeaderWithKLicense(const fs::file& input, const std::string& inpu
unsigned char npd_magic[4] = { 0x4E, 0x50, 0x44, 0x00 }; //NPD0 unsigned char npd_magic[4] = { 0x4E, 0x50, 0x44, 0x00 }; //NPD0
if (memcmp(&NPD.magic, npd_magic, 4)) if (memcmp(&NPD.magic, npd_magic, 4))
{ {
edat_log.error("EDAT: %s has invalid NPD header or already decrypted.", input_file_name); edat_log.error("%s has invalid NPD header or already decrypted.", input_file_name);
return false; return false;
} }
if ((EDAT.flags & SDAT_FLAG) == SDAT_FLAG) if ((EDAT.flags & SDAT_FLAG) == SDAT_FLAG)
{ {
edat_log.error("EDAT: SDATA file given to edat function"); edat_log.error("SDATA file given to edat function");
return false; return false;
} }
@ -814,7 +814,7 @@ bool VerifyEDATHeaderWithKLicense(const fs::file& input, const std::string& inpu
// Ignore header validation in DEBUG data. // Ignore header validation in DEBUG data.
if ((EDAT.flags & EDAT_DEBUG_DATA_FLAG) != EDAT_DEBUG_DATA_FLAG) if ((EDAT.flags & EDAT_DEBUG_DATA_FLAG) != EDAT_DEBUG_DATA_FLAG)
{ {
edat_log.error("EDAT: NPD hash validation failed!"); edat_log.error("NPD hash validation failed!");
return false; return false;
} }
} }
@ -865,13 +865,13 @@ fs::file DecryptEDAT(const fs::file& input, const std::string& input_file_name,
memcpy(&devklic, custom_klic, 0x10); memcpy(&devklic, custom_klic, 0x10);
else else
{ {
edat_log.error("EDAT: Invalid custom klic!"); edat_log.error("Invalid custom klic!");
return fs::file{}; return fs::file{};
} }
break; break;
} }
default: default:
edat_log.error("EDAT: Invalid mode!"); edat_log.error("Invalid mode!");
return fs::file{}; return fs::file{};
} }
@ -918,7 +918,7 @@ bool EDATADecrypter::ReadHeader()
// verify key // verify key
if (!validate_dev_klic(reinterpret_cast<uchar*>(&dev_key), &npdHeader)) if (!validate_dev_klic(reinterpret_cast<uchar*>(&dev_key), &npdHeader))
{ {
edat_log.error("EDAT: Failed validating klic"); edat_log.error("Failed validating klic");
return false; return false;
} }
@ -931,7 +931,7 @@ bool EDATADecrypter::ReadHeader()
if (!dec_key) if (!dec_key)
{ {
edat_log.warning("EDAT: Empty Dec key for local activation!"); edat_log.warning("Empty Dec key for local activation!");
} }
} }
else if ((npdHeader.license & 0x1) == 0x1) // Type 1: Use network activation. else if ((npdHeader.license & 0x1) == 0x1) // Type 1: Use network activation.
@ -940,7 +940,7 @@ bool EDATADecrypter::ReadHeader()
if (!dec_key) if (!dec_key)
{ {
edat_log.warning("EDAT: Empty Dec key for network activation!"); edat_log.warning("Empty Dec key for network activation!");
} }
} }
} }