From a3ea56345d945172efd10dde3b045d53c5b956e6 Mon Sep 17 00:00:00 2001 From: Johnny Doo <7679710-CoolBurp@users.noreply.gitlab.com> Date: Sat, 21 Nov 2020 10:46:55 +0100 Subject: [PATCH 1/2] Fix download URL parser --- SpotifyKeyDumper/Utils.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/SpotifyKeyDumper/Utils.cpp b/SpotifyKeyDumper/Utils.cpp index 3d9ec58..d5af8cf 100644 --- a/SpotifyKeyDumper/Utils.cpp +++ b/SpotifyKeyDumper/Utils.cpp @@ -1,6 +1,7 @@ #include "pch.h" #include "Utils.h" #include "aes.h" +#include const uint8_t IV[] = { 0x72, 0xE0, 0x67, 0xFB, 0xDD, 0xCB, 0xCF, 0x77, 0xEB, 0xE8, 0xBC, 0x64, 0x3F, 0x63, 0x0D, 0x93 }; @@ -135,6 +136,7 @@ struct SongInfo static const std::string albumSearchPattern = "\x68\x65\x69\x67\x68\x74\x22\x20\x3A\x20\x36\x34\x30"; static const std::wstring songDirRoot = L"Downloads"; +static const std::string songRegex = "https?:\\/\\/(?:www\.)?([-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6})\\b([-a-zA-Z0-9()@:%_\\+.~#?&\\/\\/=]*)"; static std::wstring songDir = songDirRoot; void Utils::DownloadSong(std::string fileId, std::string trackUri, std::string key, std::string authToken) { @@ -156,15 +158,36 @@ void Utils::DownloadSong(std::string fileId, std::string trackUri, std::string k } // Parse storage resolve response to get the encrypted song data's URL - std::string songHost = (srStr.substr(srStr.find("https://") + 8)) - .erase(srStr.substr(srStr.find("https://") + 8).find("/audio/")); - std::string songPath = srStr.substr(srStr.find("/audio/")).erase(srStr.substr(srStr.find("/audio/")).find("=") + 85); + std::string songHost; + std::string songPath; + try { + std::regex re(songRegex); + std::smatch match; + if (std::regex_search(srStr, match, re) && match.size() > 1) { + songHost = match.str(1); + songPath = match.str(2); + } + else { + std::cout << "Error: Download URL not found" << std::endl; + return; + } + } + catch (std::regex_error& e) { + // Syntax error in the regular expression + std::cout << "Error: regex_error" << std::endl; + return; + } // Download encrypted song data from Spotify std::string songStr = DownloadSpotifyUrl(songHost, songPath, ""); //std::cout << "URL: " << songHost + songPath << std::endl; + if (songStr.empty()) { + std::cout << "Error: Could not download audio" << std::endl; + return; + } + if (songStr.substr(0, 6).compare("") == 0) { std::cout << "Error: " + songStr << std::endl; From 60eb96ece43f71f205773a88543ecf8f8b945b8f Mon Sep 17 00:00:00 2001 From: Johnny Doo <7679710-CoolBurp@users.noreply.gitlab.com> Date: Sat, 28 Nov 2020 11:38:16 +0100 Subject: [PATCH 2/2] Fix coding style --- SpotifyKeyDumper/Utils.cpp | 20 +++++++++++++------- SpotifyKeyDumper/pch.h | 1 + 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/SpotifyKeyDumper/Utils.cpp b/SpotifyKeyDumper/Utils.cpp index d5af8cf..27be049 100644 --- a/SpotifyKeyDumper/Utils.cpp +++ b/SpotifyKeyDumper/Utils.cpp @@ -1,7 +1,6 @@ #include "pch.h" #include "Utils.h" #include "aes.h" -#include const uint8_t IV[] = { 0x72, 0xE0, 0x67, 0xFB, 0xDD, 0xCB, 0xCF, 0x77, 0xEB, 0xE8, 0xBC, 0x64, 0x3F, 0x63, 0x0D, 0x93 }; @@ -136,7 +135,9 @@ struct SongInfo static const std::string albumSearchPattern = "\x68\x65\x69\x67\x68\x74\x22\x20\x3A\x20\x36\x34\x30"; static const std::wstring songDirRoot = L"Downloads"; -static const std::string songRegex = "https?:\\/\\/(?:www\.)?([-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6})\\b([-a-zA-Z0-9()@:%_\\+.~#?&\\/\\/=]*)"; +static const std::string songRegex = + "https?:\\/\\/(?:www\.)?([-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6})" + "\\b([-a-zA-Z0-9()@:%_\\+.~#?&\\/\\/=]*)"; static std::wstring songDir = songDirRoot; void Utils::DownloadSong(std::string fileId, std::string trackUri, std::string key, std::string authToken) { @@ -160,19 +161,23 @@ void Utils::DownloadSong(std::string fileId, std::string trackUri, std::string k // Parse storage resolve response to get the encrypted song data's URL std::string songHost; std::string songPath; - try { + try + { std::regex re(songRegex); std::smatch match; - if (std::regex_search(srStr, match, re) && match.size() > 1) { + if (std::regex_search(srStr, match, re) && match.size() > 1) + { songHost = match.str(1); songPath = match.str(2); } - else { + else + { std::cout << "Error: Download URL not found" << std::endl; return; } } - catch (std::regex_error& e) { + catch (std::regex_error& e) + { // Syntax error in the regular expression std::cout << "Error: regex_error" << std::endl; return; @@ -183,7 +188,8 @@ void Utils::DownloadSong(std::string fileId, std::string trackUri, std::string k //std::cout << "URL: " << songHost + songPath << std::endl; - if (songStr.empty()) { + if (songStr.empty()) + { std::cout << "Error: Could not download audio" << std::endl; return; } diff --git a/SpotifyKeyDumper/pch.h b/SpotifyKeyDumper/pch.h index 737c58a..45f7346 100644 --- a/SpotifyKeyDumper/pch.h +++ b/SpotifyKeyDumper/pch.h @@ -22,5 +22,6 @@ #include #include #include +#include #endif //PCH_H