Skip to content

Commit

Permalink
Added the tweaks source code files
Browse files Browse the repository at this point in the history
  • Loading branch information
ObscureMosquito authored Sep 7, 2023
1 parent b2ab0a7 commit 1ae10f2
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 0 deletions.
13 changes: 13 additions & 0 deletions CustomURLProtocol.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// CustomURLProtocol.h
// NSURLProtocolExample
//
// Created by lujb on 15/6/15.
// Copyright (c) 2015年 lujb. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface CustomURLProtocol : NSURLProtocol

@end
97 changes: 97 additions & 0 deletions CustomURLProtocol.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#import "CustomURLProtocol.h"

static NSString * const URLProtocolHandledKey = @"URLProtocolHandledKey";

@interface CustomURLProtocol () <NSURLConnectionDelegate>

@property (nonatomic, strong) NSURLConnection *connection;

@end

@implementation CustomURLProtocol

+ (BOOL)canInitWithRequest:(NSURLRequest *)request {
// Check if the request URL contains "dv6-storefront-p6bootstrap.js"
NSString *requestURLString = request.URL.absoluteString;

// Check if the request URL is the exception URL
if ([requestURLString isEqualToString:@"https://search.itunes.apple.com/htmlResources/d04b/dv6-storefront-p6bootstrap.js"]) {
// Allow this specific URL to go through without modification
return NO;
}

if ([requestURLString rangeOfString:@"dv6-storefront-p6bootstrap.js"].location != NSNotFound) {
return YES;
}

// Check if the request URL contains "dv6-storefront-k6bootstrap.js"
if ([requestURLString rangeOfString:@"dv6-storefront-k6bootstrap.js"].location != NSNotFound) {
return YES;
}

return NO;
}

+ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request {
return request;
}

- (void)startLoading {
// Create a new request based on the original request
NSMutableURLRequest *mutableRequest = [self.request mutableCopy];
NSString *requestURLString = mutableRequest.URL.absoluteString;

// Check if the request URL is the exception URL
if ([requestURLString isEqualToString:@"https://search.itunes.apple.com/htmlResources/d04b/dv6-storefront-p6bootstrap.js"]) {
// Allow this specific URL to go through without modification
[self passThroughRequest:mutableRequest];
return;
}

// Replace "dv6-storefront-p6bootstrap.js" with "dv7-storefront-p7bootstrap.js"
requestURLString = [requestURLString stringByReplacingOccurrencesOfString:@"dv6-storefront-p6bootstrap.js" withString:@"dv7-storefront-p7bootstrap.js"];

// Replace "dv6-storefront-k6bootstrap.js" with "dv7-storefront-k7bootstrap.js"
requestURLString = [requestURLString stringByReplacingOccurrencesOfString:@"dv6-storefront-k6bootstrap.js" withString:@"dv7-storefront-k7bootstrap.js"];

mutableRequest.URL = [NSURL URLWithString:requestURLString];

// Prevent infinite loops by marking this request as handled
[NSURLProtocol setProperty:@YES forKey:URLProtocolHandledKey inRequest:mutableRequest];

// Create a connection with the modified request
self.connection = [NSURLConnection connectionWithRequest:mutableRequest delegate:self];
}

- (void)stopLoading {
[self.connection cancel];
}

- (void)passThroughRequest:(NSURLRequest *)request {
// Allow a specific request to go through without modification
self.connection = [NSURLConnection connectionWithRequest:request delegate:self];
}

#pragma mark - NSURLConnectionDelegate

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
// Pass the received response back to the app
[self.client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
// Pass the received data back to the app
[self.client URLProtocol:self didLoadData:data];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
// Indicate that loading is complete
[self.client URLProtocolDidFinishLoading:self];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
// Handle any connection errors and pass them back to the app
[self.client URLProtocol:self didFailWithError:error];
}

@end
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
TARGET := iphone:clang:latest:7.0
INSTALL_TARGET_PROCESSES = SpringBoard
BUNDLE_NAME = com.mosquito.itunesstorex

archs= armv7

include $(THEOS)/makefiles/common.mk

TWEAK_NAME = iTunesStoreX

iTunesStoreX_FILES = Tweak.x CustomURLProtocol.m
iTunesStoreX_CFLAGS = -fobjc-arc

include $(THEOS_MAKE_PATH)/tweak.mk

51 changes: 51 additions & 0 deletions Tweak.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
#import <substrate.h>
#import <CustomURLProtocol.h>

%hook NSURL

- (instancetype)initWithString:(NSString *)URLString {

// URLs to modify
NSString *baseURLToModify1 = @"http://ax.init.itunes.apple.com";

// Check if the URL starts with the specified base URLs
if ([URLString hasPrefix:baseURLToModify1]) {

NSURL *oldURL = [NSURL URLWithString:URLString];
NSString *path = [oldURL path];
NSString *query = [oldURL query];

// Ax init replacement, also dv6->7
NSString *newBaseURL = @"http://init.itunes.apple.com";
NSString *newURLString = [NSString stringWithFormat:@"%@%@%@", newBaseURL, path, (query ? [NSString stringWithFormat:@"?%@", query] : @"")];

// Create a new NSURL instance with the modified URL
NSURL *newURL = [NSURL URLWithString:newURLString];

return newURL;
} else {
// If the URL doesn't need modification, return the original NSURL instance
return %orig;
}
}

%end

%hook NSURLRequest

static void RegisterCustomURLProtocol() {
[NSURLProtocol registerClass:[CustomURLProtocol class]];
}

__attribute__((constructor))
static void init_hook() {
// Register your custom protocol class
RegisterCustomURLProtocol();

// Other initialization code for your tweak
}

%end
9 changes: 9 additions & 0 deletions control
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Package: com.mosquito.itunesstorex
Name: iTunesStoreX
Version: 1.0
Architecture: iphoneos-arm
Description: This tweak fixes the App Store (Particularly every aspect of the iTunes Store too). It fixes every app's connection issues with the iTunes Store, examples are: Podcasts, iBooks, Videos, Music, iTunes and of course, the App Store. This tweak also fixes Apple ID Authentication, downloads and the pwning of apps on iOS 6 (the Apple ID prompt bypass), since that's been impossible since apple shut of the iTunes Store on anything lower than 7
Maintainer: Requis, Daph
Author: Requis (ObscureMosquito), Daph (Mali)
Section: Tweaks
Depends: mobilesubstrate, firmware(<==6)
1 change: 1 addition & 0 deletions iTunesStoreX.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ Filter = { Bundles = ( "com.apple.itunesstore" ); }; }

0 comments on commit 1ae10f2

Please sign in to comment.