Skip to content

Instantly share code, notes, and snippets.

@esterTion
Last active May 31, 2020 22:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esterTion/c2318c108a6e48adaf09da550cd6b866 to your computer and use it in GitHub Desktop.
Save esterTion/c2318c108a6e48adaf09da550cd6b866 to your computer and use it in GitHub Desktop.
Redirect game api call host
shit title place holder
{ Filter = { Bundles = ( "moe.low.arc", "com.zzk.cgssguide" ); }; }
Package: com.estertion.arcapi
Name: ArcApiServer
Depends: mobilesubstrate
Version: 0.0.1
Architecture: iphoneos-arm
Description: An awesome MobileSubstrate tweak!
Maintainer: esterTion
Author: esterTion
Section: Tweaks
include $(THEOS)/makefiles/common.mk
TWEAK_NAME = ArcApiServer
ArcApiServer_ARCHS = arm64
ArcApiServer_FILES = Tweak.xm
include $(THEOS_MAKE_PATH)/tweak.mk
/*
#include <mach-o/dyld.h>
#include <mach-o/getsect.h>
*/
#import <substrate.h>
%hook NSMutableURLRequest
-(NSMutableURLRequest*)initWithURL:(NSURL *)URL
cachePolicy:(NSURLRequestCachePolicy)cachePolicy
timeoutInterval:(NSTimeInterval)timeoutInterval
{
if ([[URL host] isEqualToString: @"arcapi.lowiro.com"]) {
NSURLComponents *components = [NSURLComponents componentsWithURL:URL resolvingAgainstBaseURL:YES];
components.host = @"arc.estertion.win";
URL = components.URL;
#ifdef DEBUG
NSLog(@"[ArcApiServer] redirected to %@", URL);
#endif
return %orig(URL, cachePolicy, timeoutInterval);
} else if ([[URL host] isEqualToString: @"truecolor.kirara.ca"]) {
// DereGuide image server fix, because i'm iOS 9
NSURLComponents *components = [NSURLComponents componentsWithURL:URL resolvingAgainstBaseURL:YES];
components.host = @"hidamarirhodonite.kirara.ca";
URL = components.URL;
#ifdef DEBUG
NSLog(@"[ArcApiServer] redirected to %@", URL);
#endif
return %orig(URL, cachePolicy, timeoutInterval);
} else {
return %orig;
}
}
%end
/*
// attempt to hook strcpy, which seems to be called when game initializing, but failed
static const char* originalServer = "https://arcapi.lowiro.com/4/";
static const char* modifiedServer = "https://arc.estertion.win/4/";
%hookf(char *, strcpy, char * destination, const char * source) {
if (strlen(source) == 28)
NSLog(@"[ArcApiServer] %s", source);
if (strcmp(source, originalServer) == 0) {
NSLog(@"[ArcApiServer] api endpoint hijacked");
return %orig(destination, modifiedServer);
}
return %orig;
}*/
/*
// attempt to modify executable binary in memory, but failed because of execution protection (memory address can't be both executable and writable)
%ctor {
const char* imgName = _dyld_get_image_name(0);
NSLog(@"[ArcApiServer] Image #%d: %s", 0, imgName);
const struct mach_header_64 *mhp = (const struct mach_header_64*)_dyld_get_image_header(0);
uint64_t sectionSize = 0;
char *textSectionPtr = getsectdatafromheader_64(mhp, "__TEXT", "__cstring", &sectionSize);
NSLog(@"[ArcApiServer] __TEXT __cstring %p data size: %llu", textSectionPtr, sectionSize);
textSectionPtr++;
const char* originalServer = "https://arcapi.lowiro.com/4/";
const char* modifiedServer = "https://arc.estertion.win/4/";
while (sectionSize > 0) {
uint32_t len = strlen(textSectionPtr);
//NSLog(@"[ArcApiServer] string size: %u", len);
if (len == 28 && strcmp(textSectionPtr, originalServer) == 0) {
NSLog(@"[ArcApiServer] Found server string at %p, %s", textSectionPtr, textSectionPtr);
@try{
for (uint32_t i=0; i < 28; i++) {
*(textSectionPtr + i) = *(modifiedServer + i);
}
} @catch (NSException* e) {
NSLog(@"[ArcApiServer] %@", e);
}
break;
} else {
textSectionPtr += len + 1;
sectionSize -= len + 1;
}
}
}*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment