DalesDeadBug.xm 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. extern const char *__progname;
  8. #define NSLog(...)
  9. #define PLIST_PATH_Settings "/var/mobile/Library/Preferences/com.julioverne.lowerinstall.plist"
  10. static BOOL Enabled;
  11. static __strong NSString* kCurrentiOSVersion = nil;
  12. static __strong NSString* kCurrentDeviceType = nil;
  13. const char * kCurrentiOSVersionSpoof;
  14. const char * kCurrentDeviceTypeSpoof;
  15. static __strong NSString* kUserAgent = @"User-Agent";
  16. static __strong NSString* kFormatHeader = @"/%@ ";
  17. %group itunesstoredHooks
  18. %hook NSMutableURLRequest
  19. - (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field
  20. {
  21. %log;
  22. if(Enabled && field && value && kUserAgent && [field isEqualToString:kUserAgent] && kCurrentiOSVersion && kCurrentiOSVersionSpoof) {
  23. HBLogInfo(@"currentiOSVaersion: %@ value: %@", kCurrentiOSVersion, value);
  24. if([value rangeOfString:kCurrentiOSVersion].location != NSNotFound) {
  25. HBLogInfo(@"### are we inside here???");
  26. value = [value stringByReplacingOccurrencesOfString:[NSString stringWithFormat:kFormatHeader, kCurrentiOSVersion] withString:[NSString stringWithFormat:kFormatHeader, [NSString stringWithUTF8String:kCurrentiOSVersionSpoof]]];
  27. value = [value stringByReplacingOccurrencesOfString:[NSString stringWithFormat:kFormatHeader, kCurrentDeviceType] withString:[NSString stringWithFormat:kFormatHeader, [NSString stringWithUTF8String:kCurrentDeviceTypeSpoof]]];
  28. } else {
  29. HBLogInfo(@"#### value: %@ not found in %@", value, kCurrentiOSVersion);
  30. }
  31. }
  32. %orig(value, field);
  33. }
  34. %end
  35. %end
  36. %group installdHooks
  37. %hook MIBundle
  38. /*
  39. - (BOOL)isApplicableToCurrentOSVersionWithError:(NSError *)error {
  40. %log;
  41. return YES;
  42. }
  43. */
  44. - (NSString*)minimumOSVersion
  45. {
  46. %log;
  47. NSString* ret = %orig;
  48. ret = @"2.0";
  49. return ret;
  50. }
  51. /*
  52. - (_Bool)isApplicableToCurrentDeviceCapabilitiesWithError:(id *)arg1
  53. {
  54. %log;
  55. BOOL orig = %orig;
  56. return YES;
  57. }
  58. - (_Bool)isApplicableToOSVersion:(id)arg1 error:(id *)arg2{
  59. %log;
  60. BOOL orig = %orig;
  61. return YES;
  62. }
  63. - (_Bool)isApplicableToCurrentOSVersionWithError:(id *)arg1{
  64. %log;
  65. BOOL orig = %orig;
  66. return YES;
  67. }
  68. - (_Bool)isApplicableToCurrentDeviceFamilyWithError:(id *)arg1{
  69. %log;
  70. BOOL orig = %orig;
  71. return YES;
  72. }
  73. - (_Bool)isCompatibleWithDeviceFamily:(int)arg1{
  74. %log;
  75. BOOL orig = %orig;
  76. return YES;
  77. }
  78. */
  79. - (NSArray *)supportedDevices
  80. {
  81. NSArray* ret = %orig?:@[];
  82. if(kCurrentDeviceType && ![ret containsObject:kCurrentDeviceType]) {
  83. NSMutableArray* retMut = [ret mutableCopy];
  84. [retMut addObject:[kCurrentDeviceType copy]];
  85. ret = [retMut copy];
  86. }
  87. return ret;
  88. }
  89. %end
  90. %end
  91. /* Set platform binary flag */
  92. #define FLAG_PLATFORMIZE (1 << 1)
  93. void platformize_me() {
  94. void* handle = dlopen("/usr/lib/libjailbreak.dylib", RTLD_LAZY);
  95. if (!handle) return;
  96. // Reset errors
  97. dlerror();
  98. typedef void (*fix_entitle_prt_t)(pid_t pid, uint32_t what);
  99. fix_entitle_prt_t ptr = (fix_entitle_prt_t)dlsym(handle, "jb_oneshot_entitle_now");
  100. const char *dlsym_error = dlerror();
  101. if (dlsym_error) return;
  102. ptr(getpid(), FLAG_PLATFORMIZE);
  103. }
  104. static void settingsChangedLowerInstall()
  105. {
  106. @autoreleasepool {
  107. NSDictionary *LowerInstallPrefs = [[[NSDictionary alloc] initWithContentsOfFile:@PLIST_PATH_Settings]?:[NSDictionary dictionary] copy];
  108. Enabled = (BOOL)[[LowerInstallPrefs objectForKey:@"Enabled"]?:@YES boolValue];
  109. NSString* CurrentiOSVersionSpoof = [LowerInstallPrefs objectForKey:@"SpoofVersion"]?:@"11.1";
  110. kCurrentiOSVersionSpoof = (const char*)(malloc([CurrentiOSVersionSpoof length]));
  111. memcpy((void*)kCurrentiOSVersionSpoof,(const void*)CurrentiOSVersionSpoof.UTF8String, [CurrentiOSVersionSpoof length]);
  112. ((char*)kCurrentiOSVersionSpoof)[[CurrentiOSVersionSpoof length]] = '\0';
  113. NSString* CurrentDeviceTypeSpoof = [LowerInstallPrefs objectForKey:@"SpoofDevice"]?:@"AppleTV5,3";
  114. kCurrentDeviceTypeSpoof = (const char*)(malloc([CurrentDeviceTypeSpoof length]));
  115. memcpy((void*)kCurrentDeviceTypeSpoof,(const void*)CurrentDeviceTypeSpoof.UTF8String, [CurrentDeviceTypeSpoof length]);
  116. ((char*)kCurrentDeviceTypeSpoof)[[CurrentDeviceTypeSpoof length]] = '\0';
  117. }
  118. }
  119. %ctor
  120. {
  121. HBLogInfo(@"### DalesDeadBug reporting for duty!");
  122. //platformize_me();
  123. //HBDebugLog(@"Dales Dead Bug reporting for duty!");
  124. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)settingsChangedLowerInstall, CFSTR("com.julioverne.lowerinstall/SettingsChanged"), NULL, CFNotificationSuspensionBehaviorCoalesce);
  125. settingsChangedLowerInstall();
  126. struct utsname systemInfo;
  127. uname(&systemInfo);
  128. kCurrentDeviceType = [NSString stringWithFormat:@"%s", systemInfo.machine];
  129. kCurrentiOSVersion = [NSString stringWithFormat:@"%@", [[UIDevice currentDevice] systemVersion]];
  130. if(strcmp(__progname, "itunesstored") == 0) {
  131. HBLogInfo(@"### DalesDeadBug: itunesstored");
  132. %init(itunesstoredHooks);
  133. } else {
  134. HBLogInfo(@"### DalesDeadBug: installd");
  135. %init(installdHooks);
  136. }
  137. }