Skip to content

Commit b3fba68

Browse files
committed
swiftlint lint --fix
1 parent 0c84a2d commit b3fba68

14 files changed

+340
-339
lines changed

FrameworkClientApp/FishHook.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,46 +46,46 @@ private func replaceSymbolAtImage(
4646
var dataCmd: UnsafeMutablePointer<segment_command_64>!
4747
var symtabCmd: UnsafeMutablePointer<symtab_command>!
4848
var dynamicSymtabCmd: UnsafeMutablePointer<dysymtab_command>!
49-
49+
5050
guard var curCmdPointer = UnsafeMutableRawPointer(bitPattern: UInt(bitPattern: image)+UInt(MemoryLayout<mach_header_64>.size)) else { return }
51-
51+
5252
for _ in 0..<image.pointee.ncmds {
5353
let curCmd = curCmdPointer.assumingMemoryBound(to: segment_command_64.self)
54-
54+
5555
if curCmd.pointee.cmd == LC_SEGMENT_64 {
5656
let curCmdNameOffset = MemoryLayout.size(ofValue: curCmd.pointee.cmd) + MemoryLayout.size(ofValue: curCmd.pointee.cmdsize)
5757
let curCmdNamePointer = curCmdPointer.advanced(by: curCmdNameOffset).assumingMemoryBound(to: Int8.self)
5858
let curCmdName = String(cString: curCmdNamePointer)
59-
if (curCmdName == SEG_LINKEDIT) {
59+
if curCmdName == SEG_LINKEDIT {
6060
linkeditCmd = curCmd
61-
} else if (curCmdName == SEG_DATA) {
61+
} else if curCmdName == SEG_DATA {
6262
dataCmd = curCmd
6363
}
6464
} else if curCmd.pointee.cmd == LC_SYMTAB {
6565
symtabCmd = UnsafeMutablePointer<symtab_command>(OpaquePointer(curCmd))
6666
} else if curCmd.pointee.cmd == LC_DYSYMTAB {
6767
dynamicSymtabCmd = UnsafeMutablePointer<dysymtab_command>(OpaquePointer(curCmd))
6868
}
69-
69+
7070
curCmdPointer += Int(curCmd.pointee.cmdsize)
7171
}
72-
72+
7373
if linkeditCmd == nil || symtabCmd == nil || dynamicSymtabCmd == nil || dataCmd == nil {
7474
return
7575
}
76-
76+
7777
let linkedBase = slide + Int(linkeditCmd.pointee.vmaddr) - Int(linkeditCmd.pointee.fileoff)
7878
let symtab = UnsafeMutablePointer<nlist_64>(bitPattern: linkedBase + Int(symtabCmd.pointee.symoff))
7979
let strtab = UnsafeMutablePointer<UInt8>(bitPattern: linkedBase + Int(symtabCmd.pointee.stroff))
8080
let indirectsym = UnsafeMutablePointer<UInt32>(bitPattern: linkedBase + Int(dynamicSymtabCmd.pointee.indirectsymoff))
81-
81+
8282
if symtab == nil || strtab == nil || indirectsym == nil {
8383
return
8484
}
85-
85+
8686
for tmp in 0..<dataCmd.pointee.nsects {
8787
let curSection = UnsafeMutableRawPointer(dataCmd).advanced(by: MemoryLayout<segment_command_64>.size + MemoryLayout<section_64>.size*Int(tmp)).assumingMemoryBound(to: section_64.self)
88-
88+
8989
// symbol_pointers sections
9090
if curSection.pointee.flags == S_LAZY_SYMBOL_POINTERS {
9191
replaceSymbolPointerAtSection(curSection, symtab: symtab!, strtab: strtab!, indirectsym: indirectsym!, slide: slide, symbolName: symbol, newMethod: newMethod, oldMethod: &oldMethod)
@@ -109,11 +109,11 @@ private func replaceSymbolPointerAtSection(
109109
) {
110110
let indirectSymVmAddr = indirectsym.advanced(by: Int(section.pointee.reserved1))
111111
let sectionVmAddr = UnsafeMutablePointer<UnsafeMutableRawPointer>(bitPattern: slide+Int(section.pointee.addr))
112-
112+
113113
if sectionVmAddr == nil {
114114
return
115115
}
116-
116+
117117
for tmp in 0..<Int(section.pointee.size)/MemoryLayout<UnsafeMutableRawPointer>.size {
118118
let curIndirectSym = indirectSymVmAddr.advanced(by: tmp)
119119
if curIndirectSym.pointee == INDIRECT_SYMBOL_ABS || curIndirectSym.pointee == INDIRECT_SYMBOL_LOCAL {

FrameworkClientApp/ViewController.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ class RuntimeClass {
1717

1818
internal class ViewController: UIViewController {
1919
@IBOutlet weak var result: UITextView!
20-
20+
2121
override func viewDidAppear(_ animated: Bool) {
2222
var message = ""
23-
23+
2424
#if arch(arm64)
2525
message += executeChecksForArm64()
2626
#endif
27-
27+
2828
// Runtime Check
2929
let test = RuntimeClass.init()
3030
_ = test.runtimeModifiedFunction()
@@ -35,7 +35,7 @@ internal class ViewController: UIViewController {
3535
selector: #selector(RuntimeClass.runtimeModifiedFunction),
3636
isClassMethod: false
3737
)
38-
38+
3939
message += """
4040
Jailbreak? \(IOSSecuritySuite.amIJailbroken())
4141
Jailbreak with fail msg? \(IOSSecuritySuite.amIJailbrokenWithFailMessage())
@@ -51,7 +51,7 @@ internal class ViewController: UIViewController {
5151
Am I runtime hooked? \(amIRuntimeHooked)
5252
Am I proxied? \(IOSSecuritySuite.amIProxied())
5353
"""
54-
54+
5555
result.text = message
5656
}
5757
}
@@ -60,19 +60,19 @@ internal class ViewController: UIViewController {
6060
extension ViewController {
6161
func executeChecksForArm64() -> String {
6262
// executeAntiHook()
63-
63+
6464
// MSHook Check
6565
func msHookReturnFalse(takes: Int) -> Bool {
6666
return false /// add breakpoint at here to test `IOSSecuritySuite.hasBreakpointAt`
6767
}
68-
68+
6969
typealias FunctionType = @convention(thin) (Int) -> (Bool)
7070
func getSwiftFunctionAddr(_ function: @escaping FunctionType) -> UnsafeMutableRawPointer {
7171
return unsafeBitCast(function, to: UnsafeMutableRawPointer.self)
7272
}
73-
73+
7474
let funcAddr = getSwiftFunctionAddr(msHookReturnFalse)
75-
75+
7676
return """
7777
Am I MSHooked? \(IOSSecuritySuite.amIMSHooked(funcAddr))
7878
Application executable file hash value? \(IOSSecuritySuite.getMachOFileHashValue() ?? "")
@@ -84,34 +84,34 @@ extension ViewController {
8484
Watchpoint? \(testWatchpoint())
8585
"""
8686
}
87-
87+
8888
func testWatchpoint() -> Bool {
89-
89+
9090
// Uncomment these \/ and set a watch point to check the feature
9191
// var ptr = malloc(9)
9292
// var count = 3
9393
return IOSSecuritySuite.hasWatchpoint()
9494
}
95-
95+
9696
func executeAntiHook() {
9797
typealias MyPrint = @convention(thin) (Any..., String, String) -> Void
9898
func myPrint(_ items: Any..., separator: String = " ", terminator: String = "\n") {
9999
print("print has been hooked")
100100
}
101-
101+
102102
let myprint: MyPrint = myPrint
103103
let myPrintPointer = unsafeBitCast(myprint, to: UnsafeMutableRawPointer.self)
104104
var oldMethod: UnsafeMutableRawPointer?
105-
105+
106106
// simulating hook
107107
replaceSymbol(
108108
"$ss5print_9separator10terminatoryypd_S2StF",
109109
newMethod: myPrintPointer,
110110
oldMethod: &oldMethod
111111
)
112-
112+
113113
print("print hasn't been hooked")
114-
114+
115115
// antiHook
116116
IOSSecuritySuite.denySymbolHook("$ss5print_9separator10terminatoryypd_S2StF")
117117
print("print has been antiHooked")

IOSSecuritySuite.xcodeproj/project.pbxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@
281281
/* Begin PBXShellScriptBuildPhase section */
282282
70B0BBC7226F3A5F000CFB39 /* SwiftLint */ = {
283283
isa = PBXShellScriptBuildPhase;
284+
alwaysOutOfDate = 1;
284285
buildActionMask = 2147483647;
285286
files = (
286287
);

IOSSecuritySuite/DebuggerChecker.swift

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,64 +15,64 @@ internal class DebuggerChecker {
1515
var mib: [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]
1616
var size = MemoryLayout<kinfo_proc>.stride
1717
let sysctlRet = sysctl(&mib, UInt32(mib.count), &kinfo, &size, nil, 0)
18-
18+
1919
if sysctlRet != 0 {
2020
print("Error occured when calling sysctl(). The debugger check may not be reliable")
2121
}
22-
22+
2323
return (kinfo.kp_proc.p_flag & P_TRACED) != 0
2424
}
25-
25+
2626
static func denyDebugger() {
2727
// bind ptrace()
2828
let pointerToPtrace = UnsafeMutableRawPointer(bitPattern: -2)
2929
let ptracePtr = dlsym(pointerToPtrace, "ptrace")
3030
typealias PtraceType = @convention(c) (CInt, pid_t, CInt, CInt) -> CInt
3131
let ptrace = unsafeBitCast(ptracePtr, to: PtraceType.self)
32-
32+
3333
// PT_DENY_ATTACH == 31
3434
let ptraceRet = ptrace(31, 0, 0, 0)
35-
35+
3636
if ptraceRet != 0 {
3737
print("Error occured when calling ptrace(). Denying debugger may not be reliable")
3838
}
3939
}
40-
40+
4141
#if arch(arm64)
4242
static func hasBreakpointAt(
4343
_ functionAddr: UnsafeRawPointer,
4444
functionSize: vm_size_t?
4545
) -> Bool {
4646
let funcAddr = vm_address_t(UInt(bitPattern: functionAddr))
47-
47+
4848
var vmStart: vm_address_t = funcAddr
4949
var vmSize: vm_size_t = 0
5050
let vmRegionInfo = UnsafeMutablePointer<Int32>.allocate(
5151
capacity: MemoryLayout<vm_region_basic_info_64>.size/4
5252
)
53-
53+
5454
defer {
5555
vmRegionInfo.deallocate()
5656
}
57-
57+
5858
var vmRegionInfoCount: mach_msg_type_number_t = mach_msg_type_number_t(VM_REGION_BASIC_INFO_64)
5959
var objectName: mach_port_t = 0
60-
60+
6161
let ret = vm_region_64(
6262
mach_task_self_, &vmStart,
6363
&vmSize, VM_REGION_BASIC_INFO_64,
6464
vmRegionInfo, &vmRegionInfoCount,
6565
&objectName
6666
)
67-
67+
6868
if ret != KERN_SUCCESS {
6969
return false
7070
}
71-
71+
7272
let vmRegion = vmRegionInfo.withMemoryRebound(
7373
to: vm_region_basic_info_64.self, capacity: 1, { $0 }
7474
)
75-
75+
7676
if vmRegion.pointee.protection == (VM_PROT_READ | VM_PROT_EXECUTE) {
7777
let armBreakpointOpcode = 0xe7ffdefe
7878
let arm64BreakpointOpcode = 0xd4200000
@@ -81,7 +81,7 @@ internal class DebuggerChecker {
8181
if let size = functionSize, size < judgeSize {
8282
judgeSize = size
8383
}
84-
84+
8585
for valueToOffset in 0..<(judgeSize / 4) {
8686
if (instructionBegin.advanced(
8787
by: Int(valueToOffset)
@@ -92,31 +92,31 @@ internal class DebuggerChecker {
9292
}
9393
}
9494
}
95-
95+
9696
return false
9797
}
98-
98+
9999
static func hasWatchpoint() -> Bool {
100100
var threads: thread_act_array_t?
101101
var threadCount: mach_msg_type_number_t = 0
102102
var hasWatchpoint = false
103-
103+
104104
if task_threads(mach_task_self_, &threads, &threadCount) == KERN_SUCCESS {
105105
var threadStat = arm_debug_state64_t()
106106
let capacity = MemoryLayout<arm_debug_state64_t>.size/MemoryLayout<natural_t>.size
107-
107+
108108
let threadStatPointer = withUnsafeMutablePointer(to: &threadStat, {
109109
$0.withMemoryRebound(to: natural_t.self, capacity: capacity, { $0 })
110110
})
111-
111+
112112
var count = mach_msg_type_number_t(
113113
MemoryLayout<arm_debug_state64_t>.size/MemoryLayout<UInt32>.size
114114
)
115-
115+
116116
guard let threads = threads else {
117117
return false
118118
}
119-
119+
120120
for threadIndex in 0..<threadCount where thread_get_state(
121121
threads[Int(threadIndex)],
122122
ARM_DEBUG_STATE64,
@@ -128,21 +128,21 @@ internal class DebuggerChecker {
128128
).pointee.__wvr.0 != 0
129129
if hasWatchpoint { break }
130130
}
131-
131+
132132
vm_deallocate(
133133
mach_task_self_,
134134
UInt(bitPattern: threads),
135135
vm_size_t(threadCount * UInt32(MemoryLayout<thread_act_t>.size))
136136
)
137137
}
138-
138+
139139
return hasWatchpoint
140140
}
141141
#endif
142-
142+
143143
static func isParentPidUnexpected() -> Bool {
144144
let parentPid: pid_t = getppid()
145-
145+
146146
return parentPid != 1 // LaunchD is pid 1
147147
}
148148
}

0 commit comments

Comments
 (0)