static NSString
*
nsDomainString
=
@
"com.witchan.precise-time"
;
static NSString
*
nsNotificationString
=
@
"com.witchan.precise-time/preferences.changed"
;
static
BOOL
enabled;
static void notificationCallback(CFNotificationCenterRef center, void
*
observer, CFStringRef name, const void
*
object
, CFDictionaryRef userInfo) {
NSNumber
*
enabledValue
=
(NSNumber
*
)[[NSUserDefaults standardUserDefaults] objectForKey:@
"enabled"
inDomain:nsDomainString];
enabled
=
(enabledValue)? [enabledValue boolValue] : YES;
NSLog(@
"=witchan= 插件状态:%d"
, enabled);
}
%
hook UIStatusBarServer
%
property
(nonatomic, strong) StatusBarUpdater
*
updater;
/
/
SCD_Struct_UI104结构请从ida pro复制
-
(void)_receivedStatusBarData:(SCD_Struct_UI104
*
)arg1 actions:(
int
)arg2 animated:(
BOOL
)arg3 {
if
(
self
.updater
=
=
nil) {
self
.updater
=
[[StatusBarUpdater alloc] init];
}
if
(!enabled) {
[
self
.updater stopUpdating];
%
orig;
return
;
}
/
/
获取当前时间
NSDate
*
currentDate
=
[NSDate date];
/
/
创建日期格式化器
NSDateFormatter
*
dateFormatter
=
[[NSDateFormatter alloc] init];
/
/
设置日期格式
[dateFormatter setDateFormat:@
"HH:mm:ss"
];
/
/
24
小时制
/
/
将当前日期格式化为字符串
NSString
*
formattedTime
=
[dateFormatter stringFromDate:currentDate];
NSLog(@
"=witchan= now timeString: %@"
, formattedTime);
/
/
_statusBarData.var1
=
strcpy(ret
-
>personName,
"12:33:22"
);
strcpy(arg1
-
>var1, [formattedTime UTF8String]);
%
orig(arg1, arg2, arg3);
NSLog(@
"=witchan= _receivedStatusBarData: %d %d"
, arg2, arg3);
/
/
创建一个新结构体用于复制
/
/
SCD_Struct_UI104 copy;
/
/
memcpy(©, arg1, sizeof(SCD_Struct_UI104));
/
/
正确复制结构体数据
[
self
.updater updateStatusBarData:
*
arg1 statusBarServer:
self
];
[
self
.updater startUpdating];
}
%
end
%
ctor {
NSLog(@
"=witchan= precise time plugin load success"
);
notificationCallback(NULL, NULL, NULL, NULL, NULL);
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, notificationCallback, (CFStringRef)nsNotificationString, NULL, CFNotificationSuspensionBehaviorCoalesce);
}