DalesDeadBug.xm 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #import <objc/runtime.h>
  2. #import <notify.h>
  3. #import <dlfcn.h>
  4. #import <substrate.h>
  5. #import <sys/utsname.h>
  6. #import <UIKit/UIKit.h>
  7. #import "TVSettingsTweakViewController.h"
  8. extern const char *__progname;
  9. #define NSLog(...)
  10. #define PLIST_PATH_Settings "/var/mobile/Library/Preferences/com.nito.dalesdeadbug.plist"
  11. static BOOL Enabled;
  12. static __strong NSString* kCurrentiOSVersion = nil;
  13. static __strong NSString* kCurrentDeviceType = nil;
  14. static __strong NSString* kCurrentiOSVersionSpoof = nil; //no idea why theres were chars, just overcomplicating things.
  15. const char * kCurrentDeviceTypeSpoof;
  16. static __strong NSString* kUserAgent = @"User-Agent";
  17. static __strong NSString* kFormatHeader = @"/%@ ";
  18. %group itunesstoredHooks
  19. %hook NSMutableURLRequest
  20. - (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field
  21. {
  22. %log;
  23. //TODO: absolutely do NOT check this here every time... will be okay for now.
  24. NSDictionary *LowerInstallPrefs = [[[NSDictionary alloc] initWithContentsOfFile:@PLIST_PATH_Settings]?:[NSDictionary dictionary] copy];
  25. //HBLogInfo(@"###LowerInstallPrefs: %@", LowerInstallPrefs);
  26. Enabled = (BOOL)[[LowerInstallPrefs objectForKey:@"Enabled"]?:@YES boolValue];
  27. kCurrentiOSVersionSpoof = [LowerInstallPrefs objectForKey:@"SpoofVersion"]?:@"11.1";
  28. if(Enabled && field && value && kUserAgent && [field isEqualToString:kUserAgent] && kCurrentiOSVersion && kCurrentiOSVersionSpoof) {
  29. HBLogInfo(@"currentiOSVersion: %@ value: %@", kCurrentiOSVersion, value);
  30. if([value rangeOfString:kCurrentiOSVersion].location != NSNotFound) {
  31. //HBLogInfo(@"### are we inside here???");
  32. value = [value stringByReplacingOccurrencesOfString:[NSString stringWithFormat:kFormatHeader, kCurrentiOSVersion] withString:[NSString stringWithFormat:kFormatHeader, kCurrentiOSVersionSpoof]];
  33. //HBLogInfo(@"### are we inside here??? 2");
  34. //value = [value stringByReplacingOccurrencesOfString:[NSString stringWithFormat:kFormatHeader, kCurrentDeviceType] withString:[NSString stringWithFormat:kFormatHeader, [NSString stringWithUTF8String:kCurrentDeviceTypeSpoof]]];
  35. //HBLogInfo(@"### are we inside here??? 3");
  36. } else {
  37. HBLogInfo(@"#### value: %@ not found in %@", value, kCurrentiOSVersion);
  38. }
  39. }
  40. %orig(value, field);
  41. }
  42. %end
  43. %end
  44. %group installdHooks
  45. %hook MIBundle
  46. /*
  47. - (BOOL)isApplicableToCurrentOSVersionWithError:(NSError *)error {
  48. %log;
  49. return YES;
  50. }
  51. */
  52. - (NSString*)minimumOSVersion
  53. {
  54. %log;
  55. NSString* ret = %orig;
  56. ret = @"2.0";
  57. return ret;
  58. }
  59. /*
  60. - (_Bool)isApplicableToCurrentDeviceCapabilitiesWithError:(id *)arg1
  61. {
  62. %log;
  63. BOOL orig = %orig;
  64. return YES;
  65. }
  66. - (_Bool)isApplicableToOSVersion:(id)arg1 error:(id *)arg2{
  67. %log;
  68. BOOL orig = %orig;
  69. return YES;
  70. }
  71. - (_Bool)isApplicableToCurrentOSVersionWithError:(id *)arg1{
  72. %log;
  73. BOOL orig = %orig;
  74. return YES;
  75. }
  76. - (_Bool)isApplicableToCurrentDeviceFamilyWithError:(id *)arg1{
  77. %log;
  78. BOOL orig = %orig;
  79. return YES;
  80. }
  81. - (_Bool)isCompatibleWithDeviceFamily:(int)arg1{
  82. %log;
  83. BOOL orig = %orig;
  84. return YES;
  85. }
  86. - (NSArray *)supportedDevices
  87. {
  88. NSArray* ret = %orig?:@[];
  89. if(kCurrentDeviceType && ![ret containsObject:kCurrentDeviceType]) {
  90. NSMutableArray* retMut = [ret mutableCopy];
  91. [retMut addObject:[kCurrentDeviceType copy]];
  92. ret = [retMut copy];
  93. }
  94. return ret;
  95. }
  96. */
  97. %end
  98. %end
  99. /* Set platform binary flag */
  100. #define FLAG_PLATFORMIZE (1 << 1)
  101. void platformize_me() {
  102. void* handle = dlopen("/usr/lib/libjailbreak.dylib", RTLD_LAZY);
  103. if (!handle) return;
  104. // Reset errors
  105. dlerror();
  106. typedef void (*fix_entitle_prt_t)(pid_t pid, uint32_t what);
  107. fix_entitle_prt_t ptr = (fix_entitle_prt_t)dlsym(handle, "jb_oneshot_entitle_now");
  108. const char *dlsym_error = dlerror();
  109. if (dlsym_error) return;
  110. ptr(getpid(), FLAG_PLATFORMIZE);
  111. }
  112. static void settingsChangedLowerInstall()
  113. {
  114. @autoreleasepool {
  115. NSDictionary *LowerInstallPrefs = [[[NSDictionary alloc] initWithContentsOfFile:@PLIST_PATH_Settings]?:[NSDictionary dictionary] copy];
  116. Enabled = (BOOL)[[LowerInstallPrefs objectForKey:@"Enabled"]?:@YES boolValue];
  117. kCurrentiOSVersionSpoof = [LowerInstallPrefs objectForKey:@"SpoofVersion"]?:@"11.1";
  118. //kCurrentiOSVersionSpoof = (const char*)(malloc([CurrentiOSVersionSpoof length]));
  119. //memcpy((void*)kCurrentiOSVersionSpoof,(const void*)CurrentiOSVersionSpoof.UTF8String, [CurrentiOSVersionSpoof length]);
  120. //((char*)kCurrentiOSVersionSpoof)[[CurrentiOSVersionSpoof length]] = '\0';
  121. NSString* CurrentDeviceTypeSpoof = [LowerInstallPrefs objectForKey:@"SpoofDevice"]?:@"AppleTV5,3";
  122. kCurrentDeviceTypeSpoof = (const char*)(malloc([CurrentDeviceTypeSpoof length]));
  123. memcpy((void*)kCurrentDeviceTypeSpoof,(const void*)CurrentDeviceTypeSpoof.UTF8String, [CurrentDeviceTypeSpoof length]);
  124. ((char*)kCurrentDeviceTypeSpoof)[[CurrentDeviceTypeSpoof length]] = '\0';
  125. }
  126. }
  127. %group settingsHooks
  128. /*
  129. %hook TVSettingsMainViewController
  130. - (id)loadSettingGroups {
  131. %log;
  132. NSArray* groups = %orig;
  133. TSKSettingGroup *group = groups[0];
  134. // +[<TSKSettingItem: 0x1ad71bc88> childPaneItemWithTitle:General description:(null) representedObject:(null) keyPath:(null) childControllerClass:TVSettingsGeneralViewController]
  135. Class theClass = NSClassFromString(@"TVSettingsTweakViewController");
  136. id testItem = [TSKSettingItem childPaneItemWithTitle:@"Tweaks" description:nil representedObject:nil keyPath:nil childControllerClass:theClass];
  137. HBLogDebug(@"testItem = %@", testItem);
  138. NSArray *settingsItems = [group valueForKey:@"settingItems"];
  139. HBLogDebug(@"settingsItems = %@", settingsItems);
  140. NSMutableArray *newItems = [settingsItems mutableCopy];
  141. //[newItems addObject:testItem];
  142. [newItems insertObject:testItem atIndex:7];
  143. HBLogDebug(@"newItems = %@", newItems);
  144. [group setSettingItems:newItems];
  145. return @[group];
  146. }
  147. %end
  148. */
  149. %end
  150. %ctor
  151. {
  152. HBLogInfo(@"### DalesDeadBug reporting for duty!");
  153. //platformize_me();
  154. //HBDebugLog(@"Dales Dead Bug reporting for duty!");
  155. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)settingsChangedLowerInstall, CFSTR("com.julioverne.lowerinstall/SettingsChanged"), NULL, CFNotificationSuspensionBehaviorCoalesce);
  156. settingsChangedLowerInstall();
  157. struct utsname systemInfo;
  158. uname(&systemInfo);
  159. kCurrentDeviceType = [NSString stringWithFormat:@"%s", systemInfo.machine];
  160. kCurrentiOSVersion = [NSString stringWithFormat:@"%@", [[UIDevice currentDevice] systemVersion]];
  161. if(strcmp(__progname, "itunesstored") == 0) {
  162. HBLogInfo(@"### DalesDeadBug: itunesstored");
  163. %init(itunesstoredHooks);
  164. } else if(strcmp(__progname, "installd") == 0){
  165. HBLogInfo(@"### DalesDeadBug: installd");
  166. %init(installdHooks);
  167. } else {
  168. %init(settingsHooks);
  169. }
  170. }