-
Notifications
You must be signed in to change notification settings - Fork 5
/
InjectCheck.swift
131 lines (108 loc) · 4.34 KB
/
InjectCheck.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
// InjectCheck.swift
// InjectCheck
//
// Created by D00mfist
//
import Foundation
class InjectCheck {
let consoleIO = ConsoleIO()
let checkApp = CheckApp()
func getOption(_ option: String) -> (option:OptionType, value: String) {
return (OptionType(value: option), option)
}
func staticMode() {
let argCount = CommandLine.argc
let argument = CommandLine.arguments[1]
let (option, value) = getOption(argument.substring(from: argument.index(argument.startIndex, offsetBy: 1)))
//For Debugging
print("Argument count: \(argCount) Option: \(option) value: \(value)")
switch option {
case .allApps:
if argCount != 2 {
if argCount > 2 {
print("Too many arguments for option \(option.rawValue)")
} else {
print("Too few arguments for option \(option.rawValue)")
}
consoleIO.printUsage()
} else {
if value == "All" {
//print("Selected All Option")
print("Checking All Applications")
//Run all function
let appPath = "/Applications"
let fileManager = FileManager.default
do {
let appsArray = try fileManager.contentsOfDirectory(atPath: appPath)
//print(appsArray)
let justApps = appsArray.filter { $0 != ".DS_Store" && $0 != ".localized" && $0 != "Utilities"}
for app in justApps {
print(" ================ " + app + " ================ ")
//testing
let mybundle = Bundle(path : "/Applications/" + app)
let myURL = mybundle?.bundleURL
let name = mybundle?.object(forInfoDictionaryKey: kCFBundleNameKey as String)
//let appName = name as! String
// print("The Application Name is " + appName)
var codeRef: SecStaticCode? = nil
SecStaticCodeCreateWithPath(myURL! as CFURL, [], &codeRef)
checkApp.verifyHardenedRuntimeAndProblematicEntitlements(applicationName: app, secStaticCode: codeRef!)
checkApp.electronCheck(pathToapplication: "/Applications" + app)
}
} catch {
print(error)
}
} else {
consoleIO.printUsage()
}
}
case .oneApp:
if argCount != 3 {
if argCount > 3 {
print("Too many arguments for option \(option.rawValue)")
} else {
print("Too few arguments for option \(option.rawValue)")
}
consoleIO.printUsage()
} else {
let pathtoApp = CommandLine.arguments[2]
if value == "p" {
//print("Selected Path Option")
print("Running on \(pathtoApp)")
//Run single path function
let mybundle = Bundle(path :pathtoApp)
let myURL = mybundle?.bundleURL
let name = mybundle?.object(forInfoDictionaryKey: kCFBundleNameKey as String)
let appName = name as! String
print("The Application Name is " + appName)
var codeRef: SecStaticCode? = nil
SecStaticCodeCreateWithPath(myURL! as CFURL, [], &codeRef)
checkApp.verifyHardenedRuntimeAndProblematicEntitlements(applicationName: appName, secStaticCode: codeRef!)
checkApp.electronCheck(pathToapplication: pathtoApp)
} else {
consoleIO.printUsage()
}
}
case .help:
consoleIO.printUsage()
case .unknown:
print("Unknown option \(value)")
consoleIO.printUsage()
}
}
enum OptionType: String {
case allApps = "All"
case oneApp = "p"
case help = "h"
case unknown
init(value: String) {
switch value {
case "All": self = .allApps
case "p": self = .oneApp
case "h": self = .help
default: self = .unknown
}
}
}
}