fucksigningservices.m 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // fuck-signing-services.m
  3. // Meridian
  4. //
  5. // Created by Ben Sparkes on 07/01/2018.
  6. // Copyright © 2018 Ben Sparkes. All rights reserved.
  7. //
  8. #import "fucksigningservices.h"
  9. @interface NSString (profileHelper)
  10. - (id)dictionaryFromString;
  11. @end
  12. @implementation NSString (profileHelper)
  13. // convert basic XML plist string from the profile and convert it into a mutable nsdictionary
  14. - (id)dictionaryFromString
  15. {
  16. NSData *theData = [self dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
  17. id theDict = [NSPropertyListSerialization propertyListWithData:theData
  18. options:NSPropertyListMutableContainersAndLeaves
  19. format:nil
  20. error:nil];
  21. return theDict;
  22. }
  23. @end
  24. @implementation fucksigningservices : NSObject
  25. // creds @nitoTV/lechium the fuckin' madman
  26. // https://github.com/lechium/ProvisioningProfileCleaner/blob/master/ProvisioningProfileCleaner/KBProfileHelper.m#L648
  27. + (Boolean)appIsPirated:(NSString *)profilePath
  28. {
  29. NSString *fileContents = [NSString stringWithContentsOfFile:profilePath
  30. encoding:NSUTF8StringEncoding
  31. error:nil];
  32. NSUInteger fileLength = [fileContents length];
  33. if (fileLength == 0) return false;
  34. // find NSRange location of <?xml to pass by all the "garbage" data before our plist
  35. NSUInteger startingLocation = [fileContents rangeOfString:@"<?xml"].location;
  36. // find NSRange of the end of the plist (there is "junk" cert data after our plist info as well
  37. NSRange endingRange = [fileContents rangeOfString:@"</plist>"];
  38. // adjust the location of endingRange to include </plist> into our newly trimmed string.
  39. NSUInteger endingLocation = endingRange.location + endingRange.length;
  40. // offset the ending location to trim out the "garbage" before <?xml
  41. NSUInteger endingLocationAdjusted = endingLocation - startingLocation;
  42. // create the final range of the string data from <?xml to </plist>
  43. NSRange plistRange = NSMakeRange(startingLocation, endingLocationAdjusted);
  44. NSString *plistString = [fileContents substringWithRange:plistRange];
  45. NSMutableDictionary *dict = [plistString dictionaryFromString];
  46. // Grab provisioning entries
  47. NSObject *provisionsAllDevices = [dict objectForKey:@"ProvisionsAllDevices"];
  48. NSArray *provisionedDevices = [dict objectForKey:@"ProvisionedDevices"];
  49. // Check whether keys are present & evaluate
  50. return (provisionsAllDevices != nil &&
  51. provisionedDevices == nil);
  52. }
  53. @end