DalesDeadBug.xm 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. value = [value stringByReplacingOccurrencesOfString:[NSString stringWithFormat:kFormatHeader, kCurrentiOSVersion] withString:[NSString stringWithFormat:kFormatHeader, [NSString stringWithUTF8String:kCurrentiOSVersionSpoof]]];
  26. value = [value stringByReplacingOccurrencesOfString:[NSString stringWithFormat:kFormatHeader, kCurrentDeviceType] withString:[NSString stringWithFormat:kFormatHeader, [NSString stringWithUTF8String:kCurrentDeviceTypeSpoof]]];
  27. }
  28. }
  29. %orig(value, field);
  30. }
  31. %end
  32. %end
  33. %group installdHooks
  34. %hook MIBundle
  35. - (NSString*)minimumOSVersion
  36. {
  37. %log;
  38. NSString* ret = %orig;
  39. ret = @"2.0";
  40. return ret;
  41. }
  42. /*
  43. - (_Bool)isApplicableToCurrentDeviceCapabilitiesWithError:(id *)arg1
  44. {
  45. %log;
  46. BOOL orig = %orig;
  47. return YES;
  48. }
  49. - (_Bool)isApplicableToOSVersion:(id)arg1 error:(id *)arg2{
  50. %log;
  51. return YES;
  52. }
  53. - (_Bool)isApplicableToCurrentOSVersionWithError:(id *)arg1{
  54. %log;
  55. return YES;
  56. }
  57. - (_Bool)isApplicableToCurrentDeviceFamilyWithError:(id *)arg1{
  58. %log;
  59. return YES;
  60. }
  61. - (_Bool)isCompatibleWithDeviceFamily:(int)arg1{
  62. %log;
  63. return YES;
  64. }
  65. */
  66. - (NSArray *)supportedDevices
  67. {
  68. NSArray* ret = %orig?:@[];
  69. if(kCurrentDeviceType && ![ret containsObject:kCurrentDeviceType]) {
  70. NSMutableArray* retMut = [ret mutableCopy];
  71. [retMut addObject:[kCurrentDeviceType copy]];
  72. ret = [retMut copy];
  73. }
  74. return ret;
  75. }
  76. %end
  77. static void settingsChangedLowerInstall()
  78. {
  79. @autoreleasepool {
  80. NSDictionary *LowerInstallPrefs = [[[NSDictionary alloc] initWithContentsOfFile:@PLIST_PATH_Settings]?:[NSDictionary dictionary] copy];
  81. Enabled = (BOOL)[[LowerInstallPrefs objectForKey:@"Enabled"]?:@YES boolValue];
  82. NSString* CurrentiOSVersionSpoof = [LowerInstallPrefs objectForKey:@"SpoofVersion"]?:@"11.1";
  83. kCurrentiOSVersionSpoof = (const char*)(malloc([CurrentiOSVersionSpoof length]));
  84. memcpy((void*)kCurrentiOSVersionSpoof,(const void*)CurrentiOSVersionSpoof.UTF8String, [CurrentiOSVersionSpoof length]);
  85. ((char*)kCurrentiOSVersionSpoof)[[CurrentiOSVersionSpoof length]] = '\0';
  86. NSString* CurrentDeviceTypeSpoof = [LowerInstallPrefs objectForKey:@"SpoofDevice"]?:@"AppleTV5,3";
  87. kCurrentDeviceTypeSpoof = (const char*)(malloc([CurrentDeviceTypeSpoof length]));
  88. memcpy((void*)kCurrentDeviceTypeSpoof,(const void*)CurrentDeviceTypeSpoof.UTF8String, [CurrentDeviceTypeSpoof length]);
  89. ((char*)kCurrentDeviceTypeSpoof)[[CurrentDeviceTypeSpoof length]] = '\0';
  90. }
  91. }
  92. %ctor
  93. {
  94. //HBDebugLog(@"Dales Dead Bug reporting for duty!");
  95. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)settingsChangedLowerInstall, CFSTR("com.julioverne.lowerinstall/SettingsChanged"), NULL, CFNotificationSuspensionBehaviorCoalesce);
  96. settingsChangedLowerInstall();
  97. struct utsname systemInfo;
  98. uname(&systemInfo);
  99. kCurrentDeviceType = [NSString stringWithFormat:@"%s", systemInfo.machine];
  100. kCurrentiOSVersion = [NSString stringWithFormat:@"%@", [[UIDevice currentDevice] systemVersion]];
  101. if(strcmp(__progname, "itunesstored") == 0) {
  102. %init(itunesstoredHooks);
  103. } else {
  104. %init(installdHooks);
  105. }
  106. }