SecurityShield.swift 103 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354
  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. public class SecurityShield: NSObject {
  15. static var dispatch: DispatchGroup?
  16. public static func check(appName: String, apiKey: String, activity: UIViewController) {
  17. Preference.setAppId(value: appName)
  18. Preference.setAccount(value: apiKey)
  19. pull()
  20. }
  21. private static func pull() {
  22. let me: String! = SecureUserDefaultsSS.shared.value(forKey: "me")!
  23. let tmessage = TMessageSS()
  24. tmessage.mCode = "SS01"
  25. tmessage.mStatus = CoreMessage_TMessageUtil.getTID()
  26. tmessage.mPIN = me
  27. tmessage.mBodies["Api"] = Preference.getAccount()
  28. tmessage.mBodies["AAN"] = Preference.getAppId()
  29. tmessage.mBodies["type"] = "0"
  30. DispatchQueue.global().async{
  31. if let response = Service.writeSync(message: tmessage) {
  32. if response.isOk() {
  33. let dataResp = response.getBody(key: "A112")
  34. print("dataResp = \(dataResp)")
  35. Process.check(dataSS: dataResp)
  36. } else {
  37. Process.check(dataSS: "")
  38. }
  39. } else {
  40. Process.check(dataSS: "")
  41. }
  42. }
  43. }
  44. private static func showToast(message : String, font: UIFont = UIFont.systemFont(ofSize: 12, weight: .medium), controller: UIViewController) {
  45. let toastContainer = UIView(frame: CGRect())
  46. toastContainer.backgroundColor = controller.traitCollection.userInterfaceStyle == .dark ? .white.withAlphaComponent(0.6) : UIColor.mainColorSS.withAlphaComponent(0.6)
  47. toastContainer.alpha = 0.0
  48. toastContainer.layer.cornerRadius = 25;
  49. toastContainer.clipsToBounds = true
  50. let toastLabel = UILabel(frame: CGRect())
  51. toastLabel.textColor = controller.traitCollection.userInterfaceStyle == .dark ? .blackDarkModeSS : UIColor.white
  52. toastLabel.textAlignment = .center;
  53. toastLabel.font = font
  54. toastLabel.text = message
  55. toastLabel.clipsToBounds = true
  56. toastLabel.numberOfLines = 0
  57. toastContainer.addSubview(toastLabel)
  58. controller.view.addSubview(toastContainer)
  59. controller.view.bringSubviewToFront(toastContainer)
  60. toastLabel.translatesAutoresizingMaskIntoConstraints = false
  61. toastContainer.translatesAutoresizingMaskIntoConstraints = false
  62. let a1 = NSLayoutConstraint(item: toastLabel, attribute: .leading, relatedBy: .equal, toItem: toastContainer, attribute: .leading, multiplier: 1, constant: 15)
  63. let a2 = NSLayoutConstraint(item: toastLabel, attribute: .trailing, relatedBy: .equal, toItem: toastContainer, attribute: .trailing, multiplier: 1, constant: -15)
  64. let a3 = NSLayoutConstraint(item: toastLabel, attribute: .bottom, relatedBy: .equal, toItem: toastContainer, attribute: .bottom, multiplier: 1, constant: -15)
  65. let a4 = NSLayoutConstraint(item: toastLabel, attribute: .top, relatedBy: .equal, toItem: toastContainer, attribute: .top, multiplier: 1, constant: 15)
  66. toastContainer.addConstraints([a1, a2, a3, a4])
  67. let c1 = NSLayoutConstraint(item: toastContainer, attribute: .leading, relatedBy: .equal, toItem: controller.view, attribute: .leading, multiplier: 1, constant: 65)
  68. let c2 = NSLayoutConstraint(item: toastContainer, attribute: .trailing, relatedBy: .equal, toItem: controller.view, attribute: .trailing, multiplier: 1, constant: -65)
  69. let c3 = NSLayoutConstraint(item: toastContainer, attribute: .bottom, relatedBy: .equal, toItem: controller.view, attribute: .bottom, multiplier: 1, constant: -75)
  70. controller.view.addConstraints([c1, c2, c3])
  71. UIView.animate(withDuration: 0.5, delay: 0.0, options: .curveEaseIn, animations: {
  72. toastContainer.alpha = 1.0
  73. }, completion: { _ in
  74. UIView.animate(withDuration: 0.5, delay: 1.5, options: .curveEaseOut, animations: {
  75. toastContainer.alpha = 0.0
  76. }, completion: {_ in
  77. toastContainer.removeFromSuperview()
  78. })
  79. })
  80. }
  81. }
  82. private class Process: NSObject {
  83. static func check(dataSS : String) {
  84. print("dataSS = \(dataSS)")
  85. if !dataSS.isEmpty {
  86. if let jsonArray = try? JSONSerialization.jsonObject(with: dataSS.data(using: String.Encoding.utf8)!, options: JSONSerialization.ReadingOptions()) as? [AnyObject] {
  87. do {
  88. for jsonData in jsonArray {
  89. if jsonData["check_keylogger"]! != nil {
  90. Preference.setPreventKeylogger(value: jsonData["check_keylogger"]! as! String == "1")
  91. Preference.setPreventKeyloggerAction(value: jsonData["action"]! as! String)
  92. Preference.setKeyloggerAlertTitle(value: jsonData["alert_title"]! as! String)
  93. Preference.setKeyloggerAlertMessage(value: jsonData["alert_message"]! as! String)
  94. }
  95. if jsonData["check_screen_capture"]! != nil {
  96. Preference.setPreventScreenCapture(value: jsonData["check_screen_capture"]! as! String == "1")
  97. Preference.setPreventScreenCaptureAction(value: jsonData["action"]! as! String)
  98. Preference.setCheckScreenCaptureAlertTitle(value: jsonData["alert_title"]! as! String)
  99. Preference.setScreenCaptureAlertMessage(value: jsonData["alert_message"]! as! String)
  100. }
  101. if jsonData["check_emulator"]! != nil {
  102. Preference.setCheckEmulator(value: jsonData["check_emulator"]! as! String == "1")
  103. Preference.setCheckEmulatorAction(value: jsonData["action"]! as! String)
  104. Preference.setCheckEmulatorAlertTitle(value: jsonData["alert_title"]! as! String)
  105. Preference.setCheckEmulatorAlertMessage(value: jsonData["alert_message"]! as! String)
  106. }
  107. if jsonData["check_rooted_device"]! != nil {
  108. Preference.setCheckRooted(value: jsonData["check_rooted_device"]! as! String == "1")
  109. Preference.setCheckRootedAction(value: jsonData["action"]! as! String)
  110. Preference.setCheckRootedAlertTitle(value: jsonData["alert_title"]! as! String)
  111. Preference.setCheckRootedAlertMessage(value: jsonData["alert_message"]! as! String)
  112. }
  113. if jsonData["check_outdated_os"]! != nil {
  114. Preference.setCheckOutdatedOs(value: jsonData["check_outdated_os"]! as! String == "1")
  115. Preference.setCheckOutdatedOsAction(value: jsonData["action"]! as! String)
  116. Preference.setCheckOutdatedOsAlertTitle(value: jsonData["alert_title"]! as! String)
  117. Preference.setCheckOutdatedOsAlertMessage(value: jsonData["alert_message"]! as! String)
  118. }
  119. if jsonData["minimum_ios_version"]! != nil {
  120. Preference.setMinimumOsVersion(value: jsonData["minimum_ios_version"]! as! String)
  121. }
  122. if jsonData["check_sum"]! != nil {
  123. Preference.setCheckTempering(value: jsonData["check_sum"]! as! String == "1")
  124. Preference.setCheckTemperingAction(value: jsonData["action"]! as! String)
  125. Preference.setCheckTemperingAlertTitle(value: jsonData["alert_title"]! as! String)
  126. Preference.setCheckTemperingAlertMessage(value: jsonData["alert_message"]! as! String)
  127. }
  128. if jsonData["check_usb_debugging"]! != nil {
  129. Preference.setCheckDebugging(value: jsonData["check_usb_debugging"]! as! String == "1")
  130. Preference.setCheckDebuggingAction(value: jsonData["action"]! as! String)
  131. Preference.setCheckDebuggingAlertTitle(value: jsonData["alert_title"]! as! String)
  132. Preference.setCheckDebuggingAlertMessage(value: jsonData["alert_message"]! as! String)
  133. }
  134. if jsonData["check_screen_casting"]! != nil {
  135. Preference.setCheckScreenCasting(value: jsonData["check_screen_casting"]! as! String == "1")
  136. Preference.setCheckScreenCastingAction(value: jsonData["action"]! as! String)
  137. Preference.setCheckScreenCastingAlertTitle(value: jsonData["alert_title"]! as! String)
  138. Preference.setCheckScreenCastingAlertMessage(value: jsonData["alert_message"]! as! String)
  139. }
  140. if jsonData["check_screen_overlay"]! != nil {
  141. Preference.setCheckScreenOverlay(value: jsonData["check_screen_overlay"]! as! String == "1")
  142. Preference.setCheckScreenOverlayAction(value: jsonData["action"]! as! String)
  143. Preference.setCheckScreenOverlayAlertTitle(value: jsonData["alert_title"]! as! String)
  144. Preference.setCheckScreenOverlayAlertMessage(value: jsonData["alert_message"]! as! String)
  145. }
  146. if jsonData["check_call_forwarding"]! != nil {
  147. Preference.setCheckCallForward(value: jsonData["check_call_forwarding"]! as! String == "1")
  148. Preference.setCheckCallForwardAction(value: jsonData["action"]! as! String)
  149. Preference.setCheckCallForwardAlertTitle(value: jsonData["alert_title"]! as! String)
  150. Preference.setCheckCallForwardAlertMessage(value: jsonData["alert_message"]! as! String)
  151. }
  152. if jsonData["multiple_login"]! != nil {
  153. Preference.setCheckMultipleLogin(value: jsonData["multiple_login"]! as! String == "1")
  154. Preference.setCheckMultipleLoginAction(value: jsonData["action"]! as! String)
  155. Preference.setCheckMultipleLoginAlertTitle(value: jsonData["alert_title"]! as! String)
  156. Preference.setCheckMultipleLoginAlertMessage(value: jsonData["alert_message"]! as! String)
  157. }
  158. if jsonData["check_sim_swap"]! != nil {
  159. Preference.setCheckSimSwap(value: jsonData["check_sim_swap"]! as! String == "1")
  160. Preference.setCheckSimSwapAction(value: jsonData["action"]! as! String)
  161. Preference.setCheckSimSwapAlertTitle(value: jsonData["alert_title"]! as! String)
  162. Preference.setCheckSimSwapAlertMessage(value: jsonData["alert_message"]! as! String)
  163. }
  164. if jsonData["check_geovelocity"]! != nil {
  165. Preference.setCheckGeoVelocity(value: jsonData["check_geovelocity"]! as! String == "1")
  166. Preference.setCheckGeoVelocityAction(value: jsonData["action"]! as! String)
  167. Preference.setCheckGeoVelocityAlertTitle(value: jsonData["alert_title"]! as! String)
  168. Preference.setCheckGeoVelocityAlertMessage(value: jsonData["alert_message"]! as! String)
  169. }
  170. if jsonData["behavioral_analysis"]! != nil {
  171. Preference.setCheckBehaviourAnalysis(value: jsonData["behavioral_analysis"]! as! String == "1")
  172. Preference.setCheckBehaviourAnalysisAction(value: jsonData["action"]! as! String)
  173. Preference.setCheckBehaviourAnalysisAlertTitle(value: jsonData["alert_title"]! as! String)
  174. Preference.setCheckBehaviourAnalysisAlertMessage(value: jsonData["alert_message"]! as! String)
  175. }
  176. }
  177. if Preference.getPreventKeylogger() || Preference.getPreventScreenCapture() {
  178. DispatchQueue.main.async(execute: {
  179. let alert = SSLibAlertController(title: Preference.getPreventKeylogger() ? Preference.getKeyloggerAlertTitle() : Preference.getCheckScreenCaptureAlertTitle(), message: Preference.getPreventKeylogger() ? Preference.getKeyloggerAlertMessage() : Preference.getScreenCaptureAlertMessage(), preferredStyle: .alert)
  180. if Preference.getPreventKeyloggerAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE || Preference.getPreventScreenCaptureAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  181. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: {_ in
  182. NotificationCenter.default.addObserver(self, selector: #selector(preventScreenRecording), name: UIScreen.capturedDidChangeNotification, object: nil)
  183. DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
  184. if let window = UIApplication.shared.windows.first {
  185. makeSecure(window: window)
  186. }
  187. })
  188. }))
  189. if UIApplication.shared.visibleViewController?.navigationController != nil {
  190. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  191. } else {
  192. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  193. }
  194. } else {
  195. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  196. exit(-101)
  197. }))
  198. if UIApplication.shared.visibleViewController?.navigationController != nil {
  199. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  200. } else {
  201. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  202. }
  203. }
  204. })
  205. } else {
  206. if screen != nil {
  207. screen?.removeFromSuperview()
  208. }
  209. }
  210. subCheck(1)
  211. } catch {
  212. }
  213. }
  214. } else {
  215. subCheck(1)
  216. }
  217. }
  218. private static var screen: UIView!
  219. @objc static func preventScreenRecording() {
  220. let isCaptured = UIScreen.main.isCaptured
  221. //print("isCaptured: \(isCaptured)")
  222. if isCaptured {
  223. blurScreen()
  224. }
  225. else {
  226. removeBlurScreen()
  227. }
  228. }
  229. private static func blurScreen(style: UIBlurEffect.Style = UIBlurEffect.Style.regular) {
  230. screen = UIScreen.main.snapshotView(afterScreenUpdates: false)
  231. let blurEffect = UIBlurEffect(style: style)
  232. let blurBackground = UIVisualEffectView(effect: blurEffect)
  233. screen.addSubview(blurBackground)
  234. blurBackground.frame = (screen.frame)
  235. if let window = UIApplication.shared.windows.first {
  236. window.addSubview(screen)
  237. } else {
  238. //print("window nil")
  239. }
  240. }
  241. private static func removeBlurScreen() {
  242. screen?.removeFromSuperview()
  243. }
  244. private static func makeSecure(window: UIWindow) {
  245. let field = UITextField()
  246. let view = UIView(frame: CGRect(x: 0, y: 0, width: field.frame.self.width, height: field.frame.self.height))
  247. let image = UIImageView(image: UIImage.imageWithColorSS(color: .black, size: CGSize(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)))
  248. image.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
  249. field.isSecureTextEntry = true
  250. window.addSubview(field)
  251. view.addSubview(image)
  252. window.layer.superlayer?.addSublayer(field.layer)
  253. field.layer.sublayers?.last!.addSublayer(window.layer)
  254. field.leftView = view
  255. field.leftViewMode = .always
  256. }
  257. static func subCheck(_ typeSecurity : Int) {
  258. if typeSecurity == 1 {
  259. if checkEmulator() {
  260. return
  261. }
  262. subCheck(2)
  263. } else if typeSecurity == 2 {
  264. if checkRootedDevice() {
  265. return
  266. }
  267. subCheck(3)
  268. } else if typeSecurity == 3 {
  269. if checkOutdatedOS() {
  270. return
  271. }
  272. subCheck(4)
  273. } else if typeSecurity == 4 {
  274. if checkTempering() {
  275. return
  276. }
  277. subCheck(5)
  278. } else if typeSecurity == 5 {
  279. if checkDebugging() {
  280. return
  281. }
  282. subCheck(6)
  283. } else if typeSecurity == 6 {
  284. NotificationCenter.default.addObserver(self, selector: #selector(screenDidConnect), name: UIScreen.didConnectNotification, object: nil)
  285. NotificationCenter.default.addObserver(self, selector: #selector(screenDidDisconnect), name: UIScreen.didDisconnectNotification, object: nil)
  286. if checkScreenCasting() {
  287. return
  288. }
  289. subCheck(7)
  290. } else if typeSecurity == 7 {
  291. if checkScreenOverlay() {
  292. return
  293. }
  294. subCheck(8)
  295. } else if typeSecurity == 8 {
  296. if checkCallForward() {
  297. return
  298. }
  299. subCheck(9)
  300. } else if typeSecurity == 9 {
  301. if checkMultipleLogin() {
  302. return
  303. }
  304. subCheck(10)
  305. } else if typeSecurity == 10 {
  306. if checkSimSwap() {
  307. return
  308. }
  309. subCheck(11)
  310. } else if typeSecurity == 11 {
  311. if checkGeovelocity() {
  312. return
  313. }
  314. subCheck(12)
  315. } else if typeSecurity == 11 {
  316. if checkBehaviourAnalysis() {
  317. return
  318. }
  319. subCheck(12)
  320. }
  321. }
  322. static func checkEmulator() -> Bool {
  323. if Preference.getCheckEmulator() && isEmulator() {
  324. DispatchQueue.main.async(execute: {
  325. let alert = SSLibAlertController(title: Preference.getCheckEmulatorAlertTitle(), message: Preference.getCheckEmulatorAlertMessage(), preferredStyle: .alert)
  326. if Preference.getCheckEmulatorAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  327. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  328. if UIApplication.shared.visibleViewController?.navigationController != nil {
  329. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  330. } else {
  331. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  332. }
  333. } else {
  334. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  335. exit(-101)
  336. }))
  337. if UIApplication.shared.visibleViewController?.navigationController != nil {
  338. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  339. } else {
  340. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  341. }
  342. }
  343. })
  344. return true
  345. }
  346. return false
  347. }
  348. static func checkRootedDevice() -> Bool {
  349. if Preference.getCheckRooted() && isRooted() {
  350. DispatchQueue.main.async(execute: {
  351. let alert = SSLibAlertController(title: Preference.getCheckRootedAlertTitle(), message: Preference.getCheckRootedAlertMessage(), preferredStyle: .alert)
  352. if Preference.getCheckRootedAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  353. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  354. if UIApplication.shared.visibleViewController?.navigationController != nil {
  355. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  356. } else {
  357. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  358. }
  359. } else {
  360. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  361. exit(-141)
  362. }))
  363. if UIApplication.shared.visibleViewController?.navigationController != nil {
  364. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  365. } else {
  366. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  367. }
  368. }
  369. })
  370. return true
  371. }
  372. return false
  373. }
  374. static func checkOutdatedOS() -> Bool {
  375. if Preference.getCheckOutdatedOs() {
  376. let requiredVersion = Preference.getMinimumOsVersion()
  377. let systemVersion = UIDevice.current.systemVersion
  378. let versionComponents = systemVersion.split(separator: ".").prefix(2)
  379. let versionString = versionComponents.joined(separator: ".")
  380. if let currentVersion = Double(versionString),
  381. let requiredVersionDouble = Double(requiredVersion) {
  382. if currentVersion < requiredVersionDouble {
  383. DispatchQueue.main.async(execute: {
  384. let alert = SSLibAlertController(title: Preference.getCheckRootedAlertTitle(), message: Preference.getCheckRootedAlertMessage(), preferredStyle: .alert)
  385. if Preference.getCheckOutdatedOsAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  386. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  387. if UIApplication.shared.visibleViewController?.navigationController != nil {
  388. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  389. } else {
  390. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  391. }
  392. } else {
  393. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  394. exit(-103)
  395. }))
  396. if UIApplication.shared.visibleViewController?.navigationController != nil {
  397. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  398. } else {
  399. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  400. }
  401. }
  402. })
  403. return true
  404. }
  405. } else {
  406. print("Failed to compare versions")
  407. }
  408. }
  409. return false
  410. }
  411. static func checkTempering() -> Bool {
  412. if Preference.getCheckTempering() && isTempering() {
  413. DispatchQueue.main.async(execute: {
  414. let alert = SSLibAlertController(title: Preference.getCheckTemperingAlertTitle(), message: Preference.getCheckTemperingAlertMessage(), preferredStyle: .alert)
  415. if Preference.getCheckTemperingAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  416. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  417. if UIApplication.shared.visibleViewController?.navigationController != nil {
  418. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  419. } else {
  420. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  421. }
  422. } else {
  423. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  424. exit(-141)
  425. }))
  426. if UIApplication.shared.visibleViewController?.navigationController != nil {
  427. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  428. } else {
  429. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  430. }
  431. }
  432. })
  433. return true
  434. }
  435. return false
  436. }
  437. static func checkDebugging() -> Bool {
  438. if Preference.getCheckDebugging() && isDebugging() {
  439. DispatchQueue.main.async(execute: {
  440. let alert = SSLibAlertController(title: Preference.getCheckDebuggingAlertTitle(), message: Preference.getCheckDebuggingAlertMessage(), preferredStyle: .alert)
  441. if Preference.getCheckDebuggingAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  442. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  443. if UIApplication.shared.visibleViewController?.navigationController != nil {
  444. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  445. } else {
  446. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  447. }
  448. } else {
  449. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  450. exit(-141)
  451. }))
  452. if UIApplication.shared.visibleViewController?.navigationController != nil {
  453. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  454. } else {
  455. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  456. }
  457. }
  458. })
  459. return true
  460. }
  461. return false
  462. }
  463. static func checkScreenCasting() -> Bool {
  464. if Preference.getCheckScreenCasting() && isScreenCasting() {
  465. DispatchQueue.main.async(execute: {
  466. let alert = SSLibAlertController(title: Preference.getCheckScreenCastingAlertTitle(), message: Preference.getCheckScreenCastingAlertMessage(), preferredStyle: .alert)
  467. if Preference.getCheckScreenCastingAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  468. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  469. if UIApplication.shared.visibleViewController?.navigationController != nil {
  470. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  471. } else {
  472. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  473. }
  474. } else {
  475. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  476. exit(-141)
  477. }))
  478. if UIApplication.shared.visibleViewController?.navigationController != nil {
  479. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  480. } else {
  481. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  482. }
  483. }
  484. })
  485. return true
  486. }
  487. return false
  488. }
  489. static func checkScreenOverlay() -> Bool {
  490. if Preference.getCheckScreenOverlay() && isScreenOverlay() {
  491. DispatchQueue.main.async(execute: {
  492. let alert = SSLibAlertController(title: Preference.getCheckScreenOverlayAlertTitle(), message: Preference.getCheckScreenOverlayAlertMessage(), preferredStyle: .alert)
  493. if Preference.getCheckScreenOverlayAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  494. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  495. if UIApplication.shared.visibleViewController?.navigationController != nil {
  496. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  497. } else {
  498. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  499. }
  500. } else {
  501. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  502. exit(-141)
  503. }))
  504. if UIApplication.shared.visibleViewController?.navigationController != nil {
  505. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  506. } else {
  507. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  508. }
  509. }
  510. })
  511. return true
  512. }
  513. return false
  514. }
  515. static func checkCallForward() -> Bool {
  516. if Preference.getCheckCallForward() && isCallForwarded() {
  517. DispatchQueue.main.async(execute: {
  518. let alert = SSLibAlertController(title: Preference.getCheckCallForwardAlertTitle(), message: Preference.getCheckCallForwardAlertMessage(), preferredStyle: .alert)
  519. if Preference.getCheckCallForwardAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  520. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  521. if UIApplication.shared.visibleViewController?.navigationController != nil {
  522. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  523. } else {
  524. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  525. }
  526. } else {
  527. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  528. exit(-141)
  529. }))
  530. if UIApplication.shared.visibleViewController?.navigationController != nil {
  531. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  532. } else {
  533. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  534. }
  535. }
  536. })
  537. return true
  538. }
  539. return false
  540. }
  541. static func checkMultipleLogin() -> Bool {
  542. if Preference.getCheckMultipleLogin() && isMultipleLogin() {
  543. DispatchQueue.main.async(execute: {
  544. let alert = SSLibAlertController(title: Preference.getCheckMultipleLoginAlertTitle(), message: Preference.getCheckMultipleLoginAlertMessage(), preferredStyle: .alert)
  545. if Preference.getCheckMultipleLoginAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  546. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  547. if UIApplication.shared.visibleViewController?.navigationController != nil {
  548. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  549. } else {
  550. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  551. }
  552. } else {
  553. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  554. exit(-141)
  555. }))
  556. if UIApplication.shared.visibleViewController?.navigationController != nil {
  557. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  558. } else {
  559. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  560. }
  561. }
  562. })
  563. return true
  564. }
  565. return false
  566. }
  567. static func checkSimSwap() -> Bool {
  568. if Preference.getCheckSimSwap() && isSimSwap() {
  569. DispatchQueue.main.async(execute: {
  570. let alert = SSLibAlertController(title: Preference.getCheckSimSwapAlertTitle(), message: Preference.getCheckSimSwapAlertMessage(), preferredStyle: .alert)
  571. if Preference.getCheckSimSwapAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  572. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  573. if UIApplication.shared.visibleViewController?.navigationController != nil {
  574. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  575. } else {
  576. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  577. }
  578. } else {
  579. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  580. exit(-141)
  581. }))
  582. if UIApplication.shared.visibleViewController?.navigationController != nil {
  583. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  584. } else {
  585. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  586. }
  587. }
  588. })
  589. return true
  590. }
  591. return false
  592. }
  593. static func checkGeovelocity() -> Bool {
  594. if Preference.getCheckGeoVelocity() && isGeovelocityDetected() {
  595. DispatchQueue.main.async(execute: {
  596. let alert = SSLibAlertController(title: Preference.getCheckGeoVelocityAlertTitle(), message: Preference.getCheckGeoVelocityAlertMessage(), preferredStyle: .alert)
  597. if Preference.getCheckGeoVelocityAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  598. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  599. if UIApplication.shared.visibleViewController?.navigationController != nil {
  600. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  601. } else {
  602. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  603. }
  604. } else {
  605. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  606. exit(-141)
  607. }))
  608. if UIApplication.shared.visibleViewController?.navigationController != nil {
  609. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  610. } else {
  611. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  612. }
  613. }
  614. })
  615. return true
  616. }
  617. return false
  618. }
  619. static func checkBehaviourAnalysis() -> Bool {
  620. if Preference.getCheckBehaviourAnalysis() && isSuspiciousBehavior() {
  621. DispatchQueue.main.async(execute: {
  622. let alert = SSLibAlertController(title: Preference.getCheckBehaviourAnalysisAlertTitle(), message: Preference.getCheckBehaviourAnalysisAlertMessage(), preferredStyle: .alert)
  623. if Preference.getCheckBehaviourAnalysisAction() == PreferencesKey.SECURITY_SHIELD_ALERT_CONTINUE {
  624. alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
  625. if UIApplication.shared.visibleViewController?.navigationController != nil {
  626. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  627. } else {
  628. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  629. }
  630. } else {
  631. alert.addAction(UIAlertAction(title: "Exit", style: UIAlertAction.Style.default, handler: {_ in
  632. exit(-141)
  633. }))
  634. if UIApplication.shared.visibleViewController?.navigationController != nil {
  635. UIApplication.shared.visibleViewController?.navigationController?.present(alert, animated: true, completion: nil)
  636. } else {
  637. UIApplication.shared.visibleViewController?.present(alert, animated: true, completion: nil)
  638. }
  639. }
  640. })
  641. return true
  642. }
  643. return false
  644. }
  645. private static func isEmulator() -> Bool {
  646. let deviceName = UIDevice.current.name
  647. if deviceName.contains("Simulator") {
  648. return true
  649. }
  650. let deviceModel = UIDevice.current.model
  651. if deviceModel.hasPrefix("Simulator") {
  652. return true
  653. }
  654. let systemName = UIDevice.current.systemName
  655. if systemName == "Simulator" {
  656. return true
  657. }
  658. #if targetEnvironment(simulator)
  659. return true
  660. #else
  661. #endif
  662. return false
  663. }
  664. private static func isRooted() -> Bool {
  665. #if arch(i386) || arch(x86_64)
  666. return false
  667. #else
  668. let fileManager = FileManager.default
  669. if fileManager.fileExists(atPath: "/Applications/Cydia.app") ||
  670. fileManager.fileExists(atPath: "/Library/MobileSubstrate/MobileSubstrate.dylib") ||
  671. fileManager.fileExists(atPath: "/bin/bash") ||
  672. fileManager.fileExists(atPath: "/usr/sbin/sshd") ||
  673. fileManager.fileExists(atPath: "/etc/apt") ||
  674. fileManager.fileExists(atPath: "/private/var/lib/apt/") ||
  675. fileManager.fileExists(atPath: "/Applications/FakeApp.app") {
  676. return true
  677. }
  678. #endif
  679. let filePath = "/private/var/mobile/Library/Preferences/com.apple.springboard.plist"
  680. if FileManager.default.fileExists(atPath: filePath) {
  681. return true
  682. }
  683. return false
  684. }
  685. private static func isTempering() -> Bool {
  686. return false
  687. }
  688. private static func isDebugging() -> Bool {
  689. var name: [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]
  690. var info = kinfo_proc()
  691. var size = MemoryLayout<kinfo_proc>.size
  692. let result = sysctl(&name, UInt32(name.count), &info, &size, nil, 0)
  693. if result == 0 {
  694. return (info.kp_proc.p_flag & P_TRACED) != 0
  695. } else {
  696. return false
  697. }
  698. }
  699. private static func isScreenCasting() -> Bool {
  700. return checkForExternalScreen()
  701. }
  702. @objc static func screenDidConnect(notification: Notification) {
  703. _ = checkScreenCasting()
  704. }
  705. // Called when a screen is disconnected
  706. @objc static func screenDidDisconnect(notification: Notification) {
  707. _ = checkScreenCasting()
  708. }
  709. private static func checkForExternalScreen() -> Bool {
  710. let screens = UIScreen.screens
  711. if screens.count > 1 {
  712. return true
  713. } else {
  714. return false
  715. }
  716. }
  717. private static func isScreenOverlay() -> Bool {
  718. return false
  719. }
  720. private static func isCallForwarded() -> Bool {
  721. return false
  722. }
  723. private static func isMultipleLogin() -> Bool {
  724. return false
  725. }
  726. private static func isSimSwap() -> Bool {
  727. guard let savedSimInfo: [String: [String: String]]? = SecureUserDefaultsSS.shared.value(forKey: "SavedSIMInfo") else {
  728. let simInfo = getSIMInfo()
  729. SecureUserDefaultsSS.shared.set(simInfo, forKey: "SavedSIMInfo")
  730. return false
  731. }
  732. let currentSimInfo = getSIMInfo()
  733. return savedSimInfo != currentSimInfo
  734. }
  735. private static func getSIMInfo() -> [String: [String: String]] {
  736. let networkInfo = CTTelephonyNetworkInfo()
  737. var simData: [String: [String: String]] = [:]
  738. if let carriers = networkInfo.serviceSubscriberCellularProviders {
  739. for (key, carrier) in carriers {
  740. let carrierName = carrier.carrierName ?? "Unknown"
  741. let mobileCountryCode = carrier.mobileCountryCode ?? "Unknown"
  742. let mobileNetworkCode = carrier.mobileNetworkCode ?? "Unknown"
  743. let isoCountryCode = carrier.isoCountryCode ?? "Unknown"
  744. simData[key] = [
  745. "carrierName": carrierName,
  746. "mobileCountryCode": mobileCountryCode,
  747. "mobileNetworkCode": mobileNetworkCode,
  748. "isoCountryCode": isoCountryCode
  749. ]
  750. }
  751. }
  752. return simData
  753. }
  754. private static func isGeovelocityDetected() -> Bool {
  755. return false
  756. }
  757. private static func isSuspiciousBehavior() -> Bool {
  758. return false
  759. }
  760. }
  761. private class Service {
  762. static func writeSync(message: TMessageSS, timeout: Int = 15 * 1000) -> TMessageSS? {
  763. do {
  764. print(">> SENDING MESSAGE >> ", message.toLogString())
  765. if let data = try API.sGetResponse(sRequest: message.pack(), lTimeout: timeout, bKeepTOResp: true) {
  766. let response = TMessageSS(data: data)
  767. print("<< RESPONSE MESSAGE << ", response.toLogString())
  768. return response
  769. }
  770. } catch {
  771. print(error)
  772. }
  773. return nil
  774. }
  775. }
  776. private class Preference {
  777. static func getAppId() -> String {
  778. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_USER_APP_ID) {
  779. return value
  780. }
  781. return ""
  782. }
  783. static func setAppId(value: String){
  784. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_USER_APP_ID)
  785. }
  786. static func getAccount() -> String {
  787. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_USER_ACCOUNT) {
  788. return value
  789. }
  790. return ""
  791. }
  792. static func setAccount(value: String){
  793. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_USER_ACCOUNT)
  794. }
  795. static func getDomainOpr() -> String {
  796. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_DOMAIN_OPR) {
  797. return value
  798. }
  799. return "https://nexilis.io/"
  800. }
  801. static func getIpOpr() -> String {
  802. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_IP_PORT_OPR) {
  803. return value
  804. }
  805. return "34.101.172.194:42823"
  806. }
  807. /**
  808. * Keylogger
  809. */
  810. static func setPreventKeylogger(value: Bool){
  811. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_KEYLOGGER)
  812. }
  813. static func getPreventKeylogger() -> Bool {
  814. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_KEYLOGGER) {
  815. return value
  816. }
  817. return false
  818. }
  819. static func setPreventKeyloggerAction(value: String){
  820. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_KEYLOGGER_ACTION)
  821. }
  822. static func getPreventKeyloggerAction() -> String {
  823. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_KEYLOGGER_ACTION) {
  824. return value
  825. }
  826. return "0"
  827. }
  828. static func setKeyloggerAlertTitle(value: String){
  829. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_KEYLOGGER_ALERT_TITLE)
  830. }
  831. static func getKeyloggerAlertTitle() -> String {
  832. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_KEYLOGGER_ALERT_TITLE) {
  833. return value
  834. }
  835. return PreferencesKey.ss_screenshare_title
  836. }
  837. static func setKeyloggerAlertMessage(value: String){
  838. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_KEYLOGGER_ALERT_MESSAGE)
  839. }
  840. static func getKeyloggerAlertMessage() -> String {
  841. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_KEYLOGGER_ALERT_MESSAGE) {
  842. return value
  843. }
  844. return PreferencesKey.ss_screenshare_warning
  845. }
  846. /**
  847. * Screen Capture
  848. */
  849. static func setPreventScreenCapture(value: Bool){
  850. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_CAPTURE)
  851. }
  852. static func getPreventScreenCapture() -> Bool {
  853. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_CAPTURE) {
  854. return value
  855. }
  856. return false
  857. }
  858. static func setPreventScreenCaptureAction(value: String){
  859. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_CAPTURE_ACTION)
  860. }
  861. static func getPreventScreenCaptureAction() -> String {
  862. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_CAPTURE_ACTION) {
  863. return value
  864. }
  865. return "0"
  866. }
  867. static func setCheckScreenCaptureAlertTitle(value: String){
  868. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_CAPTURE_ALERT_TITLE)
  869. }
  870. static func getCheckScreenCaptureAlertTitle() -> String {
  871. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_CAPTURE_ALERT_TITLE) {
  872. return value
  873. }
  874. return PreferencesKey.ss_screenshare_title
  875. }
  876. static func setScreenCaptureAlertMessage(value: String){
  877. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_CAPTURE_ALERT_MESSAGE)
  878. }
  879. static func getScreenCaptureAlertMessage() -> String {
  880. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_CAPTURE_ALERT_MESSAGE) {
  881. return value
  882. }
  883. return PreferencesKey.ss_screenshare_warning
  884. }
  885. /**
  886. * Emulator
  887. */
  888. static func setCheckEmulator(value: Bool){
  889. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_EMULATOR)
  890. }
  891. static func getCheckEmulator() -> Bool {
  892. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_EMULATOR) {
  893. return value
  894. }
  895. return false
  896. }
  897. static func setCheckEmulatorAction(value: String){
  898. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_EMULATOR_ACTION)
  899. }
  900. static func getCheckEmulatorAction() -> String {
  901. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_EMULATOR_ACTION) {
  902. return value
  903. }
  904. return "0"
  905. }
  906. static func setCheckEmulatorAlertTitle(value: String){
  907. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_EMULATOR_ALERT_TITLE)
  908. }
  909. static func getCheckEmulatorAlertTitle() -> String {
  910. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_EMULATOR_ALERT_TITLE) {
  911. return value
  912. }
  913. return PreferencesKey.ss_emulator_title
  914. }
  915. static func setCheckEmulatorAlertMessage(value: String){
  916. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_EMULATOR_ALERT_MESSAGE)
  917. }
  918. static func getCheckEmulatorAlertMessage() -> String {
  919. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_EMULATOR_ALERT_MESSAGE) {
  920. return value
  921. }
  922. return PreferencesKey.ss_emulator_continue
  923. }
  924. /**
  925. * Root/Jailbreak Detection
  926. */
  927. static func setCheckRooted(value: Bool){
  928. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_ROOTED)
  929. }
  930. static func getCheckRooted() -> Bool {
  931. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_ROOTED) {
  932. return value
  933. }
  934. return false
  935. }
  936. static func setCheckRootedAction(value: String){
  937. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_ROOTED_ACTION)
  938. }
  939. static func getCheckRootedAction() -> String {
  940. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_ROOTED_ACTION) {
  941. return value
  942. }
  943. return "0"
  944. }
  945. static func setCheckRootedAlertTitle(value: String){
  946. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_ROOTED_ALERT_TITLE)
  947. }
  948. static func getCheckRootedAlertTitle() -> String {
  949. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_ROOTED_ALERT_TITLE) {
  950. return value
  951. }
  952. return PreferencesKey.ss_rooted_title
  953. }
  954. static func setCheckRootedAlertMessage(value: String){
  955. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_ROOTED_ALERT_MESSAGE)
  956. }
  957. static func getCheckRootedAlertMessage() -> String {
  958. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_ROOTED_ALERT_MESSAGE) {
  959. return value
  960. }
  961. return PreferencesKey.ss_rooted_warning
  962. }
  963. /**
  964. * Outdated OS Detection
  965. */
  966. static func setCheckOutdatedOs(value: Bool){
  967. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_OUTDATED_OS)
  968. }
  969. static func getCheckOutdatedOs() -> Bool {
  970. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_OUTDATED_OS) {
  971. return value
  972. }
  973. return false
  974. }
  975. static func setCheckOutdatedOsAction(value: String){
  976. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_ROOTED_ACTION)
  977. }
  978. static func getCheckOutdatedOsAction() -> String {
  979. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_ROOTED_ACTION) {
  980. return value
  981. }
  982. return "0"
  983. }
  984. static func setCheckOutdatedOsAlertTitle(value: String){
  985. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_OUTDATED_OS_ALERT_TITLE)
  986. }
  987. static func getCheckOutdatedOsAlertTitle() -> String {
  988. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_OUTDATED_OS_ALERT_TITLE) {
  989. return value
  990. }
  991. return PreferencesKey.ss_os_not_supported_title
  992. }
  993. static func setCheckOutdatedOsAlertMessage(value: String){
  994. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_OUTDATED_OS_ALERT_MESSAGE)
  995. }
  996. static func getCheckOutdatedOsAlertMessage() -> String {
  997. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_OUTDATED_OS_ALERT_MESSAGE) {
  998. return value
  999. }
  1000. return PreferencesKey.ss_os_not_supported_continue
  1001. }
  1002. static func setMinimumOsVersion(value: String){
  1003. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_MINIMUM_OS_VERSION)
  1004. }
  1005. static func getMinimumOsVersion() -> String {
  1006. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_MINIMUM_OS_VERSION) {
  1007. return value
  1008. }
  1009. return "14"
  1010. }
  1011. /**
  1012. * Tempering Detection
  1013. */
  1014. static func setCheckTempering(value: Bool){
  1015. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_TEMPERING)
  1016. }
  1017. static func getCheckTempering() -> Bool {
  1018. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_TEMPERING) {
  1019. return value
  1020. }
  1021. return false
  1022. }
  1023. static func setCheckTemperingAction(value: String){
  1024. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_TEMPERING_ACTION)
  1025. }
  1026. static func getCheckTemperingAction() -> String {
  1027. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_TEMPERING_ACTION) {
  1028. return value
  1029. }
  1030. return "0"
  1031. }
  1032. static func setCheckTemperingAlertTitle(value: String){
  1033. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_TEMPERING_ALERT_TITLE)
  1034. }
  1035. static func getCheckTemperingAlertTitle() -> String {
  1036. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_TEMPERING_ALERT_TITLE) {
  1037. return value
  1038. }
  1039. return PreferencesKey.ss_tempering_title
  1040. }
  1041. static func setCheckTemperingAlertMessage(value: String){
  1042. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_TEMPERING_ALERT_MESSAGE)
  1043. }
  1044. static func getCheckTemperingAlertMessage() -> String {
  1045. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_TEMPERING_ALERT_MESSAGE) {
  1046. return value
  1047. }
  1048. return PreferencesKey.ss_tempering_warning
  1049. }
  1050. /**
  1051. * Debugging Detection
  1052. */
  1053. static func setCheckDebugging(value: Bool){
  1054. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_DEBUGGING)
  1055. }
  1056. static func getCheckDebugging() -> Bool {
  1057. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_DEBUGGING) {
  1058. return value
  1059. }
  1060. return false
  1061. }
  1062. static func setCheckDebuggingAction(value: String){
  1063. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_DEBUGGING_ACTION)
  1064. }
  1065. static func getCheckDebuggingAction() -> String {
  1066. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_DEBUGGING_ACTION) {
  1067. return value
  1068. }
  1069. return "0"
  1070. }
  1071. static func setCheckDebuggingAlertTitle(value: String){
  1072. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_DEBUGGING_ALERT_TITLE)
  1073. }
  1074. static func getCheckDebuggingAlertTitle() -> String {
  1075. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_DEBUGGING_ALERT_TITLE) {
  1076. return value
  1077. }
  1078. return PreferencesKey.ss_debugging_title
  1079. }
  1080. static func setCheckDebuggingAlertMessage(value: String){
  1081. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_DEBUGGING_ALERT_MESSAGE)
  1082. }
  1083. static func getCheckDebuggingAlertMessage() -> String {
  1084. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_DEBUGGING_ALERT_MESSAGE) {
  1085. return value
  1086. }
  1087. return PreferencesKey.ss_debugging_warning
  1088. }
  1089. /**
  1090. * Screen Casting
  1091. */
  1092. static func setCheckScreenCasting(value: Bool){
  1093. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_CASTING)
  1094. }
  1095. static func getCheckScreenCasting() -> Bool {
  1096. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_CASTING) {
  1097. return value
  1098. }
  1099. return false
  1100. }
  1101. static func setCheckScreenCastingAction(value: String){
  1102. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_CASTING_ACTION)
  1103. }
  1104. static func getCheckScreenCastingAction() -> String {
  1105. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_CASTING_ACTION) {
  1106. return value
  1107. }
  1108. return "0"
  1109. }
  1110. static func setCheckScreenCastingAlertTitle(value: String){
  1111. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_CASTING_ALERT_TITLE)
  1112. }
  1113. static func getCheckScreenCastingAlertTitle() -> String {
  1114. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_CASTING_ALERT_TITLE) {
  1115. return value
  1116. }
  1117. return PreferencesKey.ss_debugging_title
  1118. }
  1119. static func setCheckScreenCastingAlertMessage(value: String){
  1120. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_CASTING_ALERT_MESSAGE)
  1121. }
  1122. static func getCheckScreenCastingAlertMessage() -> String {
  1123. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_CASTING_ALERT_MESSAGE) {
  1124. return value
  1125. }
  1126. return PreferencesKey.ss_debugging_warning
  1127. }
  1128. /**
  1129. * Screen Overlay
  1130. */
  1131. static func setCheckScreenOverlay(value: Bool){
  1132. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_OVERLAY)
  1133. }
  1134. static func getCheckScreenOverlay() -> Bool {
  1135. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_OVERLAY) {
  1136. return value
  1137. }
  1138. return false
  1139. }
  1140. static func setCheckScreenOverlayAction(value: String){
  1141. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_OVERLAY_ACTION)
  1142. }
  1143. static func getCheckScreenOverlayAction() -> String {
  1144. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_OVERLAY_ACTION) {
  1145. return value
  1146. }
  1147. return "0"
  1148. }
  1149. static func setCheckScreenOverlayAlertTitle(value: String){
  1150. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_OVERLAY_ALERT_TITLE)
  1151. }
  1152. static func getCheckScreenOverlayAlertTitle() -> String {
  1153. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_OVERLAY_ALERT_TITLE) {
  1154. return value
  1155. }
  1156. return PreferencesKey.ss_screenoverlay_title
  1157. }
  1158. static func setCheckScreenOverlayAlertMessage(value: String){
  1159. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SCREEN_OVERLAY_ALERT_MESSAGE)
  1160. }
  1161. static func getCheckScreenOverlayAlertMessage() -> String {
  1162. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SCREEN_OVERLAY_ALERT_MESSAGE) {
  1163. return value
  1164. }
  1165. return PreferencesKey.ss_screenoverlay_continue
  1166. }
  1167. /**
  1168. * Call Redirection Detection
  1169. */
  1170. static func setCheckCallForward(value: Bool){
  1171. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_CALL_FORWARD)
  1172. }
  1173. static func getCheckCallForward() -> Bool {
  1174. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_CALL_FORWARD) {
  1175. return value
  1176. }
  1177. return false
  1178. }
  1179. static func setCheckCallForwardAction(value: String){
  1180. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_CALL_FORWARD_ACTION)
  1181. }
  1182. static func getCheckCallForwardAction() -> String {
  1183. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_CALL_FORWARD_ACTION) {
  1184. return value
  1185. }
  1186. return "0"
  1187. }
  1188. static func setCheckCallForwardAlertTitle(value: String){
  1189. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_CALL_FORWARD_ALERT_TITLE)
  1190. }
  1191. static func getCheckCallForwardAlertTitle() -> String {
  1192. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_CALL_FORWARD_ALERT_TITLE) {
  1193. return value
  1194. }
  1195. return PreferencesKey.ss_callforward_title
  1196. }
  1197. static func setCheckCallForwardAlertMessage(value: String){
  1198. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_CALL_FORWARD_ALERT_MESSAGE)
  1199. }
  1200. static func getCheckCallForwardAlertMessage() -> String {
  1201. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_CALL_FORWARD_ALERT_MESSAGE) {
  1202. return value
  1203. }
  1204. return PreferencesKey.ss_callforward_continue
  1205. }
  1206. /**
  1207. * Multiple Login Detection
  1208. */
  1209. static func setCheckMultipleLogin(value: Bool){
  1210. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_MULTIPLE_LOGIN)
  1211. }
  1212. static func getCheckMultipleLogin() -> Bool {
  1213. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_MULTIPLE_LOGIN) {
  1214. return value
  1215. }
  1216. return false
  1217. }
  1218. static func setCheckMultipleLoginAction(value: String){
  1219. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_MULTIPLE_LOGIN_ACTION)
  1220. }
  1221. static func getCheckMultipleLoginAction() -> String {
  1222. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_MULTIPLE_LOGIN_ACTION) {
  1223. return value
  1224. }
  1225. return "0"
  1226. }
  1227. static func setCheckMultipleLoginAlertTitle(value: String){
  1228. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_MULTIPLE_LOGIN_ALERT_TITLE)
  1229. }
  1230. static func getCheckMultipleLoginAlertTitle() -> String {
  1231. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_MULTIPLE_LOGIN_ALERT_TITLE) {
  1232. return value
  1233. }
  1234. return PreferencesKey.ss_multiple_login_title
  1235. }
  1236. static func setCheckMultipleLoginAlertMessage(value: String){
  1237. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_MULTIPLE_LOGIN_ALERT_MESSAGE)
  1238. }
  1239. static func getCheckMultipleLoginAlertMessage() -> String {
  1240. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_MULTIPLE_LOGIN_ALERT_MESSAGE) {
  1241. return value
  1242. }
  1243. return PreferencesKey.ss_multiple_login_warning
  1244. }
  1245. /**
  1246. * SIM Swap Detection
  1247. */
  1248. static func setCheckSimSwap(value: Bool){
  1249. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SIM_SWAP)
  1250. }
  1251. static func getCheckSimSwap() -> Bool {
  1252. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SIM_SWAP) {
  1253. return value
  1254. }
  1255. return false
  1256. }
  1257. static func setCheckSimSwapAction(value: String){
  1258. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SIM_SWAP_ACTION)
  1259. }
  1260. static func getCheckSimSwapAction() -> String {
  1261. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SIM_SWAP_ACTION) {
  1262. return value
  1263. }
  1264. return "0"
  1265. }
  1266. static func setCheckSimSwapAlertTitle(value: String){
  1267. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SIM_SWAP_ALERT_TITLE)
  1268. }
  1269. static func getCheckSimSwapAlertTitle() -> String {
  1270. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SIM_SWAP_ALERT_TITLE) {
  1271. return value
  1272. }
  1273. return PreferencesKey.ss_simswap_title
  1274. }
  1275. static func setCheckSimSwapAlertMessage(value: String){
  1276. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_SIM_SWAP_ALERT_MESSAGE)
  1277. }
  1278. static func getCheckSimSwapAlertMessage() -> String {
  1279. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_SIM_SWAP_ALERT_MESSAGE) {
  1280. return value
  1281. }
  1282. return PreferencesKey.ss_simswap_warning
  1283. }
  1284. /**
  1285. * Geo-Velocity Checks
  1286. */
  1287. static func setCheckGeoVelocity(value: Bool){
  1288. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_GEO_VELOCITY)
  1289. }
  1290. static func getCheckGeoVelocity() -> Bool {
  1291. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_GEO_VELOCITY) {
  1292. return value
  1293. }
  1294. return false
  1295. }
  1296. static func setCheckGeoVelocityAction(value: String){
  1297. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_GEO_VELOCITY_ACTION)
  1298. }
  1299. static func getCheckGeoVelocityAction() -> String {
  1300. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_GEO_VELOCITY_ACTION) {
  1301. return value
  1302. }
  1303. return "0"
  1304. }
  1305. static func setCheckGeoVelocityAlertTitle(value: String){
  1306. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_GEO_VELOCITY_ALERT_TITLE)
  1307. }
  1308. static func getCheckGeoVelocityAlertTitle() -> String {
  1309. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_GEO_VELOCITY_ALERT_TITLE) {
  1310. return value
  1311. }
  1312. return PreferencesKey.ss_geo_velocity_title
  1313. }
  1314. static func setCheckGeoVelocityAlertMessage(value: String){
  1315. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_GEO_VELOCITY_ALERT_MESSAGE)
  1316. }
  1317. static func getCheckGeoVelocityAlertMessage() -> String {
  1318. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_GEO_VELOCITY_ALERT_MESSAGE) {
  1319. return value
  1320. }
  1321. return PreferencesKey.ss_geo_velocity_warning
  1322. }
  1323. /**
  1324. * Behavioral Anomaly Detection
  1325. */
  1326. static func setCheckBehaviourAnalysis(value: Bool){
  1327. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_BEHAVIOUR_ANALYSIS)
  1328. }
  1329. static func getCheckBehaviourAnalysis() -> Bool {
  1330. if let value: Bool = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_BEHAVIOUR_ANALYSIS) {
  1331. return value
  1332. }
  1333. return false
  1334. }
  1335. static func setCheckBehaviourAnalysisAction(value: String){
  1336. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_BEHAVIOUR_ANALYSIS_ACTION)
  1337. }
  1338. static func getCheckBehaviourAnalysisAction() -> String {
  1339. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_BEHAVIOUR_ANALYSIS_ACTION) {
  1340. return value
  1341. }
  1342. return "0"
  1343. }
  1344. static func setCheckBehaviourAnalysisAlertTitle(value: String){
  1345. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_BEHAVIOUR_ANALYSIS_ALERT_TITLE)
  1346. }
  1347. static func getCheckBehaviourAnalysisAlertTitle() -> String {
  1348. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_BEHAVIOUR_ANALYSIS_ALERT_TITLE) {
  1349. return value
  1350. }
  1351. return PreferencesKey.ss_behaviour_anomaly_title
  1352. }
  1353. static func setCheckBehaviourAnalysisAlertMessage(value: String){
  1354. SecureUserDefaultsSS.shared.set(value, forKey: PreferencesKey.SS_CHECK_BEHAVIOUR_ANALYSIS_ALERT_MESSAGE)
  1355. }
  1356. static func getCheckBehaviourAnalysisAlertMessage() -> String {
  1357. if let value: String = SecureUserDefaultsSS.shared.value(forKey: PreferencesKey.SS_CHECK_BEHAVIOUR_ANALYSIS_ALERT_MESSAGE) {
  1358. return value
  1359. }
  1360. return PreferencesKey.ss_behaviour_anomaly_warning
  1361. }
  1362. }
  1363. private class PreferencesKey {
  1364. static let SECURITY_SHIELD_ALERT_EXIT = "0"
  1365. static let SECURITY_SHIELD_ALERT_CONTINUE = "1"
  1366. static let ERR121 = "121:Emulator detected"
  1367. static let ERR122 = "122:Malware detected"
  1368. static let ERR123 = "123:USB/WiFi debugging detected"
  1369. static let ERR124 = "124:Cloned app detected"
  1370. static let ERR125 = "125:Call forwarding detected"
  1371. static let ERR126 = "126:Screen sharing detected"
  1372. static let ERR127 = "127:OS Version not supported"
  1373. static let ERR128 = "128:Application backup detected"
  1374. static let ERR129 = "129:Failed security reasons"
  1375. static let ERR130 = "130:Tampering detected"
  1376. static let ERR131 = "131:SIM Swap detected"
  1377. static let ERR132 = "132:Behavioral Anomaly detected"
  1378. static let SS_USER_APP_ID = "ss_user_app_id"
  1379. static let SS_USER_ACCOUNT = "ss_user_account"
  1380. static let SS_DOMAIN_OPR = "domain_opr"
  1381. static let SS_IP_PORT_OPR = "ip_opr"
  1382. static let SS_CHECK_KEYLOGGER = "ss_check_keylogger"
  1383. static let SS_CHECK_KEYLOGGER_ACTION = "ss_check_keylogger_action"
  1384. static let SS_CHECK_KEYLOGGER_ALERT_TITLE = "ss_check_keylogger_alert_title"
  1385. static let SS_CHECK_KEYLOGGER_ALERT_MESSAGE = "ss_check_keylogger_alert_message"
  1386. static let SS_CHECK_SCREEN_CAPTURE = "ss_check_screen_capture"
  1387. static let SS_CHECK_SCREEN_CAPTURE_ACTION = "ss_check_screen_capture_action"
  1388. static let SS_CHECK_SCREEN_CAPTURE_ALERT_TITLE = "ss_check_screen_capture_alert_title"
  1389. static let SS_CHECK_SCREEN_CAPTURE_ALERT_MESSAGE = "ss_check_screen_capture_alert_message"
  1390. static let ss_screenshare_title = "Screen Sharing Detected!"
  1391. 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."
  1392. static let SS_CHECK_EMULATOR = "ss_check_emulator"
  1393. static let SS_CHECK_EMULATOR_ACTION = "ss_check_emulator_action"
  1394. static let SS_CHECK_EMULATOR_ALERT_TITLE = "ss_check_emulator_alert_title"
  1395. static let SS_CHECK_EMULATOR_ALERT_MESSAGE = "ss_check_emulator_alert_message"
  1396. static let ss_emulator_title = "Emulator Detected!"
  1397. static let ss_emulator_continue = "We are sorry for the inconvenience. For security reasons this app is not allowed to run on an emulator."
  1398. static let SS_CHECK_ROOTED = "ss_check_rooted"
  1399. static let SS_CHECK_ROOTED_ACTION = "ss_check_rooted_action"
  1400. static let SS_CHECK_ROOTED_ALERT_TITLE = "ss_check_rooted_alert_title"
  1401. static let SS_CHECK_ROOTED_ALERT_MESSAGE = "ss_check_rooted_alert_message"
  1402. static let ss_rooted_title = "Root or Jailbreak Detected!"
  1403. 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."
  1404. static let SS_CHECK_OUTDATED_OS = "ss_check_outdated_os"
  1405. static let SS_CHECK_OUTDATED_OS_ACTION = "ss_check_outdated_os_action"
  1406. static let SS_CHECK_OUTDATED_OS_ALERT_TITLE = "ss_check_outdated_os_alert_title"
  1407. static let SS_CHECK_OUTDATED_OS_ALERT_MESSAGE = "ss_check_outdated_os_alert_message"
  1408. static let SS_CHECK_MINIMUM_OS_VERSION = "ss_minimum_os_version"
  1409. static let ss_os_not_supported_title = "Android Version Not Secure!"
  1410. 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."
  1411. static let SS_CHECK_TEMPERING = "ss_check_tempering"
  1412. static let SS_CHECK_TEMPERING_ACTION = "ss_check_tempering_action"
  1413. static let SS_CHECK_TEMPERING_ALERT_TITLE = "ss_check_tempering_alert_title"
  1414. static let SS_CHECK_TEMPERING_ALERT_MESSAGE = "ss_check_tempering_alert_message"
  1415. static let ss_tempering_title = "Tempering Detected!"
  1416. 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."
  1417. static let SS_CHECK_DEBUGGING = "ss_check_debugging"
  1418. static let SS_CHECK_DEBUGGING_ACTION = "ss_check_debugging_action"
  1419. static let SS_CHECK_DEBUGGING_ALERT_TITLE = "ss_check_debugging_alert_title"
  1420. static let SS_CHECK_DEBUGGING_ALERT_MESSAGE = "ss_check_debugging_alert_message"
  1421. static let ss_debugging_title = "Debugging Mode Detected!"
  1422. static let ss_debugging_warning = "Your device running on debugging mode. Please disable it."
  1423. static let SS_CHECK_SCREEN_CASTING = "ss_check_screen_casting"
  1424. static let SS_CHECK_SCREEN_CASTING_ACTION = "ss_check_screen_casting_action"
  1425. static let SS_CHECK_SCREEN_CASTING_ALERT_TITLE = "ss_check_screen_casting_alert_title"
  1426. static let SS_CHECK_SCREEN_CASTING_ALERT_MESSAGE = "ss_check_screen_casting_alert_message"
  1427. static let SS_CHECK_SCREEN_OVERLAY = "ss_check_screen_overlay"
  1428. static let SS_CHECK_SCREEN_OVERLAY_ACTION = "ss_check_screen_overlay_action"
  1429. static let SS_CHECK_SCREEN_OVERLAY_ALERT_TITLE = "ss_check_screen_overlay_alert_title"
  1430. static let SS_CHECK_SCREEN_OVERLAY_ALERT_MESSAGE = "ss_check_screen_overlay_alert_message"
  1431. static let ss_screenoverlay_title = "Screen Overlay Detected!"
  1432. 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."
  1433. static let SS_CHECK_CALL_FORWARD = "ss_check_call_forward"
  1434. static let SS_CHECK_CALL_FORWARD_ACTION = "ss_check_call_forward_action"
  1435. static let SS_CHECK_CALL_FORWARD_ALERT_TITLE = "ss_check_call_forward_alert_title"
  1436. static let SS_CHECK_CALL_FORWARD_ALERT_MESSAGE = "ss_check_call_forward_alert_message"
  1437. static let ss_callforward_title = "Call Forwarding Detected!";
  1438. 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.";
  1439. static let SS_CHECK_MULTIPLE_LOGIN = "ss_check_multiple_login"
  1440. static let SS_CHECK_MULTIPLE_LOGIN_ACTION = "ss_check_multiple_login_action"
  1441. static let SS_CHECK_MULTIPLE_LOGIN_ALERT_TITLE = "ss_check_multiple_login_alert_title"
  1442. static let SS_CHECK_MULTIPLE_LOGIN_ALERT_MESSAGE = "ss_check_multiple_login_alert_message"
  1443. static let ss_multiple_login_title = "Multiple Login Detected!"
  1444. 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."
  1445. static let SS_CHECK_SIM_SWAP = "ss_check_sim_swap"
  1446. static let SS_CHECK_SIM_SWAP_ACTION = "ss_check_sim_swap_action"
  1447. static let SS_CHECK_SIM_SWAP_ALERT_TITLE = "ss_check_sim_swap_alert_title"
  1448. static let SS_CHECK_SIM_SWAP_ALERT_MESSAGE = "ss_check_sim_swap_alert_message"
  1449. static let ss_simswap_title = "Sim Swap Detected!"
  1450. 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."
  1451. static let SS_CHECK_GEO_VELOCITY = "ss_check_geo_velocity"
  1452. static let SS_CHECK_GEO_VELOCITY_ACTION = "ss_check_geo_velocity_action"
  1453. static let SS_CHECK_GEO_VELOCITY_ALERT_TITLE = "ss_check_geo_velocity_alert_title"
  1454. static let SS_CHECK_GEO_VELOCITY_ALERT_MESSAGE = "ss_check_geo_velocity_alert_message"
  1455. static let ss_geo_velocity_title = "Geo Velocity Anomaly Detected!"
  1456. 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."
  1457. static let SS_CHECK_BEHAVIOUR_ANALYSIS = "ss_check_behaviour_analysis"
  1458. static let SS_CHECK_BEHAVIOUR_ANALYSIS_ACTION = "ss_check_behaviour_analysis_action"
  1459. static let SS_CHECK_BEHAVIOUR_ANALYSIS_ALERT_TITLE = "ss_check_behaviour_analysis_alert_title"
  1460. static let SS_CHECK_BEHAVIOUR_ANALYSIS_ALERT_MESSAGE = "ss_check_behaviour_analysis_alert_message"
  1461. static let ss_behaviour_anomaly_title = "Behaviour Anomaly Detected!"
  1462. 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."
  1463. }
  1464. private class SelfSignedURLSessionDelegate: NSObject, URLSessionTaskDelegate, URLSessionDataDelegate {
  1465. public func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
  1466. if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
  1467. if let serverTrust = challenge.protectionSpace.serverTrust {
  1468. let credential = URLCredential(trust: serverTrust)
  1469. completionHandler(.useCredential, credential)
  1470. }
  1471. }
  1472. }
  1473. }
  1474. private class Utils {
  1475. private static let I_BB = 48 // 0
  1476. private static let I_BBT_1 = 57 // 9
  1477. private static let I_BAT_1 = 65 // A
  1478. private static let I_BBT_2 = 90 // Z
  1479. private static let I_BAT_2 = 97 // a
  1480. private static let I_BA = 122 // z
  1481. private static let IC_BB = 33 // !
  1482. private static let IC_BBT_1 = 47 // /
  1483. private static let IC_BAT_1 = 58 // :
  1484. private static let IC_BBT_2 = 64 // @
  1485. private static let IC_BAT_2 = 91 // [
  1486. private static let IC_BBT_3 = 96 // @
  1487. private static let IC_BAT_3 = 123 // [
  1488. private static let IC_BA = 126 // `
  1489. private static var icIGNORE = Set<Int>()
  1490. private static func initIcIgnore() {
  1491. icIGNORE.insert(10)// \r
  1492. icIGNORE.insert(13)// \n
  1493. icIGNORE.insert(32)// <space>
  1494. }
  1495. public static func decrypt(str: String) -> String {
  1496. var arr: [Character]
  1497. var iRandom = 0
  1498. var sDecrypt: String
  1499. iRandom = Int(str.substring(from: 0, to: 0)) ?? 0
  1500. sDecrypt = getPalindrom(str: str.substring(from: 1, to: nil))
  1501. arr = Array(sDecrypt)
  1502. for i in 0..<arr.count {
  1503. if (isSpecialChar(ch: arr[i])) {
  1504. arr[i] = getBeforecChar(ch: arr[i], inc: iRandom)
  1505. } else {
  1506. arr[i] = getBeforeChar(ch: arr[i], inc: iRandom)
  1507. }
  1508. }
  1509. return String(arr)
  1510. }
  1511. private static func isSpecialChar(ch: Character) -> Bool {
  1512. let ch = Int(ch.asciiValue ?? 0)
  1513. 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)
  1514. }
  1515. private static func getPalindrom(str: String) -> String {
  1516. let arr: [Character] = Array(str)
  1517. var arr2: [Character] = Array(arr)
  1518. for i in 0..<arr.count {
  1519. arr2[i] = arr[arr.count - (i + 1)]
  1520. }
  1521. return String(arr2)
  1522. }
  1523. private static func getBeforeChar(ch: Character, inc: Int) -> Character {
  1524. if icIGNORE.isEmpty {
  1525. initIcIgnore()
  1526. }
  1527. var iAscii = ch
  1528. let iAsciiBefore = iAscii
  1529. if (icIGNORE.contains(Int(iAscii.asciiValue ?? 0))) {
  1530. return iAscii;
  1531. }
  1532. if Int(iAscii.asciiValue ?? 0) > I_BA || Int(iAscii.asciiValue ?? 0) < I_BB {
  1533. } else {
  1534. if !icIGNORE.contains(Int(iAscii.asciiValue ?? 0)) {
  1535. iAscii = Character(UnicodeScalar(Int(iAscii.asciiValue ?? 0) - inc)!)
  1536. if (I_BAT_1 > Int(iAscii.asciiValue ?? 0) && Int(iAsciiBefore.asciiValue ?? 0) >= I_BAT_1) {
  1537. iAscii = Character(UnicodeScalar((I_BBT_1 + 1) - (I_BAT_1 - Int(iAscii.asciiValue ?? 0)))!)
  1538. }
  1539. if (I_BAT_2 > Int(iAscii.asciiValue ?? 0) && Int(iAsciiBefore.asciiValue ?? 0) >= I_BAT_2) {
  1540. iAscii = Character(UnicodeScalar((I_BBT_2 + 1) - (I_BAT_2 - Int(iAscii.asciiValue ?? 0)))!)
  1541. }
  1542. if (Int(iAscii.asciiValue ?? 0) < I_BB) {
  1543. iAscii = Character(UnicodeScalar((I_BA + 1) + (Int(iAscii.asciiValue ?? 0) - I_BB))!)
  1544. }
  1545. }
  1546. }
  1547. return iAscii
  1548. }
  1549. private static func getBeforecChar(ch: Character, inc: Int) -> Character {
  1550. var iAscii = ch
  1551. let iAsciiBefore = iAscii
  1552. if (Int(iAscii.asciiValue ?? 0) > IC_BA || Int(iAscii.asciiValue ?? 0) < IC_BB) {
  1553. } else {
  1554. iAscii = Character(UnicodeScalar(Int(iAscii.asciiValue ?? 0) - inc)!)
  1555. if (Int(iAscii.asciiValue ?? 0) < IC_BB) {
  1556. iAscii = Character(UnicodeScalar((IC_BA + 1) + (Int(iAscii.asciiValue ?? 0) - IC_BB))!)
  1557. if (Int(iAscii.asciiValue ?? 0) < IC_BAT_3 && Int(iAscii.asciiValue ?? 0) > IC_BBT_3) {
  1558. iAscii = Character(UnicodeScalar((IC_BBT_3 + 1) - (IC_BAT_3 - Int(iAscii.asciiValue ?? 0)))!)
  1559. }
  1560. }
  1561. if (IC_BAT_3 > Int(iAscii.asciiValue ?? 0) && Int(iAsciiBefore.asciiValue ?? 0) >= IC_BAT_3) {
  1562. iAscii = Character(UnicodeScalar((IC_BBT_3 + 1) - (IC_BAT_3 - Int(iAscii.asciiValue ?? 0)))!)
  1563. }
  1564. if (IC_BAT_2 > Int(iAscii.asciiValue ?? 0) && Int(iAsciiBefore.asciiValue ?? 0) >= IC_BAT_2) {
  1565. iAscii = Character(UnicodeScalar((IC_BBT_2 + 1) - (IC_BAT_2 - Int(iAscii.asciiValue ?? 0)))!)
  1566. }
  1567. if (IC_BAT_1 > Int(iAscii.asciiValue ?? 0) && Int(iAsciiBefore.asciiValue ?? 0) >= IC_BAT_1) {
  1568. iAscii = Character(UnicodeScalar((IC_BBT_1 + 1) - (IC_BAT_1 - Int(iAscii.asciiValue ?? 0)))!)
  1569. }
  1570. }
  1571. return iAscii
  1572. }
  1573. }
  1574. extension String {
  1575. public func substring(from: Int?, to: Int?) -> String {
  1576. if let start = from {
  1577. guard start < self.count else {
  1578. return ""
  1579. }
  1580. }
  1581. if let end = to {
  1582. guard end >= 0 else {
  1583. return ""
  1584. }
  1585. }
  1586. if let start = from, let end = to {
  1587. guard end - start >= 0 else {
  1588. return ""
  1589. }
  1590. }
  1591. let startIndex: String.Index
  1592. if let start = from, start >= 0 {
  1593. startIndex = self.index(self.startIndex, offsetBy: start)
  1594. } else {
  1595. startIndex = self.startIndex
  1596. }
  1597. let endIndex: String.Index
  1598. if let end = to, end >= 0, end < self.count {
  1599. endIndex = self.index(self.startIndex, offsetBy: end + 1)
  1600. } else {
  1601. endIndex = self.endIndex
  1602. }
  1603. return String(self[startIndex ..< endIndex])
  1604. }
  1605. }
  1606. extension UIColor {
  1607. public static var mainColorSS: UIColor {
  1608. return renderColor(hex: "#046cfc")
  1609. }
  1610. public static var blackDarkModeSS: UIColor {
  1611. return renderColor(hex: "#262626")
  1612. }
  1613. public class func renderColor(hex: String) -> UIColor {
  1614. var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
  1615. if (cString.hasPrefix("#")) {
  1616. cString.remove(at: cString.startIndex)
  1617. }
  1618. if ((cString.count) != 6) {
  1619. return UIColor.gray
  1620. }
  1621. var rgbValue:UInt64 = 0
  1622. Scanner(string: cString).scanHexInt64(&rgbValue)
  1623. return UIColor(
  1624. red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
  1625. green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
  1626. blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
  1627. alpha: CGFloat(1.0)
  1628. )
  1629. }
  1630. }
  1631. extension UIApplication {
  1632. public static var appVersion: String? {
  1633. return Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
  1634. }
  1635. var rootViewController: UIViewController? {
  1636. return UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController
  1637. }
  1638. public var visibleViewController: UIViewController? {
  1639. let keyWindow = UIApplication.shared.windows.filter {$0.isKeyWindow}.first
  1640. if var topController = keyWindow?.rootViewController {
  1641. while let presentedViewController = topController.presentedViewController {
  1642. topController = presentedViewController
  1643. }
  1644. return topController
  1645. }
  1646. return nil
  1647. }
  1648. }
  1649. extension UIImage {
  1650. static func imageWithColorSS(color: UIColor, size: CGSize) -> UIImage? {
  1651. let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
  1652. UIGraphicsBeginImageContextWithOptions(size, false, 0)
  1653. color.setFill()
  1654. UIRectFill(rect)
  1655. guard let image: UIImage = UIGraphicsGetImageFromCurrentImageContext() else {
  1656. return nil
  1657. }
  1658. UIGraphicsEndImageContext()
  1659. return image
  1660. }
  1661. }
  1662. public class TMessageSS {
  1663. public var mType: String = ""
  1664. public var mVersion: String = ""
  1665. public var mCode: String = ""
  1666. public var mStatus: String = ""
  1667. public var mPIN: String = ""
  1668. public var mL_PIN: String = ""
  1669. public var mBodies: [String: String] = [String: String]()
  1670. private var mMedia:[UInt8] = [UInt8]()
  1671. let C_HEADER:UnicodeScalar = UnicodeScalar(0x01)
  1672. let C_ENTRY:UnicodeScalar = UnicodeScalar(0x02)
  1673. let C_KEYVAL:UnicodeScalar = UnicodeScalar(0x03)
  1674. let C_ARRAY:UnicodeScalar = UnicodeScalar(0x04)
  1675. var S_HEADER: String = ""
  1676. var S_ENTRY: String = ""
  1677. var S_KEYVAL: String = ""
  1678. var S_ARRAY: String = ""
  1679. public static let TYPE_SQLITE_ONLY = "1"
  1680. public static let TYPE_ALL = "2"
  1681. public static let TYPE_NEED_ACK = "3"
  1682. let ERRCOD = "A97"
  1683. let MEDIA_LENGTH = "ML"
  1684. let FILE_SIZE = "A53C"
  1685. let IMEI = "Bb"
  1686. let VERCOD = "Bd"
  1687. func getCLMUserId() -> String {
  1688. guard let me: String = SecureUserDefaultsSS.shared.value(forKey: "me") else {
  1689. return ""
  1690. }
  1691. return me
  1692. }
  1693. public init() {
  1694. mVersion = "1.0.111"
  1695. mBodies[IMEI] = getCLMUserId()
  1696. mBodies[VERCOD] = "2.2.177"
  1697. }
  1698. public init(data : String) {
  1699. _ = unpack(data: data)
  1700. }
  1701. init(type: String, version: String, code: String,status: String, pin: String, l_pin: String, bodies:[String: String], media: [UInt8]) {
  1702. mType = type
  1703. mVersion = version
  1704. mCode = code
  1705. mStatus = status
  1706. mPIN = pin
  1707. mL_PIN = l_pin
  1708. mBodies = bodies
  1709. mMedia = media
  1710. mBodies[IMEI] = getCLMUserId()
  1711. mBodies[VERCOD] = "2.2.177"
  1712. }
  1713. public func clone(p_tmessage:TMessageSS) -> TMessageSS {
  1714. return TMessageSS(
  1715. type: p_tmessage.mType,
  1716. version: p_tmessage.mVersion,
  1717. code: p_tmessage.mCode,
  1718. status: p_tmessage.mStatus,
  1719. pin: p_tmessage.mPIN,
  1720. l_pin: p_tmessage.mL_PIN,
  1721. bodies: p_tmessage.mBodies,
  1722. media: p_tmessage.mMedia
  1723. )
  1724. }
  1725. public func setMedia(media: [UInt8]) {
  1726. mMedia = media
  1727. mBodies[MEDIA_LENGTH] = String(media.count)
  1728. }
  1729. public func getCode() -> String {
  1730. return mCode
  1731. }
  1732. public func getStatus() -> String {
  1733. return mStatus
  1734. }
  1735. public func getPIN() -> String {
  1736. return mPIN
  1737. }
  1738. public func getType() -> String {
  1739. return mType
  1740. }
  1741. public func getL_PIN() -> String {
  1742. return mL_PIN
  1743. }
  1744. public func getMedia() -> [UInt8] {
  1745. return mMedia
  1746. }
  1747. public func getBody(key : String) -> String {
  1748. if let data = mBodies[key] {
  1749. return data
  1750. }
  1751. else {
  1752. return ""
  1753. }
  1754. }
  1755. public func getBody(key : String, default_value: String) -> String {
  1756. if ((mBodies[key] == nil)) {
  1757. return default_value
  1758. } else if mBodies[key] == "null" {
  1759. return default_value
  1760. } else {
  1761. return mBodies[key]!
  1762. }
  1763. }
  1764. public func getBodyAsInteger(key : String, default_value: Int) -> Int {
  1765. if ((mBodies[key] == nil)) {
  1766. return default_value
  1767. } else if mBodies[key] == "null" {
  1768. return default_value
  1769. } else {
  1770. return Int(mBodies[key]!)!
  1771. }
  1772. }
  1773. public func getBodyAsLong(key : String, default_value: CLong) -> CLong {
  1774. if let body = mBodies[key] {
  1775. if (body == "null") {
  1776. return default_value
  1777. }
  1778. if (body == "nil") {
  1779. return default_value
  1780. }
  1781. return (body as NSString).integerValue
  1782. }
  1783. else {
  1784. return default_value
  1785. }
  1786. }
  1787. public func pack() -> String {
  1788. if (S_HEADER.isEmpty) { S_HEADER.append(Character(C_HEADER)) }
  1789. var data = ""
  1790. data.append(mType)
  1791. data.append(Character(C_HEADER))
  1792. data.append(mVersion)
  1793. data.append(Character(C_HEADER))
  1794. data.append(mCode)
  1795. data.append(Character(C_HEADER))
  1796. data.append(mStatus)
  1797. data.append(Character(C_HEADER))
  1798. data.append(mPIN)
  1799. data.append(Character(C_HEADER))
  1800. data.append(mL_PIN)
  1801. data.append(Character(C_HEADER))
  1802. data.append(toString(body: mBodies))
  1803. data.append(Character(C_HEADER))
  1804. if let media = String(data: Data(getMedia()), encoding: .windowsCP1250) {
  1805. data.append(media)
  1806. }
  1807. return data
  1808. }
  1809. public func toBytes() -> [UInt8] {
  1810. let data:String = pack()
  1811. var result: [UInt8] = Array(data.utf8)
  1812. //print("[bytes_processing] build bytes data:" + String(result.count) + ", media:" + String(getMedia().count))
  1813. if (!getMedia().isEmpty) {
  1814. for index in 0...getMedia().count - 1 {
  1815. result.append(getMedia()[index])
  1816. }
  1817. }
  1818. return result
  1819. }
  1820. private func toString(body : [String: String]) -> String {
  1821. if (S_ENTRY.isEmpty) { S_ENTRY.append(Character(C_ENTRY)) }
  1822. if (S_KEYVAL.isEmpty) { S_KEYVAL.append(Character(C_KEYVAL)) }
  1823. var result = ""
  1824. for (key, value) in body {
  1825. result += key + S_KEYVAL + value + S_ENTRY
  1826. }
  1827. if (!result.isEmpty) {
  1828. result = String(result.prefix(result.count - 1))
  1829. }
  1830. return result
  1831. }
  1832. private func toMediaBytes(image: String) -> [UInt8] {
  1833. if (image == "null") {
  1834. return [UInt8]()
  1835. }
  1836. if let data = NSData(base64Encoded: image, options: .ignoreUnknownCharacters) {
  1837. var buffer = [UInt8](repeating: 0, count: data.length)
  1838. data.getBytes(&buffer, length: data.length)
  1839. return buffer
  1840. }
  1841. return [UInt8]()
  1842. }
  1843. public func unpack(data: String) -> Bool {
  1844. var result = false
  1845. if (S_HEADER.isEmpty) { S_HEADER.append(Character(C_HEADER)) }
  1846. let headers = data.split(separator: Character(C_HEADER), maxSplits: 8, omittingEmptySubsequences: false)
  1847. if (headers.count == 8) {
  1848. mType = String(headers[0])
  1849. mVersion = String(headers[1])
  1850. mCode = String(headers[2])
  1851. mStatus = String(headers[3])
  1852. mPIN = String(headers[4])
  1853. mL_PIN = String(headers[5])
  1854. mBodies = toBodies(data: String(headers[6]))
  1855. mMedia = toMediaBytes(image: String(headers[7]))
  1856. result = true
  1857. }
  1858. return result
  1859. }
  1860. public func unpack(bytes_data: [UInt8]) -> Bool {
  1861. var result = false
  1862. let data = getData(bytes_data: bytes_data)
  1863. let headers = data.split(separator: Character(C_HEADER), maxSplits: 8, omittingEmptySubsequences: false)
  1864. if (headers.count >= 8) {
  1865. mType = String(headers[0])
  1866. mVersion = String(headers[1])
  1867. mCode = String(headers[2])
  1868. mStatus = String(headers[3])
  1869. mPIN = String(headers[4])
  1870. mL_PIN = String(headers[5])
  1871. mBodies = toBodies(data: String(headers[6]))
  1872. mMedia = getMedia(bytes_data: bytes_data)
  1873. result = true
  1874. }
  1875. else {
  1876. //print("[bytes_processing] Invalid header length: " + String(headers.count))
  1877. }
  1878. return result
  1879. }
  1880. private func toBodies(data: String) -> [String: String] {
  1881. var cvalues = [String: String]()
  1882. if (data.isEmpty || data == "") {
  1883. return cvalues
  1884. }
  1885. if (S_ENTRY.isEmpty) { S_ENTRY.append(Character(C_ENTRY)) }
  1886. if (S_KEYVAL.isEmpty) { S_KEYVAL.append(Character(C_KEYVAL)) }
  1887. let elements = data.split(separator: Character(C_ENTRY), omittingEmptySubsequences: false)
  1888. for element in elements {
  1889. let keyval = element.split(separator: Character(C_KEYVAL), omittingEmptySubsequences: false)
  1890. cvalues[String(keyval[0])] = String(keyval[1])
  1891. }
  1892. return cvalues
  1893. }
  1894. private func getData(bytes_data : [UInt8]) -> String {
  1895. var result = ""
  1896. if (S_HEADER.isEmpty) { S_HEADER.append(Character(C_HEADER)) }
  1897. var iLength = 0
  1898. for bData in bytes_data {
  1899. let chr = Character(UnicodeScalar(bData))
  1900. if (chr == Character(C_HEADER)) {
  1901. iLength = iLength + 1
  1902. if (iLength == 8) {
  1903. break
  1904. }
  1905. }
  1906. result.append(chr)
  1907. }
  1908. return result
  1909. }
  1910. private func getMedia(bytes_data: [UInt8]) -> [UInt8] {
  1911. var result:[UInt8] = [UInt8]()
  1912. if bytes_data.count > 0 {
  1913. var ml = getBodyAsInteger(key: MEDIA_LENGTH, default_value: 0)
  1914. if ml == 0 {
  1915. ml = getBodyAsInteger(key: FILE_SIZE, default_value: 0)
  1916. }
  1917. if ml > 0 {
  1918. let start = bytes_data.count - ml
  1919. for index in start...bytes_data.count - 1 {
  1920. result.append(bytes_data[index])
  1921. }
  1922. }
  1923. }
  1924. return result
  1925. }
  1926. public func toLogString() -> String {
  1927. var result = ""
  1928. result += ("[" + mType + "]")
  1929. result += ("[" + mVersion + "]")
  1930. result += ("[" + mCode + "]")
  1931. result += ("[" + mStatus + "]")
  1932. result += ("[" + mPIN + "]")
  1933. result += ("[" + mL_PIN + "]")
  1934. result += ("[" + toBodyLogString() + "]")
  1935. result += ("[" + String(mMedia.count) + "]")
  1936. return result
  1937. }
  1938. private func toBodyLogString() -> String {
  1939. if (S_ENTRY.isEmpty) { S_ENTRY.append(Character(C_ENTRY)) }
  1940. if (S_KEYVAL.isEmpty) { S_KEYVAL.append(Character(C_KEYVAL)) }
  1941. var result = ""
  1942. for (key, value) in mBodies {
  1943. result += "{" + key + "=" + value + "}"
  1944. }
  1945. return result
  1946. }
  1947. public func isOk() -> Bool {
  1948. return getBody(key: ERRCOD, default_value: "99") == "00"
  1949. }
  1950. }
  1951. public class CoreMessage_TMessageUtil {
  1952. private static var mTID = NSDate().timeIntervalSince1970 * 1000
  1953. public static func getTID() -> String {
  1954. mTID = Double(Int(mTID) + Int(1))
  1955. return String(Int(mTID))
  1956. }
  1957. public static func getString(json: Any, key: String) -> String {
  1958. return getString(json: json, key: key, def: "")
  1959. }
  1960. public static func getString(json: Any, key: String, def: String) -> String {
  1961. if let dict = json as? [String: Any], let value = dict[key] as? String {
  1962. if !value.isEmpty {
  1963. return value
  1964. }
  1965. }
  1966. return def
  1967. }
  1968. public static func getInt(json: Any, key: String, def: Int) -> Int {
  1969. if let dict = json as? [String: Any], let value = dict[key] as? Int {
  1970. return value
  1971. }
  1972. return def
  1973. }
  1974. public static func getIntAsString(json: Any, key: String, def: Int) -> String {
  1975. return String(getInt(json: json, key: key, def: def))
  1976. }
  1977. public static func getLong(json: Any, key: String, def: CLong) -> CLong {
  1978. if let dict = json as? [String: Any], let value = dict[key] as? CLong {
  1979. return value
  1980. }
  1981. return def
  1982. }
  1983. }
  1984. public class SSLibAlertController: UIAlertController {
  1985. public override func viewWillAppear(_ animated: Bool) {
  1986. super.viewWillAppear(animated)
  1987. // Customize the title's font
  1988. let titleFont = UIFont.boldSystemFont(ofSize: 16)
  1989. let titleAttributes = [NSAttributedString.Key.font: titleFont]
  1990. setValue(NSAttributedString(string: self.title ?? "", attributes: titleAttributes), forKey: "attributedTitle")
  1991. // Change the font for the message
  1992. let messageFont = UIFont.systemFont(ofSize: 14)
  1993. let messageAttributes = [NSAttributedString.Key.font: messageFont]
  1994. setValue(NSAttributedString(string: self.message ?? "", attributes: messageAttributes), forKey: "attributedMessage")
  1995. for i in self.actions {
  1996. let attributedText = NSAttributedString(string: i.title ?? "", attributes: [NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)])
  1997. guard let label = (i.value(forKey: "__representer") as AnyObject).value(forKey: "label") as? UILabel else { return }
  1998. label.attributedText = attributedText
  1999. }
  2000. }
  2001. }
  2002. public class SecureUserDefaultsSS {
  2003. static let shared = SecureUserDefaultsSS()
  2004. private let defaults: UserDefaults
  2005. private let prefsKeyAlias = "_iosx_security_master_key_easysoft_"
  2006. // Initialization with a SymmetricKey
  2007. init(defaults: UserDefaults = .standard) {
  2008. self.defaults = defaults
  2009. do {
  2010. try generateAndStorePrefsKey()
  2011. } catch {
  2012. }
  2013. }
  2014. func generateAndStorePrefsKey() throws {
  2015. if try isKeyExists(keyAliasCode: prefsKeyAlias) {
  2016. return
  2017. }
  2018. let key = SymmetricKey(size: .bits256)
  2019. let keyData = key.withUnsafeBytes { Data($0) }
  2020. let query: [String: Any] = [
  2021. kSecClass as String: kSecClassKey,
  2022. kSecAttrApplicationTag as String: prefsKeyAlias,
  2023. kSecValueData as String: keyData,
  2024. kSecAttrAccessible as String: kSecAttrAccessibleAfterFirstUnlock
  2025. ]
  2026. SecItemDelete(query as CFDictionary) // Remove if it exists
  2027. let status = SecItemAdd(query as CFDictionary, nil)
  2028. guard status == errSecSuccess else {
  2029. throw NSError(domain: "KeychainError", code: Int(status), userInfo: nil)
  2030. }
  2031. }
  2032. func isKeyExists(keyAliasCode: String) throws -> Bool {
  2033. let query: [String: Any] = [
  2034. kSecClass as String: kSecClassKey,
  2035. kSecAttrApplicationTag as String: keyAliasCode,
  2036. kSecReturnData as String: false // We only check existence, not retrieve data
  2037. ]
  2038. let status = SecItemCopyMatching(query as CFDictionary, nil)
  2039. if status == errSecItemNotFound {
  2040. return false
  2041. } else if status == errSecSuccess {
  2042. return true
  2043. } else {
  2044. throw NSError(domain: "KeychainError", code: Int(status), userInfo: nil)
  2045. }
  2046. }
  2047. func getPrefsKey() throws -> SymmetricKey {
  2048. let query: [String: Any] = [
  2049. kSecClass as String: kSecClassKey,
  2050. kSecAttrApplicationTag as String: prefsKeyAlias,
  2051. kSecReturnData as String: true
  2052. ]
  2053. var item: CFTypeRef?
  2054. let status = SecItemCopyMatching(query as CFDictionary, &item)
  2055. guard status == errSecSuccess else {
  2056. throw NSError(domain: "KeychainError", code: Int(status), userInfo: nil)
  2057. }
  2058. guard let keyData = item as? Data else {
  2059. throw NSError(domain: "KeyRetrievalError", code: -1, userInfo: nil)
  2060. }
  2061. return SymmetricKey(data: keyData)
  2062. }
  2063. func encrypt(data: Data) throws -> Data {
  2064. let key = try getPrefsKey()
  2065. let sealedBox = try AES.GCM.seal(data, using: key)
  2066. return sealedBox.combined!
  2067. }
  2068. func decrypt(data: Data) throws -> Data {
  2069. let key = try getPrefsKey()
  2070. let sealedBox = try AES.GCM.SealedBox(combined: data)
  2071. return try AES.GCM.open(sealedBox, using: key)
  2072. }
  2073. func set<T: Codable>(_ value: T, forKey key: String) {
  2074. let encoder = JSONEncoder()
  2075. guard let encodedData = try? encoder.encode(value),
  2076. let encryptedData = try? encrypt(data: encodedData) else {
  2077. print("Failed to encrypt data")
  2078. return
  2079. }
  2080. defaults.set(encryptedData, forKey: key)
  2081. }
  2082. // Retrieve a value
  2083. func value<T: Codable>(forKey key: String) -> T? {
  2084. guard let encryptedData = defaults.data(forKey: key),
  2085. let decryptedData = try? decrypt(data: encryptedData) else {
  2086. print("Failed to decrypt data")
  2087. return nil
  2088. }
  2089. let decoder = JSONDecoder()
  2090. return try? decoder.decode(T.self, from: decryptedData)
  2091. }
  2092. // Remove a value
  2093. func removeValue(forKey key: String) {
  2094. defaults.removeObject(forKey: key)
  2095. }
  2096. func sync() {
  2097. defaults.synchronize()
  2098. }
  2099. }