McareCrackCheck.swift 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // McareCrackCheck.swift
  3. // MCareSwift
  4. //
  5. // Created by heesungkim on 2017. 2. 14..
  6. // Copyright © 2017년 idatabank. All rights reserved.
  7. //
  8. import Foundation
  9. import MCareFramework
  10. class McareCrackCheck {
  11. private let bundlePath:String = Bundle.main.bundlePath
  12. private var mcareLog:MCareLogger?
  13. public init(){
  14. mcareLog = MCareLogger.sharedInstance()
  15. }
  16. func isCrack() -> String {
  17. var isCrack = false
  18. var result:String = ""
  19. if self.checkInfoFile() {
  20. isCrack = true
  21. result = result.appending(", ").appending(CommonConstants.CRACK_CODE_1002)
  22. }
  23. if self.checkPid() {
  24. isCrack = true
  25. result = result.appending(", ").appending(CommonConstants.CRACK_CODE_1003)
  26. }
  27. if self.checkPiratNameCodeSignature() {
  28. isCrack = true
  29. result = result.appending(", ").appending(CommonConstants.CRACK_CODE_1004)
  30. }
  31. if self.checkPiratNameCodeResource() {
  32. isCrack = true
  33. result = result.appending(", ").appending(CommonConstants.CRACK_CODE_1005)
  34. }
  35. if isCrack {
  36. result = result.substring(from: result.index(result.startIndex, offsetBy: 2))
  37. }
  38. else {
  39. result = result.appending(CommonConstants.CRACK_CODE_1001)
  40. }
  41. return result
  42. }
  43. func checkInfoFile() -> Bool {
  44. let path:String = self.bundlePath.appending("/Info.plist")
  45. let fileInfo:NSDictionary = Bundle.main.infoDictionary! as NSDictionary
  46. let fileManager:FileManager = FileManager.default
  47. var fileAttr:NSDictionary!
  48. do {
  49. fileAttr = try fileManager.attributesOfItem(atPath: path) as NSDictionary
  50. } catch {
  51. mcareLog?.error(output:"")
  52. }
  53. if fileAttr != nil {
  54. let cSIDArr = ["Si", "gne", "rIde", "ntity"]
  55. let cSID:String = cSIDArr.joined()
  56. if fileInfo.value(forKey: cSID) != nil {
  57. return true
  58. }
  59. }
  60. return false
  61. }
  62. func checkPid() -> Bool {
  63. let root:Int = Int(getpid())
  64. if root <= 10 {
  65. return true
  66. }
  67. return false
  68. }
  69. func checkPiratNameCodeSignature() -> Bool {
  70. let fileExists:Bool = FileManager.default.fileExists(atPath: bundlePath.appending("/_CodeSignature"))
  71. if !fileExists {
  72. return true
  73. }
  74. return false
  75. }
  76. func checkPiratNameCodeResource() -> Bool {
  77. let fileExists:Bool = FileManager.default.fileExists(atPath: bundlePath.appending("/_CodeSignature/CodeResources"))
  78. if !fileExists {
  79. return true
  80. }
  81. return false
  82. }
  83. }