SecurityShield.swift 103 KB

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