Skip to content

Instantly share code, notes, and snippets.

@steventroughtonsmith
Created June 11, 2020 02:14
Show Gist options
  • Save steventroughtonsmith/9e8ecbd0ab89e7d24ce873a464c5dc83 to your computer and use it in GitHub Desktop.
Save steventroughtonsmith/9e8ecbd0ab89e7d24ce873a464c5dc83 to your computer and use it in GitHub Desktop.
tbdswizzler.m
//
// main.m
// tbdswizzler
//
// Created by Steven Troughton-Smith on 10/12/2016.
// Copyright © 2016 High Caffeine Content. All rights reserved.
//
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
@autoreleasepool {
NSLog(@"tbdswizzler ARM64");
setreuid(geteuid(), getuid());
if (argc > 1 && strlen(argv[1]) != 0)
{
NSString *target = [NSString stringWithUTF8String:argv[1]];
NSString *contents = [NSString stringWithContentsOfFile:target];
NSMutableString *finalContents = contents.mutableCopy;
//NSLog(@"%@", target);
__block NSUInteger currentLength = 0;
[contents enumerateLinesUsingBlock:^(NSString * _Nonnull line, BOOL * _Nonnull stop) {
currentLength+=line.length;
if ([line rangeOfString:@"archs:"].length != 0 && [line rangeOfString:@"arm64"].length == 0)
{
NSString *replacementLine = line;
if ([line rangeOfString:@"x86_64"].length != 0)
{
replacementLine = [line stringByReplacingOccurrencesOfString:@" ]" withString:@", arm64 ]"];
}
[finalContents replaceOccurrencesOfString:line withString:replacementLine options:NSLiteralSearch range:NSMakeRange(0, finalContents.length)];
// NSLog(@"%@", replacementLine);
}
}];
//NSLog(@"%@", finalContents);
NSError *error = nil;
[finalContents writeToFile:target atomically:YES encoding:NSUTF8StringEncoding error:&error];
if (error)
{
NSLog(@"Error: %@", error);
exit(-1);
}
}
}
return 0;
}
int main_arm32(int argc, const char * argv[]) {
@autoreleasepool {
NSLog(@"tbdswizzler ARM");
setreuid(geteuid(), getuid());
if (argc > 1 && strlen(argv[1]) != 0)
{
NSString *target = [NSString stringWithUTF8String:argv[1]];
NSString *contents = [NSString stringWithContentsOfFile:target];
NSMutableString *finalContents = contents.mutableCopy;
//NSLog(@"%@", target);
__block NSUInteger currentLength = 0;
[contents enumerateLinesUsingBlock:^(NSString * _Nonnull line, BOOL * _Nonnull stop) {
currentLength+=line.length;
if ([line rangeOfString:@"archs:"].length != 0 && [line rangeOfString:@"x86_64"].length == 0)
{
NSString *replacementLine = line;
if ([line rangeOfString:@"armv7"].length != 0)
{
replacementLine = [line stringByReplacingOccurrencesOfString:@" ]" withString:@", i386, x86_64 ]"];
}
[finalContents replaceOccurrencesOfString:line withString:replacementLine options:NSLiteralSearch range:NSMakeRange(0, finalContents.length)];
// NSLog(@"%@", replacementLine);
}
}];
//NSLog(@"%@", finalContents);
NSError *error = nil;
[finalContents writeToFile:target atomically:YES encoding:NSUTF8StringEncoding error:&error];
if (error)
{
NSLog(@"Error: %@", error);
exit(-1);
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment