SecurityShield.swift 134 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183
  1. //
  2. // SecurityShield.swift
  3. // StreamShield
  4. //
  5. // Created by Qindi on 31/10/24.
  6. //
  7. import Foundation
  8. import UIKit
  9. import nuSDKService
  10. import AVFoundation
  11. import AVKit
  12. import CoreTelephony
  13. import CryptoKit
  14. import MachO
  15. import CommonCrypto
  16. import SystemConfiguration.CaptiveNetwork
  17. import CoreLocation
  18. import Network
  19. public class SecurityShield: NSObject {
  20. static var dispatch: DispatchGroup?
  21. public static func check(appName: String, apiKey: String) {
  22. Preference.setAppId(value: appName)
  23. Preference.setAccount(value: apiKey)
  24. DispatchQueue.global().async {
  25. do {
  26. var id = Preference.getConnectionID()
  27. if id.isEmpty {
  28. let sDID = UIDevice.current.identifierForVendor?.uuidString ?? "UNK-DEVICE"
  29. id = String(sDID[sDID.index(sDID.endIndex, offsetBy: -5)...])
  30. Preference.setConnectionID(value: id)
  31. }
  32. if !API.bnuSDKServiceReady() || API.nGetCLXConnState() == 0 {
  33. let address = getAddressNew(apiKey:Preference.getAccount())
  34. if address.isEmpty {
  35. return
  36. }
  37. let addressConn = address.components(separatedBy: ":")[0]
  38. let port = Int(address.components(separatedBy: ":")[1]) ?? 0
  39. try API.initConnection(sAPIK: apiKey, cbiI: CallBackSS(), sTCPAddr: addressConn, nTCPPort: port, sUserID: id, sStartWH: "09:00")
  40. while (!API.bnuSDKServiceReady() || API.nGetCLXConnState() == 0) {
  41. Thread.sleep(forTimeInterval: 1)
  42. }
  43. }
  44. pull()
  45. } catch {
  46. }
  47. }
  48. }
  49. private static func getAddressNew(apiKey: String) -> String {
  50. var result = ""
  51. let url = URL(string: "\(Preference.getDomainOpr())dipp/NuN1v3rs3/Qm3r4i0/get_ip_domain?account=\(apiKey)")!
  52. let urlConfig = URLSessionConfiguration.default
  53. let sessionDelegate = SelfSignedURLSessionDelegate()
  54. urlConfig.requestCachePolicy = .returnCacheDataElseLoad
  55. urlConfig.timeoutIntervalForRequest = 10.0
  56. urlConfig.timeoutIntervalForResource = 10.0
  57. let semaphore = DispatchSemaphore(value: 0)
  58. let task = URLSession(configuration: urlConfig, delegate: sessionDelegate, delegateQueue: nil).dataTask(with: url) {(data, response, error) in
  59. guard let data = data,
  60. let url = response?.url,
  61. let httpResponse = response as? HTTPURLResponse,
  62. let fields = httpResponse.allHeaderFields as? [String: String] else {
  63. semaphore.signal()
  64. return
  65. }
  66. let dataEncode = String(data: data, encoding: .utf8)!
  67. if !dataEncode.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
  68. let dataDecodeBase64 = String(data: Data(base64Encoded: dataEncode)!, encoding: .utf8)!
  69. let dataRealDecode = UtilsSS.decrypt(str: dataDecodeBase64)
  70. do {
  71. if let jsonData = dataRealDecode.data(using: .utf8), let jsonObject = try JSONSerialization.jsonObject(with: jsonData, options: []) as? [String: Any] {
  72. var newDomain = jsonObject["domain"] as! String
  73. let jsonAddress = jsonObject["address"] as! [[String: Any]]
  74. let newIp = jsonAddress[0]["ip"] as! String
  75. let newPort = jsonAddress[0]["portI"] as! String
  76. if newDomain.substring(from: newDomain.count-1, to: nil) != "/" {
  77. newDomain += "/"
  78. }
  79. if (newIp+":"+newPort) != Preference.getIpOpr() || newDomain != Preference.getDomainOpr() {
  80. //check new domain
  81. if checkNewDomain(newDomain) {
  82. Preference.setDomainOpr(value: newDomain)
  83. Preference.setIpPortOpr(value: (newIp+":"+newPort))
  84. }
  85. }
  86. }
  87. } catch {
  88. }
  89. }
  90. semaphore.signal()
  91. }
  92. task.resume()
  93. _ = semaphore.wait(timeout: .distantFuture)
  94. result = Preference.getIpOpr()
  95. return result
  96. }
  97. private static func checkNewDomain(_ newDomain: String) -> Bool {
  98. var result = false
  99. let url = URL(string: "\(newDomain)dipp/NuN1v3rs3/Qm3r4i0/get_ip_domain?account=\(Preference.getAccount())")!
  100. let urlConfig = URLSessionConfiguration.default
  101. let sessionDelegate = SelfSignedURLSessionDelegate()
  102. urlConfig.requestCachePolicy = .returnCacheDataElseLoad
  103. urlConfig.timeoutIntervalForRequest = 10.0
  104. urlConfig.timeoutIntervalForResource = 10.0
  105. let semaphore = DispatchSemaphore(value: 0)
  106. let task = URLSession(configuration: urlConfig, delegate: sessionDelegate, delegateQueue: nil).dataTask(with: url) {(data, response, error) in
  107. if let httpResponse = response as? HTTPURLResponse {
  108. if httpResponse.statusCode == 200 {
  109. guard let url = response?.url,
  110. let fields = httpResponse.allHeaderFields as? [String: String] else {
  111. semaphore.signal()
  112. return
  113. }
  114. result = true
  115. }
  116. }
  117. semaphore.signal()
  118. }
  119. task.resume()
  120. _ = semaphore.wait(timeout: .distantFuture)
  121. return result
  122. }
  123. private static func pull() {
  124. let me: String! = SecureUserDefaultsSS.shared.value(forKey: "me") ?? Preference.getConnectionID()
  125. let tmessage = TMessageSS()
  126. tmessage.mCode = "SS01"
  127. tmessage.mStatus = CoreMessage_TMessageUtil.getTID()
  128. tmessage.mPIN = me
  129. tmessage.mBodies["Api"] = Preference.getAccount()
  130. tmessage.mBodies["AAN"] = Preference.getAppId()
  131. tmessage.mBodies["type"] = "0"
  132. DispatchQueue.global().async{
  133. postDataWithCookiesAndUserAgent(from: URL(string: Preference.getDomainOpr() + "get_feature_access_new")!) { data, response, error in
  134. let response = response as? HTTPURLResponse
  135. if response?.statusCode != 200 || error != nil {
  136. return
  137. }
  138. if let data = data, let responseString = String(data: data, encoding: .utf8) {
  139. Process.check(dataSS: responseString)
  140. } else {
  141. Process.check(dataSS: "")
  142. }
  143. }
  144. // if let response = Service.writeSync(message: tmessage) {
  145. // if response.isOk() {
  146. // let dataResp = response.getBody(key: "A112")
  147. // Process.check(dataSS: dataResp)
  148. // } else {
  149. // Process.check(dataSS: "")
  150. // }
  151. // } else {
  152. // Process.check(dataSS: "")
  153. // }
  154. }
  155. }
  156. static func postDataWithCookiesAndUserAgent(from url: URL, parameter: [String: Any] = [:], parameters: [[String: Any]] = [], isFormData: Bool = false, completion: @escaping (Data?, URLResponse?, Error?) -> ()) {
  157. let apiKey: String = Preference.getAccount()
  158. let me: String? = SecureUserDefaultsSS.shared.value(forKey: "me")
  159. var defaultParameter: [String : Any] = [
  160. "app_id": Preference.getAppId(),
  161. "apikey": apiKey,
  162. ]
  163. if me != nil {
  164. defaultParameter["f_pin"] = me
  165. }
  166. var jsonArray: [[String: Any]] = []
  167. if parameters.count == 0 {
  168. jsonArray.append(defaultParameter)
  169. } else {
  170. jsonArray = parameters
  171. }
  172. var jsonData: Data!
  173. if !isFormData {
  174. jsonData = try? JSONSerialization.data(withJSONObject: parameter.count == 0 ? jsonArray : parameter, options: [])
  175. } else {
  176. let formData = parameter.map { "\($0.key)=\($0.value)" }.joined(separator: "&")
  177. jsonData = formData.data(using: .utf8)
  178. }
  179. var request = URLRequest(url: url)
  180. request.httpMethod = "POST"
  181. // request.setValue(Utils.getUserAgent(), forHTTPHeaderField: "User-Agent")
  182. // request.setValue(Utils.getCookiesMobile(), forHTTPHeaderField: "Cookie")
  183. if isFormData {
  184. request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
  185. } else {
  186. request.setValue("application/json;charset=UTF-8", forHTTPHeaderField: "Content-Type")
  187. request.setValue("application/json", forHTTPHeaderField: "Accept")
  188. }
  189. request.httpBody = jsonData
  190. let urlConfig = URLSessionConfiguration.default
  191. urlConfig.timeoutIntervalForRequest = 30.0
  192. urlConfig.timeoutIntervalForResource = 60.0
  193. let sessionDelegate = SelfSignedURLSessionDelegate()
  194. let session = URLSession(configuration: urlConfig, delegate: sessionDelegate, delegateQueue: nil)
  195. let task = session.dataTask(with: request, completionHandler: completion)
  196. task.resume()
  197. }
  198. private static func showToast(message : String, font: UIFont = UIFont.systemFont(ofSize: 12, weight: .medium), controller: UIViewController) {
  199. let toastContainer = UIView(frame: CGRect())
  200. toastContainer.backgroundColor = controller.traitCollection.userInterfaceStyle == .dark ? .white.withAlphaComponent(0.6) : UIColor.mainColorSS.withAlphaComponent(0.6)
  201. toastContainer.alpha = 0.0
  202. toastContainer.layer.cornerRadius = 25;
  203. toastContainer.clipsToBounds = true
  204. let toastLabel = UILabel(frame: CGRect())
  205. toastLabel.textColor = controller.traitCollection.userInterfaceStyle == .dark ? .blackDarkModeSS : UIColor.white
  206. toastLabel.textAlignment = .center;
  207. toastLabel.font = font
  208. toastLabel.text = message
  209. toastLabel.clipsToBounds = true
  210. toastLabel.numberOfLines = 0
  211. toastContainer.addSubview(toastLabel)
  212. controller.view.addSubview(toastContainer)
  213. controller.view.bringSubviewToFront(toastContainer)
  214. toastLabel.translatesAutoresizingMaskIntoConstraints = false
  215. toastContainer.translatesAutoresizingMaskIntoConstraints = false
  216. let a1 = NSLayoutConstraint(item: toastLabel, attribute: .leading, relatedBy: .equal, toItem: toastContainer, attribute: .leading, multiplier: 1, constant: 15)
  217. let a2 = NSLayoutConstraint(item: toastLabel, attribute: .trailing, relatedBy: .equal, toItem: toastContainer, attribute: .trailing, multiplier: 1, constant: -15)
  218. let a3 = NSLayoutConstraint(item: toastLabel, attribute: .bottom, relatedBy: .equal, toItem: toastContainer, attribute: .bottom, multiplier: 1, constant: -15)
  219. let a4 = NSLayoutConstraint(item: toastLabel, attribute: .top, relatedBy: .equal, toItem: toastContainer, attribute: .top, multiplier: 1, constant: 15)
  220. toastContainer.addConstraints([a1, a2, a3, a4])
  221. let c1 = NSLayoutConstraint(item: toastContainer, attribute: .leading, relatedBy: .equal, toItem: controller.view, attribute: .leading, multiplier: 1, constant: 65)
  222. let c2 = NSLayoutConstraint(item: toastContainer, attribute: .trailing, relatedBy: .equal, toItem: controller.view, attribute: .trailing, multiplier: 1, constant: -65)
  223. let c3 = NSLayoutConstraint(item: toastContainer, attribute: .bottom, relatedBy: .equal, toItem: controller.view, attribute: .bottom, multiplier: 1, constant: -75)
  224. controller.view.addConstraints([c1, c2, c3])
  225. UIView.animate(withDuration: 0.5, delay: 0.0, options: .curveEaseIn, animations: {
  226. toastContainer.alpha = 1.0
  227. }, completion: { _ in
  228. UIView.animate(withDuration: 0.5, delay: 1.5, options: .curveEaseOut, animations: {
  229. toastContainer.alpha = 0.0
  230. }, completion: {_ in
  231. toastContainer.removeFromSuperview()
  232. })
  233. })
  234. }
  235. }
  236. private class Process: NSObject, CLLocationManagerDelegate {
  237. static func check(dataSS : String) {
  238. if !dataSS.isEmpty {
  239. if let jsonArray = try? JSONSerialization.jsonObject(with: dataSS.data(using: String.Encoding.utf8)!, options: JSONSerialization.ReadingOptions()) as? [AnyObject] {
  240. do {
  241. for jsonData in jsonArray {
  242. if jsonData["check_keylogger"]! != nil {
  243. Preference.setPreventKeylogger(value: jsonData["check_keylogger"]! as! String == "1")
  244. Preference.setPreventKeyloggerAction(value: jsonData["action"]! as! String)
  245. Preference.setKeyloggerAlertTitle(value: jsonData["alert_title"]! as! String)
  246. Preference.setKeyloggerAlertMessage(value: jsonData["alert_message"]! as! String)
  247. }
  248. if jsonData["check_screen_capture"]! != nil {
  249. Preference.setPreventScreenCapture(value: jsonData["check_screen_capture"]! as! String == "1")
  250. Preference.setPreventScreenCaptureAction(value: jsonData["action"]! as! String)
  251. Preference.setCheckScreenCaptureAlertTitle(value: jsonData["alert_title"]! as! String)
  252. Preference.setScreenCaptureAlertMessage(value: jsonData["alert_message"]! as! String)
  253. }
  254. if jsonData["check_emulator"]! != nil {
  255. Preference.setCheckEmulator(value: jsonData["check_emulator"]! as! String == "1")
  256. Preference.setCheckEmulatorAction(value: jsonData["action"]! as! String)
  257. Preference.setCheckEmulatorAlertTitle(value: jsonData["alert_title"]! as! String)
  258. Preference.setCheckEmulatorAlertMessage(value: jsonData["alert_message"]! as! String)
  259. }
  260. if jsonData["check_rooted_device"]! != nil {
  261. Preference.setCheckRooted(value: jsonData["check_rooted_device"]! as! String == "1")
  262. Preference.setCheckRootedAction(value: jsonData["action"]! as! String)
  263. Preference.setCheckRootedAlertTitle(value: jsonData["alert_title"]! as! String)
  264. Preference.setCheckRootedAlertMessage(value: jsonData["alert_message"]! as! String)
  265. }
  266. if jsonData["check_outdated_os"]! != nil {
  267. Preference.setCheckOutdatedOs(value: jsonData["check_outdated_os"]! as! String == "1")
  268. Preference.setCheckOutdatedOsAction(value: jsonData["action"]! as! String)
  269. Preference.setCheckOutdatedOsAlertTitle(value: jsonData["alert_title"]! as! String)
  270. Preference.setCheckOutdatedOsAlertMessage(value: jsonData["alert_message"]! as! String)
  271. }
  272. if jsonData["minimum_ios_version"]! != nil {
  273. Preference.setMinimumOsVersion(value: jsonData["minimum_ios_version"]! as! String)
  274. }
  275. if jsonData["check_sum"]! != nil {
  276. Preference.setCheckTempering(value: jsonData["check_sum"]! as! String == "1")
  277. Preference.setCheckTemperingAction(value: jsonData["action"]! as! String)
  278. Preference.setCheckTemperingAlertTitle(value: jsonData["alert_title"]! as! String)
  279. Preference.setCheckTemperingAlertMessage(value: jsonData["alert_message"]! as! String)
  280. }
  281. if jsonData["check_hook"]! != nil {
  282. Preference.setCheckHooked(value: jsonData["check_hook"]! as! String == "1")
  283. Preference.setCheckHookedAction(value: jsonData["action"]! as! String)
  284. Preference.setCheckHookedAlertTitle(value: jsonData["alert_title"]! as! String)
  285. Preference.setCheckHookedAlertMessage(value: jsonData["alert_message"]! as! String)
  286. }
  287. if jsonData["check_usb_debugging"]! != nil {
  288. Preference.setCheckDebugging(value: jsonData["check_usb_debugging"]! as! String == "1")
  289. Preference.setCheckDebuggingAction(value: jsonData["action"]! as! String)
  290. Preference.setCheckDebuggingAlertTitle(value: jsonData["alert_title"]! as! String)
  291. Preference.setCheckDebuggingAlertMessage(value: jsonData["alert_message"]! as! String)
  292. }
  293. if jsonData["check_screen_casting"]! != nil {
  294. Preference.setCheckScreenCasting(value: jsonData["check_screen_casting"]! as! String == "1")
  295. Preference.setCheckScreenCastingAction(value: jsonData["action"]! as! String)
  296. Preference.setCheckScreenCastingAlertTitle(value: jsonData["alert_title"]! as! String)
  297. Preference.setCheckScreenCastingAlertMessage(value: jsonData["alert_message"]! as! String)
  298. }
  299. if jsonData["check_screen_overlay"]! != nil {
  300. Preference.setCheckScreenOverlay(value: jsonData["check_screen_overlay"]! as! String == "1")
  301. Preference.setCheckScreenOverlayAction(value: jsonData["action"]! as! String)
  302. Preference.setCheckScreenOverlayAlertTitle(value: jsonData["alert_title"]! as! String)
  303. Preference.setCheckScreenOverlayAlertMessage(value: jsonData["alert_message"]! as! String)
  304. }
  305. if jsonData["check_call_forwarding"]! != nil {
  306. Preference.setCheckCallForward(value: jsonData["check_call_forwarding"]! as! String == "1")
  307. Preference.setCheckCallForwardAction(value: jsonData["action"]! as! String)
  308. Preference.setCheckCallForwardAlertTitle(value: jsonData["alert_title"]! as! String)
  309. Preference.setCheckCallForwardAlertMessage(value: jsonData["alert_message"]! as! String)
  310. }
  311. if jsonData["multiple_login"]! != nil {
  312. Preference.setCheckMultipleLogin(value: jsonData["multiple_login"]! as! String == "1")
  313. Preference.setCheckMultipleLoginAction(value: jsonData["action"]! as! String)
  314. Preference.setCheckMultipleLoginAlertTitle(value: jsonData["alert_title"]! as! String)
  315. Preference.setCheckMultipleLoginAlertMessage(value: jsonData["alert_message"]! as! String)
  316. }
  317. if jsonData["check_sim_swap"]! != nil {
  318. Preference.setCheckSimSwap(value: jsonData["check_sim_swap"]! as! String == "1")
  319. Preference.setCheckSimSwapAction(value: jsonData["action"]! as! String)
  320. Preference.setCheckSimSwapAlertTitle(value: jsonData["alert_title"]! as! String)
  321. Preference.setCheckSimSwapAlertMessage(value: jsonData["alert_message"]! as! String)
  322. }
  323. if jsonData["check_geovelocity"]! != nil {
  324. Preference.setCheckGeoVelocity(value: jsonData["check_geovelocity"]! as! String == "1")
  325. Preference.setCheckGeoVelocityAction(value: jsonData["action"]! as! String)
  326. Preference.setCheckGeoVelocityAlertTitle(value: jsonData["alert_title"]! as! String)
  327. Preference.setCheckGeoVelocityAlertMessage(value: jsonData["alert_message"]! as! String)
  328. }
  329. if jsonData["behavioral_analysis"]! != nil {
  330. Preference.setCheckBehaviourAnalysis(value: jsonData["behavioral_analysis"]! as! String == "1")
  331. Preference.setCheckBehaviourAnalysisAction(value: jsonData["action"]! as! String)
  332. Preference.setCheckBehaviourAnalysisAlertTitle(value: jsonData["alert_title"]! as! String)
  333. Preference.setCheckBehaviourAnalysisAlertMessage(value: jsonData["alert_message"]! as! String)
  334. }
  335. }
  336. if Preference.getPreventKeylogger() || Preference.getPreventScreenCapture() {
  337. NotificationCenter.default.addObserver(self, selector: #selector(preventScreenRecording), name: UIScreen.capturedDidChangeNotification, object: nil)
  338. DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
  339. if let window = UIApplication.shared.windows.first {
  340. makeSecure(window: window)
  341. }
  342. })
  343. } else {
  344. if screen != nil {
  345. screen?.removeFromSuperview()
  346. }
  347. }
  348. subCheck(1)
  349. } catch {
  350. }
  351. }
  352. } else {
  353. subCheck(1)
  354. }
  355. }
  356. private static var screen: UIView!
  357. @objc static func preventScreenRecording() {
  358. let isCaptured = UIScreen.main.isCaptured
  359. if isCaptured {
  360. blurScreen()
  361. }
  362. else {
  363. removeBlurScreen()
  364. }
  365. }
  366. private static func blurScreen(style: UIBlurEffect.Style = UIBlurEffect.Style.regular) {
  367. screen = UIScreen.main.snapshotView(afterScreenUpdates: false)
  368. let blurEffect = UIBlurEffect(style: style)
  369. let blurBackground = UIVisualEffectView(effect: blurEffect)
  370. screen.addSubview(blurBackground)
  371. blurBackground.frame = (screen.frame)
  372. if let window = UIApplication.shared.windows.first {
  373. window.addSubview(screen)
  374. } else {
  375. }
  376. }
  377. private static func removeBlurScreen() {
  378. screen?.removeFromSuperview()
  379. }
  380. private static func makeSecure(window: UIWindow) {
  381. let field = UITextField()
  382. let view = UIView(frame: CGRect(x: 0, y: 0, width: field.frame.self.width, height: field.frame.self.height))
  383. let image = UIImageView(image: UIImage.imageWithColorSS(color: .black, size: CGSize(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)))
  384. image.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
  385. field.isSecureTextEntry = true
  386. window.addSubview(field)
  387. view.addSubview(image)
  388. window.layer.superlayer?.addSublayer(field.layer)
  389. field.layer.sublayers?.last!.addSublayer(window.layer)
  390. field.leftView = view
  391. field.leftViewMode = .always
  392. }
  393. /*
  394. * 1: Login from new device / multiple login detected
  395. * 2: Call redirection
  396. * 3: Sim change/swap
  397. * 4: Rooted device
  398. * 5: Emulator detected
  399. * 6: Developer mode/debugger (USB/WiFi) detected
  400. * 7: Screen recording/sharing/capture; keylogger
  401. * 8: Malware & suspicious apps
  402. * 9: App cloning
  403. * 10: Remote wipe
  404. * 11: Secure Folder
  405. * 12: Outdated OS
  406. * 13: Application Backup Detected
  407. * 14: Checksum / Tempering
  408. * 15: Screen Overlay
  409. * 16: Sideload app
  410. * 17: Behavioral Anomaly Detected
  411. * 18: Magisk Detected
  412. * 19: Rooted device by RootBeer
  413. * 20: Google Play Integrity
  414. * 21: Geovelocity
  415. * 22: Hook/Anti Frida Detected
  416. */
  417. static func subCheck(_ typeSecurity : Int) {
  418. if typeSecurity == 1 {
  419. if checkEmulator() {
  420. // print("ERROR 1")
  421. sendShieldErrorLog(code: 5)
  422. return
  423. }
  424. subCheck(2)
  425. } else if typeSecurity == 2 {
  426. if checkRootedDevice() {
  427. // print("ERROR 2")
  428. sendShieldErrorLog(code: 4)
  429. return
  430. }
  431. subCheck(3)
  432. } else if typeSecurity == 3 {
  433. if checkOutdatedOS() {
  434. // print("ERROR 3")
  435. sendShieldErrorLog(code: 12)
  436. return
  437. }
  438. subCheck(4)
  439. } else if typeSecurity == 4 {
  440. if checkTempering() {
  441. // print("ERROR 4")
  442. sendShieldErrorLog(code: 14)
  443. return
  444. }
  445. subCheck(5)
  446. } else if typeSecurity == 5 {
  447. if checkHooked() {
  448. // print("ERROR 5")
  449. sendShieldErrorLog(code: 22)
  450. return
  451. }
  452. subCheck(6)
  453. } else if typeSecurity == 6 {
  454. if checkDebugging() {
  455. // print("ERROR 6")
  456. sendShieldErrorLog(code: 6)
  457. return
  458. }
  459. subCheck(7)
  460. } else if typeSecurity == 7 {
  461. NotificationCenter.default.addObserver(self, selector: #selector(screenDidConnect), name: UIScreen.didConnectNotification, object: nil)
  462. NotificationCenter.default.addObserver(self, selector: #selector(screenDidDisconnect), name: UIScreen.didDisconnectNotification, object: nil)
  463. if checkScreenCasting() {
  464. // print("ERROR 7")
  465. sendShieldErrorLog(code: 7)
  466. return
  467. }
  468. subCheck(8)
  469. } else if typeSecurity == 8 {
  470. if checkScreenOverlay() {
  471. // print("ERROR 8")
  472. sendShieldErrorLog(code: 15)
  473. return
  474. }
  475. subCheck(9)
  476. } else if typeSecurity == 9 {
  477. if checkCallForward() {
  478. // print("ERROR 9")
  479. sendShieldErrorLog(code: 2)
  480. return
  481. }
  482. subCheck(10)
  483. } else if typeSecurity == 10 {
  484. if checkMultipleLogin() {
  485. // print("ERROR 10")
  486. sendShieldErrorLog(code: 1)
  487. return
  488. }
  489. subCheck(11)
  490. } else if typeSecurity == 11 {
  491. if checkSimSwap() {
  492. // print("ERROR 11")
  493. sendShieldErrorLog(code: 3)
  494. return
  495. }
  496. subCheck(12)
  497. } else if typeSecurity == 12 {
  498. if checkGeovelocity() {
  499. // print("ERROR 12")
  500. sendShieldErrorLog(code: 21)
  501. return
  502. }
  503. subCheck(13)
  504. } else if typeSecurity == 13 {
  505. if checkBehaviourAnalysis() {
  506. // print("ERROR 13")
  507. sendShieldErrorLog(code: 17)
  508. return
  509. }
  510. }
  511. }
  512. static func checkEmulator() -> Bool {
  513. if Preference.getCheckEmulator() && isEmulator() {
  514. DispatchQueue.main.async(execute: {
  515. let alert = SSLibAlertController(title: Preference.getCheckEmulatorAlertTitle(), message: Preference.getCheckEmulatorAlertMessage(), preferredStyle: .alert)
  516. if Preference.getCheckEmulatorAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  517. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: {_ in
  518. subCheck(2)
  519. }))
  520. if UIApplication.shared.visibleViewController?.navigationController != nil {
  521. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  522. } else {
  523. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  524. }
  525. } else {
  526. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  527. exit(-101)
  528. }))
  529. if UIApplication.shared.visibleViewController?.navigationController != nil {
  530. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  531. } else {
  532. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  533. }
  534. }
  535. })
  536. return true
  537. }
  538. return false
  539. }
  540. static func checkRootedDevice() -> Bool {
  541. if Preference.getCheckRooted() && isRooted() {
  542. DispatchQueue.main.async(execute: {
  543. let alert = SSLibAlertController(title: Preference.getCheckRootedAlertTitle(), message: Preference.getCheckRootedAlertMessage(), preferredStyle: .alert)
  544. if Preference.getCheckRootedAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  545. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: {_ in
  546. subCheck(3)
  547. }))
  548. if UIApplication.shared.visibleViewController?.navigationController != nil {
  549. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  550. } else {
  551. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  552. }
  553. } else {
  554. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  555. exit(-141)
  556. }))
  557. if UIApplication.shared.visibleViewController?.navigationController != nil {
  558. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  559. } else {
  560. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  561. }
  562. }
  563. })
  564. return true
  565. }
  566. return false
  567. }
  568. static func checkOutdatedOS() -> Bool {
  569. if Preference.getCheckOutdatedOs() {
  570. let requiredVersion = Preference.getMinimumOsVersion()
  571. let systemVersion = UIDevice.current.systemVersion
  572. let versionComponents = systemVersion.split(separator: ".").prefix(2)
  573. let versionString = versionComponents.joined(separator: ".")
  574. if let currentVersion = Double(versionString),
  575. let requiredVersionDouble = Double(requiredVersion) {
  576. if currentVersion < requiredVersionDouble {
  577. DispatchQueue.main.async(execute: {
  578. let alert = SSLibAlertController(title: Preference.getCheckRootedAlertTitle(), message: Preference.getCheckRootedAlertMessage(), preferredStyle: .alert)
  579. if Preference.getCheckOutdatedOsAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  580. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: {_ in
  581. subCheck(4)
  582. }))
  583. if UIApplication.shared.visibleViewController?.navigationController != nil {
  584. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  585. } else {
  586. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  587. }
  588. } else {
  589. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  590. exit(-103)
  591. }))
  592. if UIApplication.shared.visibleViewController?.navigationController != nil {
  593. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  594. } else {
  595. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  596. }
  597. }
  598. })
  599. return true
  600. }
  601. } else {
  602. }
  603. }
  604. return false
  605. }
  606. static func checkTempering() -> Bool {
  607. if Preference.getCheckTempering() && isTempering() {
  608. DispatchQueue.main.async(execute: {
  609. let alert = SSLibAlertController(title: Preference.getCheckTemperingAlertTitle(), message: Preference.getCheckTemperingAlertMessage(), preferredStyle: .alert)
  610. if Preference.getCheckTemperingAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  611. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: {_ in
  612. subCheck(5)
  613. }))
  614. if UIApplication.shared.visibleViewController?.navigationController != nil {
  615. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  616. } else {
  617. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  618. }
  619. } else {
  620. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  621. exit(-141)
  622. }))
  623. if UIApplication.shared.visibleViewController?.navigationController != nil {
  624. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  625. } else {
  626. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  627. }
  628. }
  629. })
  630. return true
  631. }
  632. return false
  633. }
  634. static func checkHooked() -> Bool {
  635. if Preference.getCheckHooked() && isHooked() {
  636. DispatchQueue.main.async(execute: {
  637. let alert = SSLibAlertController(title: Preference.getCheckHookedAlertTitle(), message: Preference.getCheckHookedAlertMessage(), preferredStyle: .alert)
  638. if Preference.getCheckHookedAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  639. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: {_ in
  640. subCheck(6)
  641. }))
  642. if UIApplication.shared.visibleViewController?.navigationController != nil {
  643. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  644. } else {
  645. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  646. }
  647. } else {
  648. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  649. exit(-141)
  650. }))
  651. if UIApplication.shared.visibleViewController?.navigationController != nil {
  652. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  653. } else {
  654. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  655. }
  656. }
  657. })
  658. return true
  659. }
  660. return false
  661. }
  662. static func checkDebugging() -> Bool {
  663. if Preference.getCheckDebugging() && isDebugging() {
  664. DispatchQueue.main.async(execute: {
  665. let alert = SSLibAlertController(title: Preference.getCheckDebuggingAlertTitle(), message: Preference.getCheckDebuggingAlertMessage(), preferredStyle: .alert)
  666. if Preference.getCheckDebuggingAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  667. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: {_ in
  668. subCheck(7)
  669. }))
  670. if UIApplication.shared.visibleViewController?.navigationController != nil {
  671. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  672. } else {
  673. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  674. }
  675. } else {
  676. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  677. exit(-141)
  678. }))
  679. if UIApplication.shared.visibleViewController?.navigationController != nil {
  680. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  681. } else {
  682. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  683. }
  684. }
  685. })
  686. return true
  687. }
  688. return false
  689. }
  690. static func checkScreenCasting() -> Bool {
  691. if Preference.getCheckScreenCasting() && isScreenCasting() {
  692. DispatchQueue.main.async(execute: {
  693. let alert = SSLibAlertController(title: Preference.getCheckScreenCastingAlertTitle(), message: Preference.getCheckScreenCastingAlertMessage(), preferredStyle: .alert)
  694. if Preference.getCheckScreenCastingAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  695. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: {_ in
  696. subCheck(8)
  697. }))
  698. if UIApplication.shared.visibleViewController?.navigationController != nil {
  699. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  700. } else {
  701. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  702. }
  703. } else {
  704. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  705. exit(-141)
  706. }))
  707. if UIApplication.shared.visibleViewController?.navigationController != nil {
  708. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  709. } else {
  710. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  711. }
  712. }
  713. })
  714. return true
  715. }
  716. return false
  717. }
  718. static func checkScreenOverlay() -> Bool {
  719. if Preference.getCheckScreenOverlay() && isScreenOverlay() {
  720. DispatchQueue.main.async(execute: {
  721. let alert = SSLibAlertController(title: Preference.getCheckScreenOverlayAlertTitle(), message: Preference.getCheckScreenOverlayAlertMessage(), preferredStyle: .alert)
  722. if Preference.getCheckScreenOverlayAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  723. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: {_ in
  724. subCheck(9)
  725. }))
  726. if UIApplication.shared.visibleViewController?.navigationController != nil {
  727. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  728. } else {
  729. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  730. }
  731. } else {
  732. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  733. exit(-141)
  734. }))
  735. if UIApplication.shared.visibleViewController?.navigationController != nil {
  736. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  737. } else {
  738. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  739. }
  740. }
  741. })
  742. return true
  743. }
  744. return false
  745. }
  746. static func checkCallForward() -> Bool {
  747. if Preference.getCheckCallForward() && isCallForwarded() {
  748. DispatchQueue.main.async(execute: {
  749. let alert = SSLibAlertController(title: Preference.getCheckCallForwardAlertTitle(), message: Preference.getCheckCallForwardAlertMessage(), preferredStyle: .alert)
  750. if Preference.getCheckCallForwardAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  751. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: {_ in
  752. subCheck(10)
  753. }))
  754. if UIApplication.shared.visibleViewController?.navigationController != nil {
  755. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  756. } else {
  757. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  758. }
  759. } else {
  760. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  761. exit(-141)
  762. }))
  763. if UIApplication.shared.visibleViewController?.navigationController != nil {
  764. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  765. } else {
  766. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  767. }
  768. }
  769. })
  770. return true
  771. }
  772. return false
  773. }
  774. static func checkMultipleLogin() -> Bool {
  775. if Preference.getCheckMultipleLogin() && isMultipleLogin() {
  776. DispatchQueue.main.async(execute: {
  777. let alert = SSLibAlertController(title: Preference.getCheckMultipleLoginAlertTitle(), message: Preference.getCheckMultipleLoginAlertMessage(), preferredStyle: .alert)
  778. if Preference.getCheckMultipleLoginAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  779. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: {_ in
  780. subCheck(11)
  781. }))
  782. if UIApplication.shared.visibleViewController?.navigationController != nil {
  783. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  784. } else {
  785. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  786. }
  787. } else {
  788. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  789. exit(-141)
  790. }))
  791. if UIApplication.shared.visibleViewController?.navigationController != nil {
  792. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  793. } else {
  794. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  795. }
  796. }
  797. })
  798. return true
  799. }
  800. return false
  801. }
  802. static func checkSimSwap() -> Bool {
  803. if Preference.getCheckSimSwap() && isSimSwap() {
  804. DispatchQueue.main.async(execute: {
  805. let alert = SSLibAlertController(title: Preference.getCheckSimSwapAlertTitle(), message: Preference.getCheckSimSwapAlertMessage(), preferredStyle: .alert)
  806. if Preference.getCheckSimSwapAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  807. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: {_ in
  808. subCheck(12)
  809. }))
  810. if UIApplication.shared.visibleViewController?.navigationController != nil {
  811. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  812. } else {
  813. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  814. }
  815. } else {
  816. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  817. exit(-141)
  818. }))
  819. if UIApplication.shared.visibleViewController?.navigationController != nil {
  820. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  821. } else {
  822. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  823. }
  824. }
  825. })
  826. return true
  827. }
  828. return false
  829. }
  830. static func checkGeovelocity() -> Bool {
  831. if Preference.getCheckGeoVelocity() && isGeovelocityDetected() {
  832. DispatchQueue.main.async(execute: {
  833. let alert = SSLibAlertController(title: Preference.getCheckGeoVelocityAlertTitle(), message: Preference.getCheckGeoVelocityAlertMessage(), preferredStyle: .alert)
  834. if Preference.getCheckGeoVelocityAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  835. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: {_ in
  836. subCheck(13)
  837. }))
  838. if UIApplication.shared.visibleViewController?.navigationController != nil {
  839. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  840. } else {
  841. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  842. }
  843. } else {
  844. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  845. exit(-141)
  846. }))
  847. if UIApplication.shared.visibleViewController?.navigationController != nil {
  848. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  849. } else {
  850. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  851. }
  852. }
  853. })
  854. return true
  855. }
  856. return false
  857. }
  858. static func checkBehaviourAnalysis() -> Bool {
  859. if Preference.getCheckBehaviourAnalysis() {
  860. isSuspiciousBehavior()
  861. return true
  862. }
  863. return false
  864. }
  865. private static func isEmulator() -> Bool {
  866. let deviceName = UIDevice.current.name
  867. if deviceName.contains("Simulator") {
  868. return true
  869. }
  870. let deviceModel = UIDevice.current.model
  871. if deviceModel.hasPrefix("Simulator") {
  872. return true
  873. }
  874. let systemName = UIDevice.current.systemName
  875. if systemName == "Simulator" {
  876. return true
  877. }
  878. #if targetEnvironment(simulator)
  879. return true
  880. #else
  881. #endif
  882. return false
  883. }
  884. private static func isRooted() -> Bool {
  885. let fileManager = FileManager.default
  886. if fileManager.fileExists(atPath: "/Applications/Cydia.app") ||
  887. fileManager.fileExists(atPath: "/Library/MobileSubstrate/MobileSubstrate.dylib") ||
  888. fileManager.fileExists(atPath: "/bin/bash") ||
  889. fileManager.fileExists(atPath: "/usr/sbin/sshd") ||
  890. fileManager.fileExists(atPath: "/etc/apt") ||
  891. fileManager.fileExists(atPath: "/private/var/lib/apt/") ||
  892. fileManager.fileExists(atPath: "/Applications/FakeApp.app") {
  893. return true
  894. }
  895. let testPath = "/private/" + UUID().uuidString
  896. do {
  897. try "test".write(toFile: testPath, atomically: true, encoding: .utf8)
  898. try FileManager.default.removeItem(atPath: testPath)
  899. return true
  900. } catch {
  901. // Could not write outside sandbox
  902. }
  903. return false
  904. }
  905. private static func isTempering() -> Bool {
  906. return false
  907. }
  908. private static func isDebugging() -> Bool {
  909. var name: [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]
  910. var info = kinfo_proc()
  911. var size = MemoryLayout<kinfo_proc>.size
  912. let result = sysctl(&name, UInt32(name.count), &info, &size, nil, 0)
  913. if result == 0 {
  914. return (info.kp_proc.p_flag & P_TRACED) != 0
  915. } else {
  916. return false
  917. }
  918. }
  919. private static func isHooked() -> Bool {
  920. let suspiciousLibraries = [
  921. "FridaGadget",
  922. "libsubstrate.dylib",
  923. "libcycript.dylib",
  924. "cyinject.dylib",
  925. "MobileSubstrate.dylib",
  926. "SSLKillSwitch.dylib",
  927. "CydiaSubstrate",
  928. "TweakInject",
  929. "0Shadow",
  930. "shadow.dylib"
  931. ]
  932. for i in 0..<_dyld_image_count() {
  933. if let imageName = _dyld_get_image_name(i) {
  934. let name = String(cString: imageName)
  935. for library in suspiciousLibraries {
  936. if name.lowercased().contains(library.lowercased()) {
  937. return true
  938. }
  939. }
  940. }
  941. }
  942. return false
  943. }
  944. private static func isScreenCasting() -> Bool {
  945. return checkForExternalScreen()
  946. }
  947. @objc static func screenDidConnect(notification: Notification) {
  948. _ = checkScreenCasting()
  949. }
  950. // Called when a screen is disconnected
  951. @objc static func screenDidDisconnect(notification: Notification) {
  952. _ = checkScreenCasting()
  953. }
  954. private static func checkForExternalScreen() -> Bool {
  955. let screens = UIScreen.screens
  956. if screens.count > 1 {
  957. return true
  958. } else {
  959. return false
  960. }
  961. }
  962. private static func isScreenOverlay() -> Bool {
  963. return false
  964. }
  965. private static func isCallForwarded() -> Bool {
  966. return false
  967. }
  968. private static func isMultipleLogin() -> Bool {
  969. return false
  970. }
  971. private static func isSimSwap() -> Bool {
  972. guard let savedSimInfo: [String: [String: String]]? = SecureUserDefaultsSS.shared.value(forKey: "SavedSIMInfo") else {
  973. let simInfo = getSIMInfo()
  974. SecureUserDefaultsSS.shared.set(simInfo, forKey: "SavedSIMInfo")
  975. return false
  976. }
  977. let currentSimInfo = getSIMInfo()
  978. return savedSimInfo != currentSimInfo
  979. }
  980. private static func getSIMInfo() -> [String: [String: String]] {
  981. let networkInfo = CTTelephonyNetworkInfo()
  982. var simData: [String: [String: String]] = [:]
  983. if let carriers = networkInfo.serviceSubscriberCellularProviders {
  984. for (key, carrier) in carriers {
  985. let carrierName = carrier.carrierName ?? "Unknown"
  986. let mobileCountryCode = carrier.mobileCountryCode ?? "Unknown"
  987. let mobileNetworkCode = carrier.mobileNetworkCode ?? "Unknown"
  988. let isoCountryCode = carrier.isoCountryCode ?? "Unknown"
  989. simData[key] = [
  990. "carrierName": carrierName,
  991. "mobileCountryCode": mobileCountryCode,
  992. "mobileNetworkCode": mobileNetworkCode,
  993. "isoCountryCode": isoCountryCode
  994. ]
  995. }
  996. }
  997. return simData
  998. }
  999. private static func isGeovelocityDetected() -> Bool {
  1000. return false
  1001. }
  1002. private static func isSuspiciousBehavior() {
  1003. let data = collectDeviceAttributes()
  1004. // print("DATA COLLECT: \(data)")
  1005. DispatchQueue.global().async{
  1006. SecurityShield.postDataWithCookiesAndUserAgent(from: URL(string: Preference.getDomainOpr() + "data_capture")!, parameter: data) { data, response, error in
  1007. let response = response as? HTTPURLResponse
  1008. if response?.statusCode != 200 || error != nil {
  1009. return
  1010. }
  1011. if let data = data, let responseString = String(data: data, encoding: .utf8) {
  1012. if !responseString.isEmpty {
  1013. // print("RESPON ANOMALI : \(responseString)")
  1014. if responseString == "ANOMALY_DETECTED" {
  1015. DispatchQueue.main.async(execute: {
  1016. let alert = SSLibAlertController(title: Preference.getCheckBehaviourAnalysisAlertTitle(), message: Preference.getCheckBehaviourAnalysisAlertMessage(), preferredStyle: .alert)
  1017. if Preference.getCheckBehaviourAnalysisAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  1018. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: {_ in
  1019. subCheck(14)
  1020. }))
  1021. if UIApplication.shared.visibleViewController?.navigationController != nil {
  1022. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  1023. } else {
  1024. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  1025. }
  1026. } else {
  1027. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  1028. exit(-141)
  1029. }))
  1030. if UIApplication.shared.visibleViewController?.navigationController != nil {
  1031. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  1032. } else {
  1033. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  1034. }
  1035. }
  1036. })
  1037. }
  1038. }
  1039. }
  1040. }
  1041. }
  1042. }
  1043. private static func sendShieldErrorLog(code: Int) {
  1044. var data = collectDeviceAttributes()
  1045. data["security_shield"] = "\(code)"
  1046. if let jsonData = try? JSONSerialization.data(withJSONObject: data, options: .prettyPrinted),
  1047. let jsonString = String(data: jsonData, encoding: .utf8) {
  1048. let me: String! = SecureUserDefaultsSS.shared.value(forKey: "me") ?? ""
  1049. let tmessage = TMessageSS()
  1050. tmessage.mCode = "SSG"
  1051. tmessage.mStatus = CoreMessage_TMessageUtil.getTID()
  1052. tmessage.mPIN = me
  1053. tmessage.mBodies["A112"] = jsonString
  1054. _ = Service.write(message: tmessage)
  1055. }
  1056. }
  1057. private static let vers = "5.0.52"
  1058. private var currentLocation: CLLocation?
  1059. private static func collectDeviceAttributes() -> [String: Any] {
  1060. var params: [String: Any] = [:]
  1061. // User and session
  1062. let me: String? = SecureUserDefaultsSS.shared.value(forKey: "me")
  1063. let sesId: String? = Preference.getConnectionID()
  1064. params["f_pin"] = me
  1065. params["session_id"] = sesId
  1066. // App info (replace with your preferences retrieval)
  1067. params["api"] = Preference.getAccount()
  1068. params["app_id"] = Preference.getAppId()
  1069. params["lib_version"] = vers
  1070. params["app_version"] = vers
  1071. // Network Info
  1072. let (netType, netTypeName) = getNetworkType()
  1073. let (operatorCode, operatorName) = getCarrierInfo()
  1074. let (wifiStatus, wifiIp, wifiSsid, wifiBssid) = getWifiInfo()
  1075. params["network_type"] = netType
  1076. params["network_type_name"] = netTypeName
  1077. params["network_operator"] = operatorCode
  1078. params["network_operator_name"] = operatorName
  1079. params["wifi_ssid"] = wifiSsid
  1080. params["wifi_bssid"] = wifiBssid
  1081. params["wifi_adapter"] = wifiStatus
  1082. params["wifi_ip"] = wifiIp
  1083. // IP Address
  1084. params["ip_addressv4"] = getIPAddress(useIPv4: true)
  1085. params["ip_address"] = getIPAddress(useIPv4: false)
  1086. // GPS / location
  1087. let semaphore = DispatchSemaphore(value: 0)
  1088. DispatchQueue.main.async {
  1089. LocationFetcher.shared.getCurrentLocation { coordinate in
  1090. var long = "0"
  1091. var lat = "0"
  1092. if let coord = coordinate {
  1093. long = "\(coord.longitude)"
  1094. lat = "\(coord.latitude)"
  1095. }
  1096. // print("Latitude: \(lat), Longitude: \(long)")
  1097. params["latitude"] = lat
  1098. params["longitude"] = long
  1099. semaphore.signal()
  1100. }
  1101. }
  1102. _ = semaphore.wait(timeout: .now() + 10.0)
  1103. // iOS doesn't have an Android ID; use identifierForVendor
  1104. params["ios_identifier"] = UIDevice.current.identifierForVendor?.uuidString ?? ""
  1105. // Device attributes
  1106. let device = UIDevice.current
  1107. params["device_NAME"] = device.name
  1108. params["device_MODEL"] = device.model
  1109. params["device_SYSTEM_NAME"] = device.systemName
  1110. params["device_SYSTEM_VERSION"] = device.systemVersion
  1111. params["device_IDENTIFIER_FOR_VENDOR"] = device.identifierForVendor?.uuidString ?? ""
  1112. return getSimData(params: params)
  1113. }
  1114. private static func getSimData(params: [String: Any] = [:]) -> [String: Any] {
  1115. var params = params
  1116. var simArray: [[String: Any]] = []
  1117. let networkInfo = CTTelephonyNetworkInfo()
  1118. if #available(iOS 12.0, *) {
  1119. if let carriers = networkInfo.serviceSubscriberCellularProviders {
  1120. for (key, carrier) in carriers {
  1121. var simInfo: [String: Any] = [:]
  1122. simInfo["carrier_name"] = carrier.carrierName ?? ""
  1123. simInfo["mcc"] = carrier.mobileCountryCode ?? ""
  1124. simInfo["mnc"] = carrier.mobileNetworkCode ?? ""
  1125. simInfo["sim_slot"] = key // This is not a true "slot", but the key used internally
  1126. simArray.append(simInfo)
  1127. }
  1128. }
  1129. } else {
  1130. if let carrier = networkInfo.subscriberCellularProvider {
  1131. var simInfo: [String: Any] = [:]
  1132. simInfo["carrier_name"] = carrier.carrierName ?? ""
  1133. simInfo["mcc"] = carrier.mobileCountryCode ?? ""
  1134. simInfo["mnc"] = carrier.mobileNetworkCode ?? ""
  1135. simInfo["sim_slot"] = "default"
  1136. simArray.append(simInfo)
  1137. }
  1138. }
  1139. params["sim_data"] = simArray
  1140. return params
  1141. }
  1142. private static func getNetworkType() -> (type: String, name: String) {
  1143. let monitor = NWPathMonitor()
  1144. var networkType = ""
  1145. var networkTypeName = ""
  1146. let semaphore = DispatchSemaphore(value: 0)
  1147. monitor.pathUpdateHandler = { path in
  1148. if path.usesInterfaceType(.wifi) {
  1149. networkType = "1" // Corresponds to TYPE_WIFI in Android
  1150. networkTypeName = "WIFI"
  1151. } else if path.usesInterfaceType(.cellular) {
  1152. networkType = "0" // Corresponds to TYPE_MOBILE
  1153. networkTypeName = "MOBILE"
  1154. } else {
  1155. networkType = "-1"
  1156. networkTypeName = "UNKNOWN"
  1157. }
  1158. semaphore.signal()
  1159. monitor.cancel()
  1160. }
  1161. let queue = DispatchQueue(label: "NetworkMonitor")
  1162. monitor.start(queue: queue)
  1163. semaphore.wait()
  1164. return (networkType, networkTypeName)
  1165. }
  1166. private static func getCarrierInfo() -> (operatorCode: String, operatorName: String) {
  1167. let networkInfo = CTTelephonyNetworkInfo()
  1168. var carrierCode = ""
  1169. var carrierName = ""
  1170. if #available(iOS 12.0, *) {
  1171. if let carriers = networkInfo.serviceSubscriberCellularProviders {
  1172. for (_, carrier) in carriers {
  1173. carrierCode = (carrier.mobileCountryCode ?? "") + (carrier.mobileNetworkCode ?? "")
  1174. carrierName = carrier.carrierName ?? ""
  1175. break // Just use the first one
  1176. }
  1177. }
  1178. } else {
  1179. if let carrier = networkInfo.subscriberCellularProvider {
  1180. carrierCode = (carrier.mobileCountryCode ?? "") + (carrier.mobileNetworkCode ?? "")
  1181. carrierName = carrier.carrierName ?? ""
  1182. }
  1183. }
  1184. return (carrierCode, carrierName)
  1185. }
  1186. private static func getWifiInfo() -> (adapter: String, ip: String, ssid: String, bssid: String) {
  1187. var adapterStatus = "Off"
  1188. var ipAddress = ""
  1189. var ssid = ""
  1190. var bssid = ""
  1191. // Get IP Address
  1192. if let interfaces = CNCopySupportedInterfaces() as NSArray? {
  1193. for interfaceName in interfaces {
  1194. if let unsafeInterfaceData = CNCopyCurrentNetworkInfo(interfaceName as! CFString) as NSDictionary? {
  1195. ssid = unsafeInterfaceData["SSID"] as? String ?? ""
  1196. bssid = unsafeInterfaceData["BSSID"] as? String ?? ""
  1197. adapterStatus = "Connected"
  1198. break
  1199. }
  1200. }
  1201. }
  1202. if ssid.isEmpty {
  1203. adapterStatus = "Not Connected"
  1204. }
  1205. ipAddress = getWiFiIPAddress() ?? ""
  1206. return (adapterStatus, ipAddress, ssid, bssid)
  1207. }
  1208. private static func getWiFiIPAddress() -> String? {
  1209. var address: String?
  1210. var ifaddr: UnsafeMutablePointer<ifaddrs>?
  1211. guard getifaddrs(&ifaddr) == 0, let firstAddr = ifaddr else { return nil }
  1212. for ptr in sequence(first: firstAddr, next: { $0.pointee.ifa_next }) {
  1213. let interface = ptr.pointee
  1214. let addrFamily = interface.ifa_addr.pointee.sa_family
  1215. if addrFamily == UInt8(AF_INET) || addrFamily == UInt8(AF_INET6) {
  1216. let name = String(cString: interface.ifa_name)
  1217. if name == "en0" { // en0 is Wi-Fi
  1218. var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST))
  1219. getnameinfo(interface.ifa_addr, socklen_t(interface.ifa_addr.pointee.sa_len),
  1220. &hostname, socklen_t(hostname.count),
  1221. nil, socklen_t(0), NI_NUMERICHOST)
  1222. address = String(cString: hostname)
  1223. break
  1224. }
  1225. }
  1226. }
  1227. freeifaddrs(ifaddr)
  1228. return address
  1229. }
  1230. private static func getIPAddress(useIPv4: Bool) -> String {
  1231. var address: String = ""
  1232. var ifaddr: UnsafeMutablePointer<ifaddrs>? = nil
  1233. if getifaddrs(&ifaddr) == 0, let firstAddr = ifaddr {
  1234. for ptr in sequence(first: firstAddr, next: { $0.pointee.ifa_next }) {
  1235. let interface = ptr.pointee
  1236. let addrFamily = interface.ifa_addr.pointee.sa_family
  1237. if addrFamily == UInt8(AF_INET) || addrFamily == UInt8(AF_INET6) {
  1238. let name = String(cString: interface.ifa_name)
  1239. if name == "en0" || name == "pdp_ip0" {
  1240. var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST))
  1241. let result = getnameinfo(
  1242. interface.ifa_addr,
  1243. socklen_t(interface.ifa_addr.pointee.sa_len),
  1244. &hostname,
  1245. socklen_t(hostname.count),
  1246. nil,
  1247. socklen_t(0),
  1248. NI_NUMERICHOST
  1249. )
  1250. if result == 0 {
  1251. let ip = String(cString: hostname)
  1252. let isIPv4 = ip.contains(":") == false
  1253. if useIPv4 && isIPv4 {
  1254. address = ip
  1255. break
  1256. } else if !useIPv4 && !isIPv4 {
  1257. // Remove IPv6 scope if present
  1258. let cleanIPv6 = ip.split(separator: "%").first.map(String.init) ?? ip
  1259. address = cleanIPv6.uppercased()
  1260. break
  1261. }
  1262. }
  1263. }
  1264. }
  1265. }
  1266. freeifaddrs(ifaddr)
  1267. }
  1268. return address
  1269. }
  1270. }
  1271. private class LocationFetcher: NSObject, CLLocationManagerDelegate {
  1272. static var shared = LocationFetcher()
  1273. private var manager: CLLocationManager?
  1274. private var completion: ((CLLocationCoordinate2D?) -> Void)?
  1275. func getCurrentLocation(completion: @escaping (CLLocationCoordinate2D?) -> Void) {
  1276. self.completion = completion
  1277. self.manager = CLLocationManager()
  1278. self.manager?.delegate = self
  1279. self.manager?.desiredAccuracy = kCLLocationAccuracyBest
  1280. self.manager?.requestWhenInUseAuthorization()
  1281. if CLLocationManager.locationServicesEnabled() {
  1282. self.manager?.requestLocation()
  1283. } else {
  1284. completion(nil)
  1285. }
  1286. }
  1287. // MARK: - CLLocationManagerDelegate
  1288. func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
  1289. completion?(locations.last?.coordinate)
  1290. cleanup()
  1291. }
  1292. func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
  1293. print("Error: \(error.localizedDescription)")
  1294. completion?(nil)
  1295. cleanup()
  1296. }
  1297. private func cleanup() {
  1298. manager?.stopUpdatingLocation()
  1299. manager?.delegate = nil
  1300. manager = nil
  1301. completion = nil
  1302. }
  1303. }
  1304. private class Service {
  1305. static func writeSync(message: TMessageSS, timeout: Int = 15 * 1000) -> TMessageSS? {
  1306. if !API.bInetConnAvailable() || API.nGetCLXConnState() == 0 {
  1307. return nil
  1308. }
  1309. do {
  1310. if let data = try API.sGetResponse(sRequest: message.pack(), lTimeout: timeout, bKeepTOResp: true) {
  1311. let response = TMessageSS(data: data)
  1312. return response
  1313. }
  1314. } catch {
  1315. print(error)
  1316. }
  1317. return nil
  1318. }
  1319. static func write(message: TMessageSS, timeout: Int = 15 * 1000) -> String? {
  1320. do {
  1321. if !API.bInetConnAvailable() || API.nGetCLXConnState() == 0 {
  1322. return nil
  1323. }
  1324. //print(">> SENDING MESSAGE >> ", message.toLogString())
  1325. if message.getMedia().count == 0 {
  1326. if let data = try API.sSend(sData: message.pack(), nPriority: 1, lTimeout: timeout) {
  1327. //print("<< RESPONSE MESSAGE << ", data)
  1328. return data
  1329. }
  1330. }
  1331. // media
  1332. if let data = try API.sSend(abData: message.toBytes(), nPriority: 2, lTimeout: timeout) {
  1333. //print("<< RESPONSE MESSAGE << ", data)
  1334. return data
  1335. }
  1336. } catch {
  1337. //print(error)
  1338. }
  1339. return nil
  1340. }
  1341. }
  1342. private class Preference {
  1343. static func setConnectionID(value: String) {
  1344. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CONNECTION_ID)
  1345. }
  1346. static func getConnectionID() -> String {
  1347. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CONNECTION_ID) {
  1348. return value
  1349. }
  1350. return ""
  1351. }
  1352. static func getAppId() -> String {
  1353. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_USER_APP_ID) {
  1354. return value
  1355. }
  1356. return ""
  1357. }
  1358. static func setAppId(value: String){
  1359. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_USER_APP_ID)
  1360. }
  1361. static func getAccount() -> String {
  1362. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_USER_ACCOUNT) {
  1363. return value
  1364. }
  1365. return ""
  1366. }
  1367. static func setAccount(value: String){
  1368. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_USER_ACCOUNT)
  1369. }
  1370. static func setDomainOpr(value: String){
  1371. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_DOMAIN_OPR)
  1372. }
  1373. static func getDomainOpr() -> String {
  1374. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_DOMAIN_OPR) {
  1375. return value
  1376. }
  1377. return "https://nexilis.io/"
  1378. }
  1379. static func setIpPortOpr(value: String){
  1380. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_IP_PORT_OPR)
  1381. }
  1382. static func getIpOpr() -> String {
  1383. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_IP_PORT_OPR) {
  1384. return value
  1385. }
  1386. return "34.101.172.194:42823"
  1387. }
  1388. /**
  1389. * Keylogger
  1390. */
  1391. static func setPreventKeylogger(value: Bool){
  1392. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_KEYLOGGER)
  1393. }
  1394. static func getPreventKeylogger() -> Bool {
  1395. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_KEYLOGGER) {
  1396. return value
  1397. }
  1398. return false
  1399. }
  1400. static func setPreventKeyloggerAction(value: String){
  1401. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_KEYLOGGER_ACTION)
  1402. }
  1403. static func getPreventKeyloggerAction() -> String {
  1404. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_KEYLOGGER_ACTION) {
  1405. return value
  1406. }
  1407. return "0"
  1408. }
  1409. static func setKeyloggerAlertTitle(value: String){
  1410. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_KEYLOGGER_ALERT_TITLE)
  1411. }
  1412. static func getKeyloggerAlertTitle() -> String {
  1413. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_KEYLOGGER_ALERT_TITLE) {
  1414. if value.isEmpty {
  1415. return PreferencesKey.ss_screenshare_title
  1416. }
  1417. return value
  1418. }
  1419. return PreferencesKey.ss_screenshare_title
  1420. }
  1421. static func setKeyloggerAlertMessage(value: String){
  1422. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_KEYLOGGER_ALERT_MESSAGE)
  1423. }
  1424. static func getKeyloggerAlertMessage() -> String {
  1425. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_KEYLOGGER_ALERT_MESSAGE) {
  1426. if value.isEmpty {
  1427. return PreferencesKey.ss_screenshare_warning
  1428. }
  1429. return value
  1430. }
  1431. return PreferencesKey.ss_screenshare_warning
  1432. }
  1433. /**
  1434. * Screen Capture
  1435. */
  1436. static func setPreventScreenCapture(value: Bool){
  1437. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_CAPTURE)
  1438. }
  1439. static func getPreventScreenCapture() -> Bool {
  1440. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_CAPTURE) {
  1441. return value
  1442. }
  1443. return false
  1444. }
  1445. static func setPreventScreenCaptureAction(value: String){
  1446. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_CAPTURE_ACTION)
  1447. }
  1448. static func getPreventScreenCaptureAction() -> String {
  1449. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_CAPTURE_ACTION) {
  1450. return value
  1451. }
  1452. return "0"
  1453. }
  1454. static func setCheckScreenCaptureAlertTitle(value: String){
  1455. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_CAPTURE_ALERT_TITLE)
  1456. }
  1457. static func getCheckScreenCaptureAlertTitle() -> String {
  1458. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_CAPTURE_ALERT_TITLE) {
  1459. if value.isEmpty {
  1460. return PreferencesKey.ss_screenshare_title
  1461. }
  1462. return value
  1463. }
  1464. return PreferencesKey.ss_screenshare_title
  1465. }
  1466. static func setScreenCaptureAlertMessage(value: String){
  1467. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_CAPTURE_ALERT_MESSAGE)
  1468. }
  1469. static func getScreenCaptureAlertMessage() -> String {
  1470. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_CAPTURE_ALERT_MESSAGE) {
  1471. if value.isEmpty {
  1472. return PreferencesKey.ss_screenshare_warning
  1473. }
  1474. return value
  1475. }
  1476. return PreferencesKey.ss_screenshare_warning
  1477. }
  1478. /**
  1479. * Emulator
  1480. */
  1481. static func setCheckEmulator(value: Bool){
  1482. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_EMULATOR)
  1483. }
  1484. static func getCheckEmulator() -> Bool {
  1485. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_EMULATOR) {
  1486. return value
  1487. }
  1488. return false
  1489. }
  1490. static func setCheckEmulatorAction(value: String){
  1491. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_EMULATOR_ACTION)
  1492. }
  1493. static func getCheckEmulatorAction() -> String {
  1494. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_EMULATOR_ACTION) {
  1495. return value
  1496. }
  1497. return "0"
  1498. }
  1499. static func setCheckEmulatorAlertTitle(value: String){
  1500. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_EMULATOR_ALERT_TITLE)
  1501. }
  1502. static func getCheckEmulatorAlertTitle() -> String {
  1503. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_EMULATOR_ALERT_TITLE) {
  1504. if value.isEmpty {
  1505. return PreferencesKey.ss_emulator_title
  1506. }
  1507. return value
  1508. }
  1509. return PreferencesKey.ss_emulator_title
  1510. }
  1511. static func setCheckEmulatorAlertMessage(value: String){
  1512. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_EMULATOR_ALERT_MESSAGE)
  1513. }
  1514. static func getCheckEmulatorAlertMessage() -> String {
  1515. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_EMULATOR_ALERT_MESSAGE) {
  1516. if value.isEmpty {
  1517. return PreferencesKey.ss_emulator_continue
  1518. }
  1519. return value
  1520. }
  1521. return PreferencesKey.ss_emulator_continue
  1522. }
  1523. /**
  1524. * Root/Jailbreak Detection
  1525. */
  1526. static func setCheckRooted(value: Bool){
  1527. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_ROOTED)
  1528. }
  1529. static func getCheckRooted() -> Bool {
  1530. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_ROOTED) {
  1531. return value
  1532. }
  1533. return false
  1534. }
  1535. static func setCheckRootedAction(value: String){
  1536. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_ROOTED_ACTION)
  1537. }
  1538. static func getCheckRootedAction() -> String {
  1539. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_ROOTED_ACTION) {
  1540. return value
  1541. }
  1542. return "0"
  1543. }
  1544. static func setCheckRootedAlertTitle(value: String){
  1545. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_ROOTED_ALERT_TITLE)
  1546. }
  1547. static func getCheckRootedAlertTitle() -> String {
  1548. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_ROOTED_ALERT_TITLE) {
  1549. if value.isEmpty {
  1550. return PreferencesKey.ss_rooted_title
  1551. }
  1552. return value
  1553. }
  1554. return PreferencesKey.ss_rooted_title
  1555. }
  1556. static func setCheckRootedAlertMessage(value: String){
  1557. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_ROOTED_ALERT_MESSAGE)
  1558. }
  1559. static func getCheckRootedAlertMessage() -> String {
  1560. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_ROOTED_ALERT_MESSAGE) {
  1561. if value.isEmpty {
  1562. return PreferencesKey.ss_rooted_warning
  1563. }
  1564. return value
  1565. }
  1566. return PreferencesKey.ss_rooted_warning
  1567. }
  1568. /**
  1569. * Outdated OS Detection
  1570. */
  1571. static func setCheckOutdatedOs(value: Bool){
  1572. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_OUTDATED_OS)
  1573. }
  1574. static func getCheckOutdatedOs() -> Bool {
  1575. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_OUTDATED_OS) {
  1576. return value
  1577. }
  1578. return false
  1579. }
  1580. static func setCheckOutdatedOsAction(value: String){
  1581. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_ROOTED_ACTION)
  1582. }
  1583. static func getCheckOutdatedOsAction() -> String {
  1584. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_ROOTED_ACTION) {
  1585. return value
  1586. }
  1587. return "0"
  1588. }
  1589. static func setCheckOutdatedOsAlertTitle(value: String){
  1590. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_OUTDATED_OS_ALERT_TITLE)
  1591. }
  1592. static func getCheckOutdatedOsAlertTitle() -> String {
  1593. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_OUTDATED_OS_ALERT_TITLE) {
  1594. if value.isEmpty {
  1595. return PreferencesKey.ss_os_not_supported_title
  1596. }
  1597. return value
  1598. }
  1599. return PreferencesKey.ss_os_not_supported_title
  1600. }
  1601. static func setCheckOutdatedOsAlertMessage(value: String){
  1602. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_OUTDATED_OS_ALERT_MESSAGE)
  1603. }
  1604. static func getCheckOutdatedOsAlertMessage() -> String {
  1605. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_OUTDATED_OS_ALERT_MESSAGE) {
  1606. if value.isEmpty {
  1607. return PreferencesKey.ss_os_not_supported_continue
  1608. }
  1609. return value
  1610. }
  1611. return PreferencesKey.ss_os_not_supported_continue
  1612. }
  1613. static func setMinimumOsVersion(value: String){
  1614. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_MINIMUM_OS_VERSION)
  1615. }
  1616. static func getMinimumOsVersion() -> String {
  1617. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_MINIMUM_OS_VERSION) {
  1618. return value
  1619. }
  1620. return "14"
  1621. }
  1622. /**
  1623. * Tempering Detection
  1624. */
  1625. static func setCheckTempering(value: Bool){
  1626. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_TEMPERING)
  1627. }
  1628. static func getCheckTempering() -> Bool {
  1629. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_TEMPERING) {
  1630. return value
  1631. }
  1632. return false
  1633. }
  1634. static func setCheckTemperingAction(value: String){
  1635. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_TEMPERING_ACTION)
  1636. }
  1637. static func getCheckTemperingAction() -> String {
  1638. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_TEMPERING_ACTION) {
  1639. return value
  1640. }
  1641. return "0"
  1642. }
  1643. static func setCheckTemperingAlertTitle(value: String){
  1644. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_TEMPERING_ALERT_TITLE)
  1645. }
  1646. static func getCheckTemperingAlertTitle() -> String {
  1647. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_TEMPERING_ALERT_TITLE) {
  1648. if value.isEmpty {
  1649. return PreferencesKey.ss_tempering_title
  1650. }
  1651. return value
  1652. }
  1653. return PreferencesKey.ss_tempering_title
  1654. }
  1655. static func setCheckTemperingAlertMessage(value: String){
  1656. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_TEMPERING_ALERT_MESSAGE)
  1657. }
  1658. static func getCheckTemperingAlertMessage() -> String {
  1659. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_TEMPERING_ALERT_MESSAGE) {
  1660. if value.isEmpty {
  1661. return PreferencesKey.ss_tempering_warning
  1662. }
  1663. return value
  1664. }
  1665. return PreferencesKey.ss_tempering_warning
  1666. }
  1667. /**
  1668. * Debugging Detection
  1669. */
  1670. static func setCheckDebugging(value: Bool){
  1671. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_DEBUGGING)
  1672. }
  1673. static func getCheckDebugging() -> Bool {
  1674. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_DEBUGGING) {
  1675. return value
  1676. }
  1677. return false
  1678. }
  1679. static func setCheckDebuggingAction(value: String){
  1680. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_DEBUGGING_ACTION)
  1681. }
  1682. static func getCheckDebuggingAction() -> String {
  1683. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_DEBUGGING_ACTION) {
  1684. return value
  1685. }
  1686. return "0"
  1687. }
  1688. static func setCheckDebuggingAlertTitle(value: String){
  1689. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_DEBUGGING_ALERT_TITLE)
  1690. }
  1691. static func getCheckDebuggingAlertTitle() -> String {
  1692. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_DEBUGGING_ALERT_TITLE) {
  1693. if value.isEmpty {
  1694. return PreferencesKey.ss_debugging_title
  1695. }
  1696. return value
  1697. }
  1698. return PreferencesKey.ss_debugging_title
  1699. }
  1700. static func setCheckDebuggingAlertMessage(value: String){
  1701. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_DEBUGGING_ALERT_MESSAGE)
  1702. }
  1703. static func getCheckDebuggingAlertMessage() -> String {
  1704. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_DEBUGGING_ALERT_MESSAGE) {
  1705. if value.isEmpty {
  1706. return PreferencesKey.ss_debugging_warning
  1707. }
  1708. return value
  1709. }
  1710. return PreferencesKey.ss_debugging_warning
  1711. }
  1712. /**
  1713. * Screen Casting
  1714. */
  1715. static func setCheckScreenCasting(value: Bool){
  1716. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_CASTING)
  1717. }
  1718. static func getCheckScreenCasting() -> Bool {
  1719. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_CASTING) {
  1720. return value
  1721. }
  1722. return false
  1723. }
  1724. static func setCheckScreenCastingAction(value: String){
  1725. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_CASTING_ACTION)
  1726. }
  1727. static func getCheckScreenCastingAction() -> String {
  1728. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_CASTING_ACTION) {
  1729. return value
  1730. }
  1731. return "0"
  1732. }
  1733. static func setCheckScreenCastingAlertTitle(value: String){
  1734. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_CASTING_ALERT_TITLE)
  1735. }
  1736. static func getCheckScreenCastingAlertTitle() -> String {
  1737. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_CASTING_ALERT_TITLE) {
  1738. if value.isEmpty {
  1739. return PreferencesKey.ss_debugging_title
  1740. }
  1741. return value
  1742. }
  1743. return PreferencesKey.ss_debugging_title
  1744. }
  1745. static func setCheckScreenCastingAlertMessage(value: String){
  1746. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_CASTING_ALERT_MESSAGE)
  1747. }
  1748. static func getCheckScreenCastingAlertMessage() -> String {
  1749. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_CASTING_ALERT_MESSAGE) {
  1750. if value.isEmpty {
  1751. return PreferencesKey.ss_debugging_warning
  1752. }
  1753. return value
  1754. }
  1755. return PreferencesKey.ss_debugging_warning
  1756. }
  1757. /**
  1758. * Screen Overlay
  1759. */
  1760. static func setCheckScreenOverlay(value: Bool){
  1761. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_OVERLAY)
  1762. }
  1763. static func getCheckScreenOverlay() -> Bool {
  1764. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_OVERLAY) {
  1765. return value
  1766. }
  1767. return false
  1768. }
  1769. static func setCheckScreenOverlayAction(value: String){
  1770. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_OVERLAY_ACTION)
  1771. }
  1772. static func getCheckScreenOverlayAction() -> String {
  1773. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_OVERLAY_ACTION) {
  1774. return value
  1775. }
  1776. return "0"
  1777. }
  1778. static func setCheckScreenOverlayAlertTitle(value: String){
  1779. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_OVERLAY_ALERT_TITLE)
  1780. }
  1781. static func getCheckScreenOverlayAlertTitle() -> String {
  1782. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_OVERLAY_ALERT_TITLE) {
  1783. if value.isEmpty {
  1784. return PreferencesKey.ss_screenoverlay_title
  1785. }
  1786. return value
  1787. }
  1788. return PreferencesKey.ss_screenoverlay_title
  1789. }
  1790. static func setCheckScreenOverlayAlertMessage(value: String){
  1791. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_OVERLAY_ALERT_MESSAGE)
  1792. }
  1793. static func getCheckScreenOverlayAlertMessage() -> String {
  1794. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_OVERLAY_ALERT_MESSAGE) {
  1795. if value.isEmpty {
  1796. return PreferencesKey.ss_screenoverlay_continue
  1797. }
  1798. return value
  1799. }
  1800. return PreferencesKey.ss_screenoverlay_continue
  1801. }
  1802. /**
  1803. * Call Redirection Detection
  1804. */
  1805. static func setCheckCallForward(value: Bool){
  1806. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_CALL_FORWARD)
  1807. }
  1808. static func getCheckCallForward() -> Bool {
  1809. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_CALL_FORWARD) {
  1810. return value
  1811. }
  1812. return false
  1813. }
  1814. static func setCheckCallForwardAction(value: String){
  1815. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_CALL_FORWARD_ACTION)
  1816. }
  1817. static func getCheckCallForwardAction() -> String {
  1818. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_CALL_FORWARD_ACTION) {
  1819. return value
  1820. }
  1821. return "0"
  1822. }
  1823. static func setCheckCallForwardAlertTitle(value: String){
  1824. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_CALL_FORWARD_ALERT_TITLE)
  1825. }
  1826. static func getCheckCallForwardAlertTitle() -> String {
  1827. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_CALL_FORWARD_ALERT_TITLE) {
  1828. if value.isEmpty {
  1829. return PreferencesKey.ss_callforward_title
  1830. }
  1831. return value
  1832. }
  1833. return PreferencesKey.ss_callforward_title
  1834. }
  1835. static func setCheckCallForwardAlertMessage(value: String){
  1836. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_CALL_FORWARD_ALERT_MESSAGE)
  1837. }
  1838. static func getCheckCallForwardAlertMessage() -> String {
  1839. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_CALL_FORWARD_ALERT_MESSAGE) {
  1840. if value.isEmpty {
  1841. return PreferencesKey.ss_callforward_continue
  1842. }
  1843. return value
  1844. }
  1845. return PreferencesKey.ss_callforward_continue
  1846. }
  1847. /**
  1848. * Multiple Login Detection
  1849. */
  1850. static func setCheckMultipleLogin(value: Bool){
  1851. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_MULTIPLE_LOGIN)
  1852. }
  1853. static func getCheckMultipleLogin() -> Bool {
  1854. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_MULTIPLE_LOGIN) {
  1855. return value
  1856. }
  1857. return false
  1858. }
  1859. static func setCheckMultipleLoginAction(value: String){
  1860. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_MULTIPLE_LOGIN_ACTION)
  1861. }
  1862. static func getCheckMultipleLoginAction() -> String {
  1863. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_MULTIPLE_LOGIN_ACTION) {
  1864. return value
  1865. }
  1866. return "0"
  1867. }
  1868. static func setCheckMultipleLoginAlertTitle(value: String){
  1869. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_MULTIPLE_LOGIN_ALERT_TITLE)
  1870. }
  1871. static func getCheckMultipleLoginAlertTitle() -> String {
  1872. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_MULTIPLE_LOGIN_ALERT_TITLE) {
  1873. if value.isEmpty {
  1874. return PreferencesKey.ss_multiple_login_title
  1875. }
  1876. return value
  1877. }
  1878. return PreferencesKey.ss_multiple_login_title
  1879. }
  1880. static func setCheckMultipleLoginAlertMessage(value: String){
  1881. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_MULTIPLE_LOGIN_ALERT_MESSAGE)
  1882. }
  1883. static func getCheckMultipleLoginAlertMessage() -> String {
  1884. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_MULTIPLE_LOGIN_ALERT_MESSAGE) {
  1885. if value.isEmpty {
  1886. return PreferencesKey.ss_multiple_login_warning
  1887. }
  1888. return value
  1889. }
  1890. return PreferencesKey.ss_multiple_login_warning
  1891. }
  1892. /**
  1893. * SIM Swap Detection
  1894. */
  1895. static func setCheckSimSwap(value: Bool){
  1896. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SIM_SWAP)
  1897. }
  1898. static func getCheckSimSwap() -> Bool {
  1899. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SIM_SWAP) {
  1900. return value
  1901. }
  1902. return false
  1903. }
  1904. static func setCheckSimSwapAction(value: String){
  1905. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SIM_SWAP_ACTION)
  1906. }
  1907. static func getCheckSimSwapAction() -> String {
  1908. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SIM_SWAP_ACTION) {
  1909. return value
  1910. }
  1911. return "0"
  1912. }
  1913. static func setCheckSimSwapAlertTitle(value: String){
  1914. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SIM_SWAP_ALERT_TITLE)
  1915. }
  1916. static func getCheckSimSwapAlertTitle() -> String {
  1917. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SIM_SWAP_ALERT_TITLE) {
  1918. if value.isEmpty {
  1919. return PreferencesKey.ss_simswap_title
  1920. }
  1921. return value
  1922. }
  1923. return PreferencesKey.ss_simswap_title
  1924. }
  1925. static func setCheckSimSwapAlertMessage(value: String){
  1926. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SIM_SWAP_ALERT_MESSAGE)
  1927. }
  1928. static func getCheckSimSwapAlertMessage() -> String {
  1929. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SIM_SWAP_ALERT_MESSAGE) {
  1930. if value.isEmpty {
  1931. return PreferencesKey.ss_simswap_warning
  1932. }
  1933. return value
  1934. }
  1935. return PreferencesKey.ss_simswap_warning
  1936. }
  1937. /**
  1938. * Geo-Velocity Checks
  1939. */
  1940. static func setCheckGeoVelocity(value: Bool){
  1941. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_GEO_VELOCITY)
  1942. }
  1943. static func getCheckGeoVelocity() -> Bool {
  1944. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_GEO_VELOCITY) {
  1945. return value
  1946. }
  1947. return false
  1948. }
  1949. static func setCheckGeoVelocityAction(value: String){
  1950. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_GEO_VELOCITY_ACTION)
  1951. }
  1952. static func getCheckGeoVelocityAction() -> String {
  1953. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_GEO_VELOCITY_ACTION) {
  1954. return value
  1955. }
  1956. return "0"
  1957. }
  1958. static func setCheckGeoVelocityAlertTitle(value: String){
  1959. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_GEO_VELOCITY_ALERT_TITLE)
  1960. }
  1961. static func getCheckGeoVelocityAlertTitle() -> String {
  1962. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_GEO_VELOCITY_ALERT_TITLE) {
  1963. if value.isEmpty {
  1964. return PreferencesKey.ss_geo_velocity_title
  1965. }
  1966. return value
  1967. }
  1968. return PreferencesKey.ss_geo_velocity_title
  1969. }
  1970. static func setCheckGeoVelocityAlertMessage(value: String){
  1971. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_GEO_VELOCITY_ALERT_MESSAGE)
  1972. }
  1973. static func getCheckGeoVelocityAlertMessage() -> String {
  1974. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_GEO_VELOCITY_ALERT_MESSAGE) {
  1975. if value.isEmpty {
  1976. return PreferencesKey.ss_geo_velocity_warning
  1977. }
  1978. return value
  1979. }
  1980. return PreferencesKey.ss_geo_velocity_warning
  1981. }
  1982. /**
  1983. * Behavioral Anomaly Detection
  1984. */
  1985. static func setCheckBehaviourAnalysis(value: Bool){
  1986. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_BEHAVIOUR_ANALYSIS)
  1987. }
  1988. static func getCheckBehaviourAnalysis() -> Bool {
  1989. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_BEHAVIOUR_ANALYSIS) {
  1990. return value
  1991. }
  1992. return false
  1993. }
  1994. static func setCheckBehaviourAnalysisAction(value: String){
  1995. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_BEHAVIOUR_ANALYSIS_ACTION)
  1996. }
  1997. static func getCheckBehaviourAnalysisAction() -> String {
  1998. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_BEHAVIOUR_ANALYSIS_ACTION) {
  1999. return value
  2000. }
  2001. return "0"
  2002. }
  2003. static func setCheckBehaviourAnalysisAlertTitle(value: String){
  2004. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_BEHAVIOUR_ANALYSIS_ALERT_TITLE)
  2005. }
  2006. static func getCheckBehaviourAnalysisAlertTitle() -> String {
  2007. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_BEHAVIOUR_ANALYSIS_ALERT_TITLE) {
  2008. if value.isEmpty {
  2009. return PreferencesKey.ss_behaviour_anomaly_title
  2010. }
  2011. return value
  2012. }
  2013. return PreferencesKey.ss_behaviour_anomaly_title
  2014. }
  2015. static func setCheckBehaviourAnalysisAlertMessage(value: String){
  2016. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_BEHAVIOUR_ANALYSIS_ALERT_MESSAGE)
  2017. }
  2018. static func getCheckBehaviourAnalysisAlertMessage() -> String {
  2019. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_BEHAVIOUR_ANALYSIS_ALERT_MESSAGE) {
  2020. if value.isEmpty {
  2021. return PreferencesKey.ss_behaviour_anomaly_warning
  2022. }
  2023. return value
  2024. }
  2025. return PreferencesKey.ss_behaviour_anomaly_warning
  2026. }
  2027. /**
  2028. * Hooked Detection
  2029. */
  2030. static func setCheckHooked(value: Bool){
  2031. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_HOOKED)
  2032. }
  2033. static func getCheckHooked() -> Bool {
  2034. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_HOOKED) {
  2035. return value
  2036. }
  2037. return false
  2038. }
  2039. static func setCheckHookedAction(value: String){
  2040. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_HOOKED_ACTION)
  2041. }
  2042. static func getCheckHookedAction() -> String {
  2043. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_HOOKED_ACTION) {
  2044. return value
  2045. }
  2046. return "0"
  2047. }
  2048. static func setCheckHookedAlertTitle(value: String){
  2049. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_HOOKED_ALERT_TITLE)
  2050. }
  2051. static func getCheckHookedAlertTitle() -> String {
  2052. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_HOOKED_ALERT_TITLE) {
  2053. if value.isEmpty {
  2054. return PreferencesKey.ss_hooked_title
  2055. }
  2056. return value
  2057. }
  2058. return PreferencesKey.ss_hooked_title
  2059. }
  2060. static func setCheckHookedAlertMessage(value: String){
  2061. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_HOOKED_ALERT_MESSAGE)
  2062. }
  2063. static func getCheckHookedAlertMessage() -> String {
  2064. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_HOOKED_ALERT_MESSAGE) {
  2065. if value.isEmpty {
  2066. return PreferencesKey.ss_hooked_warning
  2067. }
  2068. return value
  2069. }
  2070. return PreferencesKey.ss_hooked_warning
  2071. }
  2072. }
  2073. private class PreferencesKey {
  2074. static let SECURITY_SHIELD_ALERT_EXIT = "0"
  2075. static let SECURITY_SHIELD_ALERT_CONTINUE = "1"
  2076. static let ERR121 = "121:Emulator detected"
  2077. static let ERR122 = "122:Malware detected"
  2078. static let ERR123 = "123:USB/WiFi debugging detected"
  2079. static let ERR124 = "124:Cloned app detected"
  2080. static let ERR125 = "125:Call forwarding detected"
  2081. static let ERR126 = "126:Screen sharing detected"
  2082. static let ERR127 = "127:OS Version not supported"
  2083. static let ERR128 = "128:Application backup detected"
  2084. static let ERR129 = "129:Failed security reasons"
  2085. static let ERR130 = "130:Tampering detected"
  2086. static let ERR131 = "131:SIM Swap detected"
  2087. static let ERR132 = "132:Behavioral Anomaly detected"
  2088. static let SS_CONNECTION_ID = "ss_connection_id"
  2089. static let SS_USER_APP_ID = "ss_user_app_id"
  2090. static let SS_USER_ACCOUNT = "ss_user_account"
  2091. static let SS_DOMAIN_OPR = "domain_opr"
  2092. static let SS_IP_PORT_OPR = "ip_opr"
  2093. static let SS_CHECK_KEYLOGGER = "ss_check_keylogger"
  2094. static let SS_CHECK_KEYLOGGER_ACTION = "ss_check_keylogger_action"
  2095. static let SS_CHECK_KEYLOGGER_ALERT_TITLE = "ss_check_keylogger_alert_title"
  2096. static let SS_CHECK_KEYLOGGER_ALERT_MESSAGE = "ss_check_keylogger_alert_message"
  2097. static let SS_CHECK_SCREEN_CAPTURE = "ss_check_screen_capture"
  2098. static let SS_CHECK_SCREEN_CAPTURE_ACTION = "ss_check_screen_capture_action"
  2099. static let SS_CHECK_SCREEN_CAPTURE_ALERT_TITLE = "ss_check_screen_capture_alert_title"
  2100. static let SS_CHECK_SCREEN_CAPTURE_ALERT_MESSAGE = "ss_check_screen_capture_alert_message"
  2101. static let ss_screenshare_title = "Screen Sharing Detected!"
  2102. static let ss_screenshare_warning = "We are sorry for the inconvenience. For security reasons this app is not allowed to cast/share screen display. The application will automatically stop.<br><br>To try again, please stop the screen casting/sharing."
  2103. static let SS_CHECK_EMULATOR = "ss_check_emulator"
  2104. static let SS_CHECK_EMULATOR_ACTION = "ss_check_emulator_action"
  2105. static let SS_CHECK_EMULATOR_ALERT_TITLE = "ss_check_emulator_alert_title"
  2106. static let SS_CHECK_EMULATOR_ALERT_MESSAGE = "ss_check_emulator_alert_message"
  2107. static let ss_emulator_title = "Emulator Detected!"
  2108. static let ss_emulator_continue = "We are sorry for the inconvenience. For security reasons this app is not allowed to run on an emulator."
  2109. static let SS_CHECK_ROOTED = "ss_check_rooted"
  2110. static let SS_CHECK_ROOTED_ACTION = "ss_check_rooted_action"
  2111. static let SS_CHECK_ROOTED_ALERT_TITLE = "ss_check_rooted_alert_title"
  2112. static let SS_CHECK_ROOTED_ALERT_MESSAGE = "ss_check_rooted_alert_message"
  2113. static let ss_rooted_title = "Root or Jailbreak Detected!"
  2114. static let ss_rooted_warning = "The operating system on your device has been modified unauthorizedly(the root). The modification might compromise secure access to organizational resources such as email and documents.<br><br> %app_name% will not work on your device. Please reset/unroot your device or contact %app_name% customer center for further information. We apologize for the inconvenient."
  2115. static let SS_CHECK_OUTDATED_OS = "ss_check_outdated_os"
  2116. static let SS_CHECK_OUTDATED_OS_ACTION = "ss_check_outdated_os_action"
  2117. static let SS_CHECK_OUTDATED_OS_ALERT_TITLE = "ss_check_outdated_os_alert_title"
  2118. static let SS_CHECK_OUTDATED_OS_ALERT_MESSAGE = "ss_check_outdated_os_alert_message"
  2119. static let SS_CHECK_MINIMUM_OS_VERSION = "ss_minimum_os_version"
  2120. static let ss_os_not_supported_title = "Android Version Not Secure!"
  2121. static let ss_os_not_supported_continue = "We are sorry for the inconvenience. This device's Android version has been deemed as no longer secure."
  2122. static let SS_CHECK_TEMPERING = "ss_check_tempering"
  2123. static let SS_CHECK_TEMPERING_ACTION = "ss_check_tempering_action"
  2124. static let SS_CHECK_TEMPERING_ALERT_TITLE = "ss_check_tempering_alert_title"
  2125. static let SS_CHECK_TEMPERING_ALERT_MESSAGE = "ss_check_tempering_alert_message"
  2126. static let ss_tempering_title = "Tempering Detected!"
  2127. static let ss_tempering_warning = "Our security shield has detected changes in the application that may indicate tempering, which could potentially lead to malware infection, data manipulation, and other risks. Please remove this apps and download from official Google Play Store."
  2128. static let SS_CHECK_DEBUGGING = "ss_check_debugging"
  2129. static let SS_CHECK_DEBUGGING_ACTION = "ss_check_debugging_action"
  2130. static let SS_CHECK_DEBUGGING_ALERT_TITLE = "ss_check_debugging_alert_title"
  2131. static let SS_CHECK_DEBUGGING_ALERT_MESSAGE = "ss_check_debugging_alert_message"
  2132. static let ss_debugging_title = "Debugging Mode Detected!"
  2133. static let ss_debugging_warning = "Your device running on debugging mode. Please disable it."
  2134. static let SS_CHECK_SCREEN_CASTING = "ss_check_screen_casting"
  2135. static let SS_CHECK_SCREEN_CASTING_ACTION = "ss_check_screen_casting_action"
  2136. static let SS_CHECK_SCREEN_CASTING_ALERT_TITLE = "ss_check_screen_casting_alert_title"
  2137. static let SS_CHECK_SCREEN_CASTING_ALERT_MESSAGE = "ss_check_screen_casting_alert_message"
  2138. static let SS_CHECK_SCREEN_OVERLAY = "ss_check_screen_overlay"
  2139. static let SS_CHECK_SCREEN_OVERLAY_ACTION = "ss_check_screen_overlay_action"
  2140. static let SS_CHECK_SCREEN_OVERLAY_ALERT_TITLE = "ss_check_screen_overlay_alert_title"
  2141. static let SS_CHECK_SCREEN_OVERLAY_ALERT_MESSAGE = "ss_check_screen_overlay_alert_message"
  2142. static let ss_screenoverlay_title = "Screen Overlay Detected!"
  2143. static let ss_screenoverlay_continue = "We are sorry for the inconvenience. For security reasons this app is not allowed to share screen overlay. Please stop the screen overlay in app setting."
  2144. static let SS_CHECK_CALL_FORWARD = "ss_check_call_forward"
  2145. static let SS_CHECK_CALL_FORWARD_ACTION = "ss_check_call_forward_action"
  2146. static let SS_CHECK_CALL_FORWARD_ALERT_TITLE = "ss_check_call_forward_alert_title"
  2147. static let SS_CHECK_CALL_FORWARD_ALERT_MESSAGE = "ss_check_call_forward_alert_message"
  2148. static let ss_callforward_title = "Call Forwarding Detected!";
  2149. static let ss_callforward_continue = "We are sorry for the inconvenience. For security reasons this app does not recommend allowing call forwarding to be active.";
  2150. static let SS_CHECK_MULTIPLE_LOGIN = "ss_check_multiple_login"
  2151. static let SS_CHECK_MULTIPLE_LOGIN_ACTION = "ss_check_multiple_login_action"
  2152. static let SS_CHECK_MULTIPLE_LOGIN_ALERT_TITLE = "ss_check_multiple_login_alert_title"
  2153. static let SS_CHECK_MULTIPLE_LOGIN_ALERT_MESSAGE = "ss_check_multiple_login_alert_message"
  2154. static let ss_multiple_login_title = "Multiple Login Detected!"
  2155. static let ss_multiple_login_warning = "We have detected multiple login attempts to your account from different devices or locations within a short period. This alert is designed to protect your account and ensure your security.<br><br> If you initiated these logins, no further action is required. However, if you did not authorize this activity, it is crucial to take immediate steps to safeguard your account. Unauthorized access may put your personal information at risk."
  2156. static let SS_CHECK_SIM_SWAP = "ss_check_sim_swap"
  2157. static let SS_CHECK_SIM_SWAP_ACTION = "ss_check_sim_swap_action"
  2158. static let SS_CHECK_SIM_SWAP_ALERT_TITLE = "ss_check_sim_swap_alert_title"
  2159. static let SS_CHECK_SIM_SWAP_ALERT_MESSAGE = "ss_check_sim_swap_alert_message"
  2160. static let ss_simswap_title = "Sim Swap Detected!"
  2161. static let ss_simswap_warning = "We noticed some unusual app behaviors and activities, including SimCard Swap on your device. If these actions were not initiated by you or you are unsure about any apps, please change your true number imediately."
  2162. static let SS_CHECK_GEO_VELOCITY = "ss_check_geo_velocity"
  2163. static let SS_CHECK_GEO_VELOCITY_ACTION = "ss_check_geo_velocity_action"
  2164. static let SS_CHECK_GEO_VELOCITY_ALERT_TITLE = "ss_check_geo_velocity_alert_title"
  2165. static let SS_CHECK_GEO_VELOCITY_ALERT_MESSAGE = "ss_check_geo_velocity_alert_message"
  2166. static let ss_geo_velocity_title = "Geo Velocity Anomaly Detected!"
  2167. static let ss_geo_velocity_warning = "Anomalies have been identified in the location check associated with your account. This warning is issued to inform you of significant irregularities in the expected location data. Immediate attention is required to address these anomalies, as they may impact your account's functionality, security, and overall user experience."
  2168. static let SS_CHECK_BEHAVIOUR_ANALYSIS = "ss_check_behaviour_analysis"
  2169. static let SS_CHECK_BEHAVIOUR_ANALYSIS_ACTION = "ss_check_behaviour_analysis_action"
  2170. static let SS_CHECK_BEHAVIOUR_ANALYSIS_ALERT_TITLE = "ss_check_behaviour_analysis_alert_title"
  2171. static let SS_CHECK_BEHAVIOUR_ANALYSIS_ALERT_MESSAGE = "ss_check_behaviour_analysis_alert_message"
  2172. static let ss_behaviour_anomaly_title = "Behaviour Anomaly Detected!"
  2173. static let ss_behaviour_anomaly_warning = "We have identified a significant anomaly in the behavior of your device. This notification serves as a precautionary measure, as unusual patterns can indicate potential security threats, unauthorized access, or software malfunctions that could compromise your data and overall device performance."
  2174. static let SS_CHECK_HOOKED = "ss_check_hooked"
  2175. static let SS_CHECK_HOOKED_ACTION = "ss_check_hooked_action"
  2176. static let SS_CHECK_HOOKED_ALERT_TITLE = "ss_check_hooked_alert_title"
  2177. static let SS_CHECK_HOOKED_ALERT_MESSAGE = "ss_check_hooked_alert_message"
  2178. static let ss_hooked_title = "Hooked Detected!"
  2179. static let ss_hooked_warning = "Our security shield has detected changes in the application that may indicate Hook or Anti Frida, which could potentially lead to malware infection, data manipulation, and other risks. Please remove this apps and download from official App Store."
  2180. }
  2181. private class SelfSignedURLSessionDelegate: NSObject, URLSessionTaskDelegate, URLSessionDataDelegate {
  2182. func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
  2183. if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
  2184. if let serverTrust = challenge.protectionSpace.serverTrust {
  2185. let credential = URLCredential(trust: serverTrust)
  2186. completionHandler(.useCredential, credential)
  2187. }
  2188. }
  2189. }
  2190. }
  2191. private class UtilsSS {
  2192. private static let I_BB = 48 // 0
  2193. private static let I_BBT_1 = 57 // 9
  2194. private static let I_BAT_1 = 65 // A
  2195. private static let I_BBT_2 = 90 // Z
  2196. private static let I_BAT_2 = 97 // a
  2197. private static let I_BA = 122 // z
  2198. private static let IC_BB = 33 // !
  2199. private static let IC_BBT_1 = 47 // /
  2200. private static let IC_BAT_1 = 58 // :
  2201. private static let IC_BBT_2 = 64 // @
  2202. private static let IC_BAT_2 = 91 // [
  2203. private static let IC_BBT_3 = 96 // @
  2204. private static let IC_BAT_3 = 123 // [
  2205. private static let IC_BA = 126 // `
  2206. private static var icIGNORE = Set<Int>()
  2207. private static func initIcIgnore() {
  2208. icIGNORE.insert(10)// \r
  2209. icIGNORE.insert(13)// \n
  2210. icIGNORE.insert(32)// <space>
  2211. }
  2212. public static func decrypt(str: String) -> String {
  2213. var arr: [Character]
  2214. var iRandom = 0
  2215. var sDecrypt: String
  2216. iRandom = Int(str.substring(from: 0, to: 0)) ?? 0
  2217. sDecrypt = getPalindrom(str: str.substring(from: 1, to: nil))
  2218. arr = Array(sDecrypt)
  2219. for i in 0..<arr.count {
  2220. if (isSpecialChar(ch: arr[i])) {
  2221. arr[i] = getBeforecChar(ch: arr[i], inc: iRandom)
  2222. } else {
  2223. arr[i] = getBeforeChar(ch: arr[i], inc: iRandom)
  2224. }
  2225. }
  2226. return String(arr)
  2227. }
  2228. private static func isSpecialChar(ch: Character) -> Bool {
  2229. let ch = Int(ch.asciiValue ?? 0)
  2230. return (ch >= IC_BB && ch <= IC_BBT_1) || (ch >= IC_BAT_1 && ch <= IC_BBT_2) || (ch >= IC_BAT_2 && ch <= IC_BBT_3) || (ch >= IC_BAT_3 && ch <= IC_BA)
  2231. }
  2232. private static func getPalindrom(str: String) -> String {
  2233. let arr: [Character] = Array(str)
  2234. var arr2: [Character] = Array(arr)
  2235. for i in 0..<arr.count {
  2236. arr2[i] = arr[arr.count - (i + 1)]
  2237. }
  2238. return String(arr2)
  2239. }
  2240. private static func getBeforeChar(ch: Character, inc: Int) -> Character {
  2241. if icIGNORE.isEmpty {
  2242. initIcIgnore()
  2243. }
  2244. var iAscii = ch
  2245. let iAsciiBefore = iAscii
  2246. if (icIGNORE.contains(Int(iAscii.asciiValue ?? 0))) {
  2247. return iAscii;
  2248. }
  2249. if Int(iAscii.asciiValue ?? 0) > I_BA || Int(iAscii.asciiValue ?? 0) < I_BB {
  2250. } else {
  2251. if !icIGNORE.contains(Int(iAscii.asciiValue ?? 0)) {
  2252. iAscii = Character(UnicodeScalar(Int(iAscii.asciiValue ?? 0) - inc)!)
  2253. if (I_BAT_1 > Int(iAscii.asciiValue ?? 0) && Int(iAsciiBefore.asciiValue ?? 0) >= I_BAT_1) {
  2254. iAscii = Character(UnicodeScalar((I_BBT_1 + 1) - (I_BAT_1 - Int(iAscii.asciiValue ?? 0)))!)
  2255. }
  2256. if (I_BAT_2 > Int(iAscii.asciiValue ?? 0) && Int(iAsciiBefore.asciiValue ?? 0) >= I_BAT_2) {
  2257. iAscii = Character(UnicodeScalar((I_BBT_2 + 1) - (I_BAT_2 - Int(iAscii.asciiValue ?? 0)))!)
  2258. }
  2259. if (Int(iAscii.asciiValue ?? 0) < I_BB) {
  2260. iAscii = Character(UnicodeScalar((I_BA + 1) + (Int(iAscii.asciiValue ?? 0) - I_BB))!)
  2261. }
  2262. }
  2263. }
  2264. return iAscii
  2265. }
  2266. private static func getBeforecChar(ch: Character, inc: Int) -> Character {
  2267. var iAscii = ch
  2268. let iAsciiBefore = iAscii
  2269. if (Int(iAscii.asciiValue ?? 0) > IC_BA || Int(iAscii.asciiValue ?? 0) < IC_BB) {
  2270. } else {
  2271. iAscii = Character(UnicodeScalar(Int(iAscii.asciiValue ?? 0) - inc)!)
  2272. if (Int(iAscii.asciiValue ?? 0) < IC_BB) {
  2273. iAscii = Character(UnicodeScalar((IC_BA + 1) + (Int(iAscii.asciiValue ?? 0) - IC_BB))!)
  2274. if (Int(iAscii.asciiValue ?? 0) < IC_BAT_3 && Int(iAscii.asciiValue ?? 0) > IC_BBT_3) {
  2275. iAscii = Character(UnicodeScalar((IC_BBT_3 + 1) - (IC_BAT_3 - Int(iAscii.asciiValue ?? 0)))!)
  2276. }
  2277. }
  2278. if (IC_BAT_3 > Int(iAscii.asciiValue ?? 0) && Int(iAsciiBefore.asciiValue ?? 0) >= IC_BAT_3) {
  2279. iAscii = Character(UnicodeScalar((IC_BBT_3 + 1) - (IC_BAT_3 - Int(iAscii.asciiValue ?? 0)))!)
  2280. }
  2281. if (IC_BAT_2 > Int(iAscii.asciiValue ?? 0) && Int(iAsciiBefore.asciiValue ?? 0) >= IC_BAT_2) {
  2282. iAscii = Character(UnicodeScalar((IC_BBT_2 + 1) - (IC_BAT_2 - Int(iAscii.asciiValue ?? 0)))!)
  2283. }
  2284. if (IC_BAT_1 > Int(iAscii.asciiValue ?? 0) && Int(iAsciiBefore.asciiValue ?? 0) >= IC_BAT_1) {
  2285. iAscii = Character(UnicodeScalar((IC_BBT_1 + 1) - (IC_BAT_1 - Int(iAscii.asciiValue ?? 0)))!)
  2286. }
  2287. }
  2288. return iAscii
  2289. }
  2290. }
  2291. extension String {
  2292. func substring(from: Int?, to: Int?) -> String {
  2293. if let start = from {
  2294. guard start < self.count else {
  2295. return ""
  2296. }
  2297. }
  2298. if let end = to {
  2299. guard end >= 0 else {
  2300. return ""
  2301. }
  2302. }
  2303. if let start = from, let end = to {
  2304. guard end - start >= 0 else {
  2305. return ""
  2306. }
  2307. }
  2308. let startIndex: String.Index
  2309. if let start = from, start >= 0 {
  2310. startIndex = self.index(self.startIndex, offsetBy: start)
  2311. } else {
  2312. startIndex = self.startIndex
  2313. }
  2314. let endIndex: String.Index
  2315. if let end = to, end >= 0, end < self.count {
  2316. endIndex = self.index(self.startIndex, offsetBy: end + 1)
  2317. } else {
  2318. endIndex = self.endIndex
  2319. }
  2320. return String(self[startIndex ..< endIndex])
  2321. }
  2322. }
  2323. extension UIColor {
  2324. static var mainColorSS: UIColor {
  2325. return renderColor(hex: "#046cfc")
  2326. }
  2327. static var blackDarkModeSS: UIColor {
  2328. return renderColor(hex: "#262626")
  2329. }
  2330. private class func renderColor(hex: String) -> UIColor {
  2331. var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
  2332. if (cString.hasPrefix("#")) {
  2333. cString.remove(at: cString.startIndex)
  2334. }
  2335. if ((cString.count) != 6) {
  2336. return UIColor.gray
  2337. }
  2338. var rgbValue:UInt64 = 0
  2339. Scanner(string: cString).scanHexInt64(&rgbValue)
  2340. return UIColor(
  2341. red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
  2342. green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
  2343. blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
  2344. alpha: CGFloat(1.0)
  2345. )
  2346. }
  2347. }
  2348. extension UIApplication {
  2349. static var appVersion: String? {
  2350. return Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
  2351. }
  2352. var rootViewController: UIViewController? {
  2353. return UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController
  2354. }
  2355. var visibleViewController: UIViewController? {
  2356. let keyWindow = UIApplication.shared.windows.filter {$0.isKeyWindow}.first
  2357. if var topController = keyWindow?.rootViewController {
  2358. while let presentedViewController = topController.presentedViewController {
  2359. topController = presentedViewController
  2360. }
  2361. return topController
  2362. }
  2363. return nil
  2364. }
  2365. }
  2366. extension UIImage {
  2367. static func imageWithColorSS(color: UIColor, size: CGSize) -> UIImage? {
  2368. let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
  2369. UIGraphicsBeginImageContextWithOptions(size, false, 0)
  2370. color.setFill()
  2371. UIRectFill(rect)
  2372. guard let image: UIImage = UIGraphicsGetImageFromCurrentImageContext() else {
  2373. return nil
  2374. }
  2375. UIGraphicsEndImageContext()
  2376. return image
  2377. }
  2378. }
  2379. private class TMessageSS {
  2380. var mType: String = ""
  2381. var mVersion: String = ""
  2382. var mCode: String = ""
  2383. var mStatus: String = ""
  2384. var mPIN: String = ""
  2385. var mL_PIN: String = ""
  2386. var mBodies: [String: String] = [String: String]()
  2387. private var mMedia:[UInt8] = [UInt8]()
  2388. let C_HEADER:UnicodeScalar = UnicodeScalar(0x01)
  2389. let C_ENTRY:UnicodeScalar = UnicodeScalar(0x02)
  2390. let C_KEYVAL:UnicodeScalar = UnicodeScalar(0x03)
  2391. let C_ARRAY:UnicodeScalar = UnicodeScalar(0x04)
  2392. var S_HEADER: String = ""
  2393. var S_ENTRY: String = ""
  2394. var S_KEYVAL: String = ""
  2395. var S_ARRAY: String = ""
  2396. static let TYPE_SQLITE_ONLY = "1"
  2397. static let TYPE_ALL = "2"
  2398. static let TYPE_NEED_ACK = "3"
  2399. let ERRCOD = "A97"
  2400. let MEDIA_LENGTH = "ML"
  2401. let FILE_SIZE = "A53C"
  2402. let IMEI = "Bb"
  2403. let VERCOD = "Bd"
  2404. func getCLMUserId() -> String {
  2405. guard let me: String = SecureUserDefaultsSS.shared.value(forKey: "me") else {
  2406. return ""
  2407. }
  2408. return me
  2409. }
  2410. init() {
  2411. mVersion = "1.0.116"
  2412. mBodies[IMEI] = getCLMUserId()
  2413. mBodies[VERCOD] = "2.2.177"
  2414. }
  2415. init(data : String) {
  2416. _ = unpack(data: data)
  2417. }
  2418. init(type: String, version: String, code: String,status: String, pin: String, l_pin: String, bodies:[String: String], media: [UInt8]) {
  2419. mType = type
  2420. mVersion = version
  2421. mCode = code
  2422. mStatus = status
  2423. mPIN = pin
  2424. mL_PIN = l_pin
  2425. mBodies = bodies
  2426. mMedia = media
  2427. mBodies[IMEI] = getCLMUserId()
  2428. mBodies[VERCOD] = "2.2.177"
  2429. }
  2430. func clone(p_tmessage:TMessageSS) -> TMessageSS {
  2431. return TMessageSS(
  2432. type: p_tmessage.mType,
  2433. version: p_tmessage.mVersion,
  2434. code: p_tmessage.mCode,
  2435. status: p_tmessage.mStatus,
  2436. pin: p_tmessage.mPIN,
  2437. l_pin: p_tmessage.mL_PIN,
  2438. bodies: p_tmessage.mBodies,
  2439. media: p_tmessage.mMedia
  2440. )
  2441. }
  2442. func setMedia(media: [UInt8]) {
  2443. mMedia = media
  2444. mBodies[MEDIA_LENGTH] = String(media.count)
  2445. }
  2446. func getCode() -> String {
  2447. return mCode
  2448. }
  2449. func getStatus() -> String {
  2450. return mStatus
  2451. }
  2452. func getPIN() -> String {
  2453. return mPIN
  2454. }
  2455. func getType() -> String {
  2456. return mType
  2457. }
  2458. func getL_PIN() -> String {
  2459. return mL_PIN
  2460. }
  2461. func getMedia() -> [UInt8] {
  2462. return mMedia
  2463. }
  2464. func getBody(key : String) -> String {
  2465. if let data = mBodies[key] {
  2466. return data
  2467. }
  2468. else {
  2469. return ""
  2470. }
  2471. }
  2472. func getBody(key : String, default_value: String) -> String {
  2473. if ((mBodies[key] == nil)) {
  2474. return default_value
  2475. } else if mBodies[key] == "null" {
  2476. return default_value
  2477. } else {
  2478. return mBodies[key]!
  2479. }
  2480. }
  2481. func getBodyAsInteger(key : String, default_value: Int) -> Int {
  2482. if ((mBodies[key] == nil)) {
  2483. return default_value
  2484. } else if mBodies[key] == "null" {
  2485. return default_value
  2486. } else {
  2487. return Int(mBodies[key]!)!
  2488. }
  2489. }
  2490. func getBodyAsLong(key : String, default_value: CLong) -> CLong {
  2491. if let body = mBodies[key] {
  2492. if (body == "null") {
  2493. return default_value
  2494. }
  2495. if (body == "nil") {
  2496. return default_value
  2497. }
  2498. return (body as NSString).integerValue
  2499. }
  2500. else {
  2501. return default_value
  2502. }
  2503. }
  2504. func pack() -> String {
  2505. if (S_HEADER.isEmpty) { S_HEADER.append(Character(C_HEADER)) }
  2506. var data = ""
  2507. data.append(mType)
  2508. data.append(Character(C_HEADER))
  2509. data.append(mVersion)
  2510. data.append(Character(C_HEADER))
  2511. data.append(mCode)
  2512. data.append(Character(C_HEADER))
  2513. data.append(mStatus)
  2514. data.append(Character(C_HEADER))
  2515. data.append(mPIN)
  2516. data.append(Character(C_HEADER))
  2517. data.append(mL_PIN)
  2518. data.append(Character(C_HEADER))
  2519. data.append(toString(body: mBodies))
  2520. data.append(Character(C_HEADER))
  2521. if let media = String(data: Data(getMedia()), encoding: .windowsCP1250) {
  2522. data.append(media)
  2523. }
  2524. return data
  2525. }
  2526. func toBytes() -> [UInt8] {
  2527. let data:String = pack()
  2528. var result: [UInt8] = Array(data.utf8)
  2529. if (!getMedia().isEmpty) {
  2530. for index in 0...getMedia().count - 1 {
  2531. result.append(getMedia()[index])
  2532. }
  2533. }
  2534. return result
  2535. }
  2536. private func toString(body : [String: String]) -> String {
  2537. if (S_ENTRY.isEmpty) { S_ENTRY.append(Character(C_ENTRY)) }
  2538. if (S_KEYVAL.isEmpty) { S_KEYVAL.append(Character(C_KEYVAL)) }
  2539. var result = ""
  2540. for (key, value) in body {
  2541. result += key + S_KEYVAL + value + S_ENTRY
  2542. }
  2543. if (!result.isEmpty) {
  2544. result = String(result.prefix(result.count - 1))
  2545. }
  2546. return result
  2547. }
  2548. private func toMediaBytes(image: String) -> [UInt8] {
  2549. if (image == "null") {
  2550. return [UInt8]()
  2551. }
  2552. if let data = NSData(base64Encoded: image, options: .ignoreUnknownCharacters) {
  2553. var buffer = [UInt8](repeating: 0, count: data.length)
  2554. data.getBytes(&buffer, length: data.length)
  2555. return buffer
  2556. }
  2557. return [UInt8]()
  2558. }
  2559. func unpack(data: String) -> Bool {
  2560. var result = false
  2561. if (S_HEADER.isEmpty) { S_HEADER.append(Character(C_HEADER)) }
  2562. let headers = data.split(separator: Character(C_HEADER), maxSplits: 8, omittingEmptySubsequences: false)
  2563. if (headers.count == 8) {
  2564. mType = String(headers[0])
  2565. mVersion = String(headers[1])
  2566. mCode = String(headers[2])
  2567. mStatus = String(headers[3])
  2568. mPIN = String(headers[4])
  2569. mL_PIN = String(headers[5])
  2570. mBodies = toBodies(data: String(headers[6]))
  2571. mMedia = toMediaBytes(image: String(headers[7]))
  2572. result = true
  2573. }
  2574. return result
  2575. }
  2576. func unpack(bytes_data: [UInt8]) -> Bool {
  2577. var result = false
  2578. let data = getData(bytes_data: bytes_data)
  2579. let headers = data.split(separator: Character(C_HEADER), maxSplits: 8, omittingEmptySubsequences: false)
  2580. if (headers.count >= 8) {
  2581. mType = String(headers[0])
  2582. mVersion = String(headers[1])
  2583. mCode = String(headers[2])
  2584. mStatus = String(headers[3])
  2585. mPIN = String(headers[4])
  2586. mL_PIN = String(headers[5])
  2587. mBodies = toBodies(data: String(headers[6]))
  2588. mMedia = getMedia(bytes_data: bytes_data)
  2589. result = true
  2590. }
  2591. else {
  2592. }
  2593. return result
  2594. }
  2595. private func toBodies(data: String) -> [String: String] {
  2596. var cvalues = [String: String]()
  2597. if (data.isEmpty || data == "") {
  2598. return cvalues
  2599. }
  2600. if (S_ENTRY.isEmpty) { S_ENTRY.append(Character(C_ENTRY)) }
  2601. if (S_KEYVAL.isEmpty) { S_KEYVAL.append(Character(C_KEYVAL)) }
  2602. let elements = data.split(separator: Character(C_ENTRY), omittingEmptySubsequences: false)
  2603. for element in elements {
  2604. let keyval = element.split(separator: Character(C_KEYVAL), omittingEmptySubsequences: false)
  2605. cvalues[String(keyval[0])] = String(keyval[1])
  2606. }
  2607. return cvalues
  2608. }
  2609. private func getData(bytes_data : [UInt8]) -> String {
  2610. var result = ""
  2611. if (S_HEADER.isEmpty) { S_HEADER.append(Character(C_HEADER)) }
  2612. var iLength = 0
  2613. for bData in bytes_data {
  2614. let chr = Character(UnicodeScalar(bData))
  2615. if (chr == Character(C_HEADER)) {
  2616. iLength = iLength + 1
  2617. if (iLength == 8) {
  2618. break
  2619. }
  2620. }
  2621. result.append(chr)
  2622. }
  2623. return result
  2624. }
  2625. private func getMedia(bytes_data: [UInt8]) -> [UInt8] {
  2626. var result:[UInt8] = [UInt8]()
  2627. if bytes_data.count > 0 {
  2628. var ml = getBodyAsInteger(key: MEDIA_LENGTH, default_value: 0)
  2629. if ml == 0 {
  2630. ml = getBodyAsInteger(key: FILE_SIZE, default_value: 0)
  2631. }
  2632. if ml > 0 {
  2633. let start = bytes_data.count - ml
  2634. for index in start...bytes_data.count - 1 {
  2635. result.append(bytes_data[index])
  2636. }
  2637. }
  2638. }
  2639. return result
  2640. }
  2641. func toLogString() -> String {
  2642. var result = ""
  2643. result += ("[" + mType + "]")
  2644. result += ("[" + mVersion + "]")
  2645. result += ("[" + mCode + "]")
  2646. result += ("[" + mStatus + "]")
  2647. result += ("[" + mPIN + "]")
  2648. result += ("[" + mL_PIN + "]")
  2649. result += ("[" + toBodyLogString() + "]")
  2650. result += ("[" + String(mMedia.count) + "]")
  2651. return result
  2652. }
  2653. private func toBodyLogString() -> String {
  2654. if (S_ENTRY.isEmpty) { S_ENTRY.append(Character(C_ENTRY)) }
  2655. if (S_KEYVAL.isEmpty) { S_KEYVAL.append(Character(C_KEYVAL)) }
  2656. var result = ""
  2657. for (key, value) in mBodies {
  2658. result += "{" + key + "=" + value + "}"
  2659. }
  2660. return result
  2661. }
  2662. func isOk() -> Bool {
  2663. return getBody(key: ERRCOD, default_value: "99") == "00"
  2664. }
  2665. }
  2666. private class CoreMessage_TMessageUtil {
  2667. private static var mTID = NSDate().timeIntervalSince1970 * 1000
  2668. static func getTID() -> String {
  2669. mTID = Double(Int(mTID) + Int(1))
  2670. return String(Int(mTID))
  2671. }
  2672. static func getString(json: Any, key: String) -> String {
  2673. return getString(json: json, key: key, def: "")
  2674. }
  2675. static func getString(json: Any, key: String, def: String) -> String {
  2676. if let dict = json as? [String: Any], let value = dict[key] as? String {
  2677. if !value.isEmpty {
  2678. return value
  2679. }
  2680. }
  2681. return def
  2682. }
  2683. static func getInt(json: Any, key: String, def: Int) -> Int {
  2684. if let dict = json as? [String: Any], let value = dict[key] as? Int {
  2685. return value
  2686. }
  2687. return def
  2688. }
  2689. static func getIntAsString(json: Any, key: String, def: Int) -> String {
  2690. return String(getInt(json: json, key: key, def: def))
  2691. }
  2692. static func getLong(json: Any, key: String, def: CLong) -> CLong {
  2693. if let dict = json as? [String: Any], let value = dict[key] as? CLong {
  2694. return value
  2695. }
  2696. return def
  2697. }
  2698. }
  2699. private class SSLibAlertController: UIAlertController {
  2700. override func viewWillAppear(_ animated: Bool) {
  2701. super.viewWillAppear(animated)
  2702. // Customize the title's font
  2703. let titleFont = UIFont.boldSystemFont(ofSize: 16)
  2704. let titleAttributes = [NSAttributedString.Key.font: titleFont]
  2705. setValue(NSAttributedString(string: self.title ?? "", attributes: titleAttributes), forKey: "attributedTitle")
  2706. // Change the font for the message
  2707. let messageFont = UIFont.systemFont(ofSize: 14)
  2708. let messageAttributes = [NSAttributedString.Key.font: messageFont]
  2709. setValue(NSAttributedString(string: self.message ?? "", attributes: messageAttributes), forKey: "attributedMessage")
  2710. for i in self.actions {
  2711. let attributedText = NSAttributedString(string: i.title ?? "", attributes: [NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)])
  2712. guard let label = (i.value(forKey: "__representer") as AnyObject).value(forKey: "label") as? UILabel else { return }
  2713. label.attributedText = attributedText
  2714. }
  2715. }
  2716. }
  2717. private class SecureUserDefaultsSS {
  2718. static let shared = SecureUserDefaultsSS()
  2719. private let defaults: UserDefaults
  2720. private let prefsKeyAlias = "_iosx_security_master_key_easysoft_"
  2721. // Initialization with a SymmetricKey
  2722. init(defaults: UserDefaults = .standard) {
  2723. self.defaults = defaults
  2724. do {
  2725. try generateAndStorePrefsKey()
  2726. } catch {
  2727. }
  2728. }
  2729. func generateAndStorePrefsKey() throws {
  2730. if try isKeyExists(keyAliasCode: prefsKeyAlias) {
  2731. return
  2732. }
  2733. let key = SymmetricKey(size: .bits256)
  2734. let keyData = key.withUnsafeBytes { Data($0) }
  2735. let query: [String: Any] = [
  2736. kSecClass as String: kSecClassKey,
  2737. kSecAttrApplicationTag as String: prefsKeyAlias,
  2738. kSecValueData as String: keyData,
  2739. kSecAttrAccessible as String: kSecAttrAccessibleAfterFirstUnlock
  2740. ]
  2741. SecItemDelete(query as CFDictionary) // Remove if it exists
  2742. let status = SecItemAdd(query as CFDictionary, nil)
  2743. guard status == errSecSuccess else {
  2744. throw NSError(domain: "KeychainError", code: Int(status), userInfo: nil)
  2745. }
  2746. }
  2747. func isKeyExists(keyAliasCode: String) throws -> Bool {
  2748. let query: [String: Any] = [
  2749. kSecClass as String: kSecClassKey,
  2750. kSecAttrApplicationTag as String: keyAliasCode,
  2751. kSecReturnData as String: false // We only check existence, not retrieve data
  2752. ]
  2753. let status = SecItemCopyMatching(query as CFDictionary, nil)
  2754. if status == errSecItemNotFound {
  2755. return false
  2756. } else if status == errSecSuccess {
  2757. return true
  2758. } else {
  2759. throw NSError(domain: "KeychainError", code: Int(status), userInfo: nil)
  2760. }
  2761. }
  2762. func getPrefsKey() throws -> SymmetricKey {
  2763. let query: [String: Any] = [
  2764. kSecClass as String: kSecClassKey,
  2765. kSecAttrApplicationTag as String: prefsKeyAlias,
  2766. kSecReturnData as String: true
  2767. ]
  2768. var item: CFTypeRef?
  2769. let status = SecItemCopyMatching(query as CFDictionary, &item)
  2770. guard status == errSecSuccess else {
  2771. throw NSError(domain: "KeychainError", code: Int(status), userInfo: nil)
  2772. }
  2773. guard let keyData = item as? Data else {
  2774. throw NSError(domain: "KeyRetrievalError", code: -1, userInfo: nil)
  2775. }
  2776. return SymmetricKey(data: keyData)
  2777. }
  2778. func encrypt(data: Data) throws -> Data {
  2779. let key = try getPrefsKey()
  2780. let sealedBox = try AES.GCM.seal(data, using: key)
  2781. return sealedBox.combined!
  2782. }
  2783. func decrypt(data: Data) throws -> Data {
  2784. let key = try getPrefsKey()
  2785. let sealedBox = try AES.GCM.SealedBox(combined: data)
  2786. return try AES.GCM.open(sealedBox, using: key)
  2787. }
  2788. func set<T: Codable>(_ value: T, forKey key: String) {
  2789. let encoder = JSONEncoder()
  2790. guard let encodedData = try? encoder.encode(value),
  2791. let encryptedData = try? encrypt(data: encodedData) else {
  2792. return
  2793. }
  2794. defaults.set(encryptedData, forKey: key)
  2795. }
  2796. // Retrieve a value
  2797. func value<T: Codable>(forKey key: String) -> T? {
  2798. guard let encryptedData = defaults.data(forKey: key),
  2799. let decryptedData = try? decrypt(data: encryptedData) else {
  2800. return nil
  2801. }
  2802. let decoder = JSONDecoder()
  2803. return try? decoder.decode(T.self, from: decryptedData)
  2804. }
  2805. // Remove a value
  2806. func removeValue(forKey key: String) {
  2807. defaults.removeObject(forKey: key)
  2808. }
  2809. func sync() {
  2810. defaults.synchronize()
  2811. }
  2812. }
  2813. class CallBackSS : CallBack {
  2814. var sID: String = ""
  2815. func connectionStateChanged(sUserID: String!, sDeviceID: String!, bConState: Bool!, nConType: Int!, nConSubType: Int!, nCLMConStat: UInt8!) {
  2816. }
  2817. func gpsStateChanged(nState: Int!) {
  2818. }
  2819. func sleepStateChanged(bState: Bool!) {
  2820. }
  2821. func callStateChanged(nState: Int!, sMessage: String!) -> Int {
  2822. return 1
  2823. }
  2824. func bcastStateChanged(nState: Int!, sMessage: String!) -> Int {
  2825. return 1
  2826. }
  2827. func sshareStateChanged(nState: Int!, sMessage: String!) -> Int {
  2828. return 1
  2829. }
  2830. func incomingData(sPacketID: String!, oData: AnyObject!) throws {
  2831. }
  2832. func lateResponse(sPacketID: String!, sResponse: String!) throws {
  2833. }
  2834. func asycnACKReceived(sPacketID: String!) throws {
  2835. }
  2836. func locationUpdated(lTime: Int64!, sLocationInfo: String!) {
  2837. }
  2838. func resetDB() {
  2839. }
  2840. }