McareCrackCheck.swift 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. return true
  45. let path:String = self.bundlePath.appending("/Info.plist")
  46. let fileInfo:NSDictionary = Bundle.main.infoDictionary! as NSDictionary
  47. let fileManager:FileManager = FileManager.default
  48. var fileAttr:NSDictionary!
  49. do {
  50. fileAttr = try fileManager.attributesOfItem(atPath: path) as NSDictionary
  51. } catch {
  52. mcareLog?.error(output:"")
  53. }
  54. if fileAttr != nil {
  55. let cSIDArr = ["Si", "gne", "rIde", "ntity"]
  56. let cSID:String = cSIDArr.joined()
  57. if fileInfo.value(forKey: cSID) != nil {
  58. return true
  59. }
  60. }
  61. return false
  62. }
  63. func checkPid() -> Bool {
  64. let root:Int = Int(getpid())
  65. if root <= 10 {
  66. return true
  67. }
  68. return false
  69. }
  70. func checkPiratNameCodeSignature() -> Bool {
  71. let fileExists:Bool = FileManager.default.fileExists(atPath: bundlePath.appending("/_CodeSignature"))
  72. if !fileExists {
  73. return true
  74. }
  75. return false
  76. }
  77. func checkPiratNameCodeResource() -> Bool {
  78. let fileExists:Bool = FileManager.default.fileExists(atPath: bundlePath.appending("/_CodeSignature/CodeResources"))
  79. if !fileExists {
  80. return true
  81. }
  82. return false
  83. }
  84. }