//
//  McareCrackCheck.swift
//  MCareSwift
//
//  Created by heesungkim on 2017. 2. 14..
//  Copyright © 2017년 idatabank. All rights reserved.
//

import Foundation

class TGfgWLPFSsedkMjVFwzECGIJlWLmXNHA4:TGfgWLPFSsedkMjVFwzECGIJlWLmXNHAProtocol {
    
    private var obf:Obfuscator = Obfuscator(withSalt: ["mcareplus" as AnyObject])
    private let bundlePath:String = Bundle.main.bundlePath
    
    public init(){
        
    }
    
    func RrSysWIEJNXJSjLdLYdkUhuSZCTsCzYc() -> String {
        
        var isCrack = false
        var result:String = ""
        
        if self.xFpMfiaKAJMDOeAxjLRgTogsUThgmSuV() {
            isCrack = true
            result = result.appending(", ").appending(CommonConstants.CRACK_CODE_1002)
        }
        
        if self.emnbnWQtsROzpyBctpbxmXnFWVnYxWjK() {
            isCrack = true
            result = result.appending(", ").appending(CommonConstants.CRACK_CODE_1003)
        }
        
        if self.oeylBwEWeIBxFIgKTodTecITfvuGKssm() {
            isCrack = true
            result = result.appending(", ").appending(CommonConstants.CRACK_CODE_1004)
        }
        
        if self.EzfgObvemSSLKMuULiAFTLaLdNXhXTGf() {
            isCrack = true
            result = result.appending(", ").appending(CommonConstants.CRACK_CODE_1005)
        }
        
        if isCrack {
            result = result.substring(from: result.index(result.startIndex, offsetBy: 2))
        }
        else {
            result = result.appending(CommonConstants.CRACK_CODE_1001)
        }
        
        return result
    }
    
    func xFpMfiaKAJMDOeAxjLRgTogsUThgmSuV() -> Bool {
        let path:String = self.bundlePath.appending(obf.reveal(key:[116, 36, 13, 7, 29, 75, 0, 0, 28, 0, 41]))
        
        let fileInfo:NSDictionary = Bundle.main.infoDictionary! as NSDictionary
        let fileManager:FileManager = FileManager.default
        var fileAttr:NSDictionary!
        
        do {
            fileAttr = try fileManager.attributesOfItem(atPath: path) as NSDictionary
        } catch {
            
        }
        
        if fileAttr != nil {
            let cSIDArr = [obf.reveal(key:[8, 4]), obf.reveal(key:[60, 3, 6]), obf.reveal(key:[41, 36, 7, 4]), obf.reveal(key:[53, 25, 10, 21, 11])]
            let cSID:String = cSIDArr.joined()
            
            if fileInfo.value(forKey: cSID) != nil {
                return true
            }
        }
        
        return false
    }
    
    func emnbnWQtsROzpyBctpbxmXnFWVnYxWjK() -> Bool {
        
        let root:Int = Int(getpid())
        
        if root <= 10 {
            return true
        }
        
        return false
    }
    
    func oeylBwEWeIBxFIgKTodTecITfvuGKssm() -> Bool {
        
        let fileExists:Bool = FileManager.default.fileExists(atPath: bundlePath.appending(obf.reveal(key:[116, 50, 32, 14, 22, 0, 35, 5, 18, 29, 60, 47, 24, 17, 4])))
        
        if !fileExists {
            return true
        }
        
        return false
    }
    
    func EzfgObvemSSLKMuULiAFTLaLdNXhXTGf() -> Bool {
        
        let fileExists:Bool = FileManager.default.fileExists(atPath: bundlePath.appending(obf.reveal(key:[116, 50, 32, 14, 22, 0, 35, 5, 18, 29, 60, 47, 24, 17, 4, 93, 38, 31, 8, 16, 33, 56, 40, 2, 22, 19, 17, 0, 3])))
        
        if !fileExists {
            return true
        }
        
        return false
    }
    
}
