diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f24fe3f --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +.DS_Store +/.build +/Packages +/*.xcodeproj +xcuserdata/ + +._* +.theos +/packages +.theos/ +packages/ +.DS_Store diff --git a/EeveeSpotify.plist b/EeveeSpotify.plist new file mode 100644 index 0000000..4bb2b96 --- /dev/null +++ b/EeveeSpotify.plist @@ -0,0 +1 @@ +{ Filter = { Bundles = ( "com.spotify.client" ); }; } diff --git a/Images/banner.png b/Images/banner.png new file mode 100644 index 0000000..eb6aab4 Binary files /dev/null and b/Images/banner.png differ diff --git a/Images/hex.png b/Images/hex.png new file mode 100644 index 0000000..6f60d5c Binary files /dev/null and b/Images/hex.png differ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5499995 --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +TARGET := iphone:clang:latest:14.0 +INSTALL_TARGET_PROCESSES = Spotify + +include $(THEOS)/makefiles/common.mk + +TWEAK_NAME = EeveeSpotify + +EeveeSpotify_FILES = $(shell find Sources/EeveeSpotify -name '*.swift') $(shell find Sources/EeveeSpotifyC -name '*.m' -o -name '*.c' -o -name '*.mm' -o -name '*.cpp') +EeveeSpotify_SWIFTFLAGS = -ISources/EeveeSpotifyC/include +EeveeSpotify_CFLAGS = -fobjc-arc -ISources/EeveeSpotifyC/include + +include $(THEOS_MAKE_PATH)/tweak.mk diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..7dccbcb --- /dev/null +++ b/Package.swift @@ -0,0 +1,88 @@ +// swift-tools-version:5.2 + +import PackageDescription +import Foundation + +let projectDir = URL(fileURLWithPath: #filePath).deletingLastPathComponent() + +@dynamicMemberLookup struct TheosConfiguration { + private let dict: [String: String] + init(at path: String) { + let configURL = URL(fileURLWithPath: path, relativeTo: projectDir) + guard let infoString = try? String(contentsOf: configURL) else { + fatalError(""" + Could not find Theos SPM config. Have you run `make spm` yet? + """) + } + let pairs = infoString.split(separator: "\n").map { + $0.split( + separator: "=", maxSplits: 1, + omittingEmptySubsequences: false + ).map(String.init) + }.map { ($0[0], $0[1]) } + dict = Dictionary(uniqueKeysWithValues: pairs) + } + subscript( + key: String, + or defaultValue: @autoclosure () -> String? = nil + ) -> String { + if let value = dict[key] { + return value + } else if let def = defaultValue() { + return def + } else { + fatalError(""" + Could not get value of key '\(key)' from Theos SPM config. \ + Try running `make spm` again. + """) + } + } + subscript(dynamicMember key: String) -> String { self[key] } +} +let conf = TheosConfiguration(at: ".theos/spm_config") + +let theosPath = conf.theos +let sdk = conf.sdk +let resourceDir = conf.swiftResourceDir +let deploymentTarget = conf.deploymentTarget +let triple = "arm64-apple-ios\(deploymentTarget)" + +let libFlags: [String] = [ + "-F\(theosPath)/vendor/lib", "-F\(theosPath)/lib", + "-I\(theosPath)/vendor/include", "-I\(theosPath)/include" +] + +let cFlags: [String] = libFlags + [ + "-target", triple, "-isysroot", sdk, + "-Wno-unused-command-line-argument", "-Qunused-arguments", +] + +let cxxFlags: [String] = [ +] + +let swiftFlags: [String] = libFlags + [ + "-target", triple, "-sdk", sdk, "-resource-dir", resourceDir, +] + +let package = Package( + name: "EeveeSpotify", + platforms: [.iOS(deploymentTarget)], + products: [ + .library( + name: "EeveeSpotify", + targets: ["EeveeSpotify"] + ), + ], + targets: [ + .target( + name: "EeveeSpotifyC", + cSettings: [.unsafeFlags(cFlags)], + cxxSettings: [.unsafeFlags(cxxFlags)] + ), + .target( + name: "EeveeSpotify", + dependencies: ["EeveeSpotifyC"], + swiftSettings: [.unsafeFlags(swiftFlags)] + ), + ] +) diff --git a/README.md b/README.md new file mode 100644 index 0000000..28d254f --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +![Banner](Images/banner.png) + +# EeveeSpotify + +This tweak makes Spotify think that you have a Premium subscription, granting free listening, just like Spotilife. + +## The History + +Several months ago, Spotilife, the only tweak to get Spotify Premium, stopped working on new Spotify versions. I decompiled Spotilife, reverse-engineered Spotify, intercepted requests, etc., and created this tweak. + +## How It Works + +Upon login, Spotify fetches user data, including active subscription, and caches it in the `offline.bnk` file in the `/Library/Application Support/PersistentCache` directory. It uses its proprietary binary format to store data, incorporating a length byte before each value, among other conventions. Certain keys, such as `player-license`, `financial-product`, and `type`, determines the user abilities. + +The tweak patches this file while initializing; Spotify loads it and assumes you have Premium. To be honest, it doesn't really patch due to challenges with dynamic length and varied bytes. Ideally, there should be a parser capable of deserializing and serializing such format. However, for now, the tweak simply extracts the username from the current `offline.bnk` file and inserts it into `premiumblank.bnk` (a file containing all premium values preset), replacing `offline.bnk` (`financial-product` is trial because I have no premium `offline.bnk`, but it doesn't matter). + +![Hex](Images/hex.png) + +Tweak also changes query parameters `trackRows` and `video` to true, so Spotify loads videos and not just track names at the artist page. Sorry if the code seems cringe; the main focus is on the concept. It can stop working just like Spotilife, but so far, it works on the latest Spotify 8.9.## (Spotilife also patches `offline.bnk`, but it changes obscure bytes that do nothing on new versions). Spotify reloads user data from time to time (and on changing network, for example), so if Premium stops working, simply restart the app. + +There is no offline or very high quality (similar to Spotilife) because these features are server-sided (i.e., you can't get very high quality tracks from the server without a subscription). In theory, it might be possible to implement offline mode locally, but not in this tweak. + +To hide the Premium tab, use [SpotifyHidePremium](https://t.me/SpotilifeIPAs/36). diff --git a/Sources/EeveeSpotify/BundleHelper.swift b/Sources/EeveeSpotify/BundleHelper.swift new file mode 100755 index 0000000..2e28531 --- /dev/null +++ b/Sources/EeveeSpotify/BundleHelper.swift @@ -0,0 +1,29 @@ +import Foundation +import libroot + +class BundleHelper { + + private let bundleName = "EeveeSpotify" + + private let bundle: Bundle + static let shared = BundleHelper() + + private init() { + self.bundle = Bundle( + path: Bundle.main.path( + forResource: bundleName, + ofType: "bundle" + ) + ?? jbRootPath("/Library/Application Support/\(bundleName).bundle") + )! + } + + func premiumBlankData() throws -> Data { + return try Data( + contentsOf: self.bundle.url( + forResource: "premiumblank", + withExtension: "bnk" + )! + ) + } +} diff --git a/Sources/EeveeSpotify/Tweak.x.swift b/Sources/EeveeSpotify/Tweak.x.swift new file mode 100644 index 0000000..fdcbb6b --- /dev/null +++ b/Sources/EeveeSpotify/Tweak.x.swift @@ -0,0 +1,55 @@ +import Orion + +class URLHook: ClassHook { + + func initWithString(_ urlString: String, relativeToURL URL: NSURL) -> NSURL { + + var finalString = urlString + + if finalString.contains("artistview") { + finalString = finalString.replacingOccurrences( + of: "trackRows=false", + with: "trackRows=true" + ) + finalString = finalString.replacingOccurrences( + of: "video=false", + with: "video=true" + ) + } + + return orig.initWithString(finalString, relativeToURL: URL) + } +} + +struct EeveeSpotify: Tweak { + + init() { + + do { + + let filePath = FileManager.default.urls( + for: .applicationSupportDirectory, in: .userDomainMask + ) + .first! + .appendingPathComponent("PersistentCache") + .appendingPathComponent("offline.bnk") + + let fileData = try Data(contentsOf: filePath) + + let usernameLength = Int(fileData[8]) + let username = Data(fileData[9..<9 + usernameLength]) + + var blankData = try BundleHelper.shared.premiumBlankData() + + blankData.insert(UInt8(usernameLength), at: 8) + blankData.insert(contentsOf: username, at: 9) + + try blankData.write(to: filePath) + NSLog("[EeveeSpotify] Successfully applied") + } + + catch { + NSLog("[EeveeSpotify] Unable to apply tweak: \(error)") + } + } +} diff --git a/Sources/EeveeSpotifyC/Tweak.m b/Sources/EeveeSpotifyC/Tweak.m new file mode 100644 index 0000000..6b69cfc --- /dev/null +++ b/Sources/EeveeSpotifyC/Tweak.m @@ -0,0 +1,8 @@ +#import +#import + +__attribute__((constructor)) static void init() { + // Initialize Orion - do not remove this line. + orion_init(); + // Custom initialization code goes here. +} diff --git a/Sources/EeveeSpotifyC/include/Tweak.h b/Sources/EeveeSpotifyC/include/Tweak.h new file mode 100644 index 0000000..e69de29 diff --git a/Sources/EeveeSpotifyC/include/module.modulemap b/Sources/EeveeSpotifyC/include/module.modulemap new file mode 100644 index 0000000..3a1a489 --- /dev/null +++ b/Sources/EeveeSpotifyC/include/module.modulemap @@ -0,0 +1,4 @@ +module EeveeSpotifyC { + umbrella "." + export * +} diff --git a/control b/control new file mode 100644 index 0000000..5f7b318 --- /dev/null +++ b/control @@ -0,0 +1,9 @@ +Package: com.eevee.spotify +Name: EeveeSpotify +Version: 1.0 +Architecture: iphoneos-arm +Description: A tweak to get Spotify Premium for free, just like Spotilife +Maintainer: Eevee +Author: Eevee +Section: Tweaks +Depends: ${ORION}, firmware (>= 14.0) diff --git a/layout/Library/Application Support/EeveeSpotify.bundle/premiumblank.bnk b/layout/Library/Application Support/EeveeSpotify.bundle/premiumblank.bnk new file mode 100644 index 0000000..90b2248 Binary files /dev/null and b/layout/Library/Application Support/EeveeSpotify.bundle/premiumblank.bnk differ