diff --git a/HCaptcha/Classes/HCaptchaDebugInfo.swift b/HCaptcha/Classes/HCaptchaDebugInfo.swift index 24ed189..1ebea8d 100644 --- a/HCaptcha/Classes/HCaptchaDebugInfo.swift +++ b/HCaptcha/Classes/HCaptchaDebugInfo.swift @@ -2,7 +2,7 @@ // HCaptchaDebugInfo.m // HCaptcha // -// Copyright © 2022 HCaptcha. All rights reserved. +// Copyright © 2024 HCaptcha. All rights reserved. // import Foundation @@ -16,11 +16,11 @@ extension String { } } -private func updateInfoFor(_ image: String, _ ctx: UnsafeMutablePointer) { +private func updateInfoFor(_ image: String, _ ctx: UnsafeMutablePointer, depth: UInt32 = 16) { var count: UInt32 = 0 if let imagePtr = (image as NSString).utf8String { let classes = objc_copyClassNamesForImage(imagePtr, &count) - for cls in UnsafeBufferPointer>(start: classes, count: Int(count)) { + for cls in UnsafeBufferPointer>(start: classes, count: Int(min(depth, count))) { CC_MD5_Update(ctx, cls, CC_LONG(strlen(cls))) } classes?.deallocate() @@ -53,6 +53,8 @@ class HCaptchaDebugInfo { } private class func buildDebugInfo() -> [String] { + let depth: UInt32 = 16 + var depsCount = 0, sysCount = 0 let depsCtx = UnsafeMutablePointer.allocate(capacity: 1) let sysCtx = UnsafeMutablePointer.allocate(capacity: 1) let appCtx = UnsafeMutablePointer.allocate(capacity: 1) @@ -67,6 +69,16 @@ class HCaptchaDebugInfo { let systemFramework = image.contains("/Library/PrivateFrameworks/") || image.contains("/System/Library/Frameworks/") + if systemFramework && sysCount < depth { + sysCount += 1 + } else if !systemFramework && depsCount < depth { + depsCount += 1 + } else if sysCount < depth || depsCount < depth { + continue + } else { + break + } + let md5Ctx = systemFramework ? sysCtx : depsCtx updateInfoFor(image, md5Ctx) }