You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.1 KiB

  1. // DTTJailbreakDetection.m
  2. //
  3. // Copyright (c) 2014 Doan Truong Thi
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy of
  6. // this software and associated documentation files (the "Software"), to deal in
  7. // the Software without restriction, including without limitation the rights to
  8. // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  9. // the Software, and to permit persons to whom the Software is furnished to do so,
  10. // subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in all
  13. // copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  17. // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  18. // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  19. // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. //
  22. #import "DTTJailbreakDetection.h"
  23. @implementation DTTJailbreakDetection
  24. + (BOOL)isJailbroken
  25. {
  26. #if !(TARGET_IPHONE_SIMULATOR)
  27. FILE *file = fopen("/Applications/Cydia.app", "r");
  28. if (file) {
  29. fclose(file);
  30. return YES;
  31. }
  32. file = fopen("/Library/MobileSubstrate/MobileSubstrate.dylib", "r");
  33. if (file) {
  34. fclose(file);
  35. return YES;
  36. }
  37. file = fopen("/bin/bash", "r");
  38. if (file) {
  39. fclose(file);
  40. return YES;
  41. }
  42. file = fopen("/usr/sbin/sshd", "r");
  43. if (file) {
  44. fclose(file);
  45. return YES;
  46. }
  47. file = fopen("/etc/apt", "r");
  48. if (file) {
  49. fclose(file);
  50. return YES;
  51. }
  52. file = fopen("/usr/bin/ssh", "r");
  53. if (file) {
  54. fclose(file);
  55. return YES;
  56. }
  57. NSFileManager *fileManager = [NSFileManager defaultManager];
  58. if ([fileManager fileExistsAtPath:@"/Applications/Cydia.app"]) {
  59. return YES;
  60. } else if ([fileManager fileExistsAtPath:@"/Library/MobileSubstrate/MobileSubstrate.dylib"]) {
  61. return YES;
  62. } else if ([fileManager fileExistsAtPath:@"/bin/bash"]) {
  63. return YES;
  64. } else if ([fileManager fileExistsAtPath:@"/usr/sbin/sshd"]) {
  65. return YES;
  66. } else if ([fileManager fileExistsAtPath:@"/etc/apt"]) {
  67. return YES;
  68. } else if ([fileManager fileExistsAtPath:@"/usr/bin/ssh"]) {
  69. return YES;
  70. }
  71. // Check if the app can access outside of its sandbox
  72. NSError *error = nil;
  73. NSString *string = @".";
  74. [string writeToFile:@"/private/jailbreak.txt" atomically:YES encoding:NSUTF8StringEncoding error:&error];
  75. if (!error) {
  76. return YES;
  77. } else {
  78. [fileManager removeItemAtPath:@"/private/jailbreak.txt" error:nil];
  79. }
  80. // Check if the app can open a Cydia's URL scheme
  81. if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"cydia://package/com.example.package"]]) {
  82. return YES;
  83. }
  84. #endif
  85. return NO;
  86. }
  87. @end