Repository Public License
1// ORIX Secure2// File: App/Sources/Debug/LaunchOptions.swift3// Description: Launch arguments used by UI tests and screenshots: isolated in-memory store, reset, demo answers, start screen,4// appearance. Demo content is checklist answers and reports produced by the real engines — never fake findings.5// -ORIXSampleFile YES / -ORIXSampleFolder YES write real test files in tmp and hand them to the file tools.6// -ORIXUITest YES -ORIXReset YES -ORIXDemo YES -ORIXSection <destination> -ORIXAppearance light|dark -ORIXLink <url>7//8// Author: Simon-Pierre Boucher9// Contact: contact@spboucher.ai10import Foundation11import ORIXSecureEngines12import UIKit1314struct LaunchOptions {15 var uiTest = false16 var reset = false17 var demo = false18 var section: Destination?19 var appearance: AppearancePreference?20 var link: String?21 var sampleFile = false22 var sampleFolder = false2324 static var current: LaunchOptions {25 var options = LaunchOptions()26 #if DEBUG27 let defaults = UserDefaults.standard28 options.uiTest = defaults.bool(forKey: "ORIXUITest")29 options.reset = defaults.bool(forKey: "ORIXReset")30 options.demo = defaults.bool(forKey: "ORIXDemo")31 options.section = defaults.string(forKey: "ORIXSection").flatMap(Destination.init(rawValue:))32 options.appearance = defaults.string(forKey: "ORIXAppearance").flatMap(AppearancePreference.init(rawValue:))33 options.link = defaults.string(forKey: "ORIXLink")34 options.sampleFile = defaults.bool(forKey: "ORIXSampleFile")35 options.sampleFolder = defaults.bool(forKey: "ORIXSampleFolder")36 #endif37 return options38 }3940 var inMemory: Bool { uiTest }4142 /// UI tests use their own defaults suite so they never touch a developer's settings.43 var defaults: UserDefaults {44 uiTest ? (UserDefaults(suiteName: "ai.spboucher.orix.secure.uitest") ?? .standard) : .standard45 }4647 func apply(to model: AppModel) {48 #if DEBUG49 if uiTest { UIView.setAnimationsEnabled(false) }50 if let appearance { model.settings.appearance = appearance }51 if uiTest { model.settings.hasSeenWelcome = !UserDefaults.standard.bool(forKey: "ORIXWelcome") }52 if demo { DemoContent.seed(model) }53 if sampleFile {54 model.router.pendingFile = DemoContent.sampleFile()55 model.router.open(.fileScanner)56 } else if sampleFolder {57 model.router.pendingFolder = DemoContent.sampleFolder()58 model.router.open(.fileCleanup)59 } else if let link {60 model.router.pendingLink = link61 model.router.open(.linkAnalyzer)62 } else if let section {63 model.router.open(section)64 }65 #endif66 }67}6869#if DEBUG70enum DemoContent {71 /// Answers part of the checklists the way a person would after a first pass, then saves the resulting reports.72 static func seed(_ model: AppModel) {73 let good = ["sec.updates.current", "sec.updates.automatic", "sec.passcode.strength", "sec.findmy", "sec.account.2fa", "sec.account.devices",74 "sec.profiles.unknown", "sec.safari.fraud", "priv.tracking", "priv.location.review", "priv.camera.review", "priv.mic.review", "priv.previews"]75 for id in good {76 if let item = ChecklistCatalog.item(id) { model.answer(item.expected, for: id) }77 }78 // Two settings reported as not yet in order, one optional protection left off, one not applicable.79 model.answer(.no, for: "sec.sdp")80 model.answer(.no, for: "priv.report")81 model.answer(.no, for: "sec.lockdown")82 model.answer(.notApplicable, for: "sec.profiles.mdm")83 model.store.save(ReportBuilder.security(model.assessment, device: model.device))84 model.store.save(ReportBuilder.privacy(model.privacy))85 model.store.save(ReportBuilder.device(model.diagnosticsEngine.diagnostics(model.device), advice: model.diagnosticsEngine.advice(model.device)))86 }8788 /// A real file for the scanner: a ZIP archive (one stored entry, one traversal-named entry) under a document-looking name.89 static func sampleFile() -> URL {90 let folder = FileManager.default.temporaryDirectory.appendingPathComponent("ORIXSecureSamples", isDirectory: true)91 try? FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true)92 let url = folder.appendingPathComponent("invoice.pdf.zip")93 func le16(_ v: Int) -> [UInt8] { [UInt8(v & 0xff), UInt8((v >> 8) & 0xff)] }94 func le32(_ v: Int) -> [UInt8] { [UInt8(v & 0xff), UInt8((v >> 8) & 0xff), UInt8((v >> 16) & 0xff), UInt8((v >> 24) & 0xff)] }95 var data: [UInt8] = []96 var central: [UInt8] = []97 var count = 098 for (name, body) in [("readme.txt", Array("hello".utf8)), ("../../outside.sh", Array("#!/bin/sh\n".utf8))] {99 let offset = data.count100 let nameBytes = Array(name.utf8)101 data += [0x50, 0x4b, 0x03, 0x04] + le16(20) + le16(0) + le16(0) + le16(0) + le16(0) + le32(0) + le32(body.count) + le32(body.count) + le16(nameBytes.count) + le16(0) + nameBytes + body102 central += [0x50, 0x4b, 0x01, 0x02] + le16(20) + le16(20) + le16(0) + le16(0) + le16(0) + le16(0) + le32(0) + le32(body.count) + le32(body.count)103 central += le16(nameBytes.count) + le16(0) + le16(0) + le16(0) + le16(0) + le32(0) + le32(offset) + nameBytes104 count += 1105 }106 let start = data.count107 data += central108 data += [0x50, 0x4b, 0x05, 0x06] + le16(0) + le16(0) + le16(count) + le16(count) + le32(central.count) + le32(start) + le16(0)109 try? Data(data).write(to: url)110 return url111 }112113 /// A real folder for file cleanup: three byte-identical files, one different file of the same size, one larger file.114 static func sampleFolder() -> URL {115 let folder = FileManager.default.temporaryDirectory.appendingPathComponent("ORIXSecureSampleFolder", isDirectory: true)116 try? FileManager.default.removeItem(at: folder)117 try? FileManager.default.createDirectory(at: folder.appendingPathComponent("Archive"), withIntermediateDirectories: true)118 let same = Data(repeating: 0x41, count: 200_000)119 try? same.write(to: folder.appendingPathComponent("report.pdf"))120 try? same.write(to: folder.appendingPathComponent("report copy.pdf"))121 try? same.write(to: folder.appendingPathComponent("Archive/report-2025.pdf"))122 try? Data(repeating: 0x42, count: 200_000).write(to: folder.appendingPathComponent("other.pdf"))123 try? Data(repeating: 0x43, count: 1_500_000).write(to: folder.appendingPathComponent("video.mov"))124 return folder125 }126}127#endif128