From f44d03b0709bc5fb078b6386f8c4fd18a1e23351 Mon Sep 17 00:00:00 2001 From: _ <🐱> Date: Tue, 1 Dec 2020 01:13:00 -0700 Subject: [PATCH] Detect erroneous song decryption and alert user when it happens --- SpotifyKeyDumper/Utils.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/SpotifyKeyDumper/Utils.cpp b/SpotifyKeyDumper/Utils.cpp index cc24573..ed35d52 100644 --- a/SpotifyKeyDumper/Utils.cpp +++ b/SpotifyKeyDumper/Utils.cpp @@ -217,6 +217,13 @@ void Utils::DownloadSong(std::string fileId, std::string uri, std::string key, s AES_init_ctx_iv(&ctx, reinterpret_cast(&key[0]), IV); AES_CTR_xcrypt_buffer(&ctx, reinterpret_cast(&downloadStr[0]), downloadStr.size()); + // Check if decrypted song data has valid header + if (downloadStr.length() < 4 || downloadStr.compare(0, 4, "OggS") != 0) + { + std::cout << "Error: Could not properly decrypt song (try downloading again)!" << std::endl; + return; + } + // Remove custom Spotify Ogg page from beginning of file downloadStr = downloadStr.substr(downloadStr.find("\xFF\xFF\xFF\xFFOggS") + 4); @@ -262,9 +269,17 @@ void Utils::DownloadSong(std::string fileId, std::string uri, std::string key, s return; } - // Download encrypted song data from Spotify + // Download episode data from Spotify downloadStr = DownloadSpotifyUrl(songHost, songPath, ""); + // TODO: MP3 files appear to have a variety of headers, not sure this is 100% reliable + // Check if downloaded episode data has valid header + /*if (downloadStr.length() < 3 || downloadStr.compare(0, 3, "ID3") != 0) + { + std::cout << "Error: Could not properly download podcast episode (try downloading again)!" << std::endl; + return; + }*/ + // Download episode and show metadata from Spotify API std::string metadata = DownloadSpotifyUrl("api.spotify.com", "/v1/episodes/" + uri.substr(uri.find("spotify:episode:") + 16), authToken);