SecurityShield.swift 135 KB

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