This crash was caused by multiple threads accessing the lastHypothesis function of the UIDictationController, causing a wild pointer problem
Lock the setLastHypothesis
and lastHypothesis
functions of UIDictationController,
// hd_hookMethod is hook components similar to aspect
[NSClassFromString(@"UIDictationController") hd_hookMethod:NSSelectorFromString(@"setLastHypothesis:") option:HDHookOptionInstead handle:^(HDInvocation *invocation){
[[invocation.target hdcore_lock] lock];
[invocation invoke];
[[invocation.target hdcore_lock] unlock];
} error:nil];
[NSClassFromString(@"UIDictationController") hd_hookMethod:NSSelectorFromString(@"lastHypothesis") option:HDHookOptionInstead handle:^NSString * (HDInvocation *invocation){
[[invocation.target hdcore_lock] lock];
__autoreleasing NSString *orgHypothesis;
[invocation invokeWithReturnValue:&orgHypothesis];
orgHypothesis = orgHypothesis.mutableCopy;
[[invocation.target hdcore_lock] unlock];
return orgHypothesis;
} error:nil];
The solution comes from the HuolalaTech team, I just translated it into English
https://juejin.cn/post/7396463744186515465