why not hook NSBundle infoDictionary function?
[NSBundle aspect_hookSelector:@selector(infoDictionary) withOptions:AspectPositionInstead usingBlock:^(id<AspectInfo> aspectInfo) { NSDictionary *dictInfoDictionary; NSInvocation *invocationInfoDictionary = aspectInfo.originalInvocation; [invocationInfoDictionary invoke]; [invocationInfoDictionary getReturnValue:&dictInfoDictionary]; NSMutableDictionary *dictInfoDictionaryNew =[NSMutableDictionary dictionaryWithDictionary:dictInfoDictionary]; dictInfoDictionaryNew[@"CFBundleIdentifier"] = @"com.naruto1.demo1"; NSLog(@"[%s,%d] dictInfoDictionary:%@",FUNCTION,LINE,dictInfoDictionaryNew); [invocationInfoDictionary setReturnValue:&dictInfoDictionaryNew]; } error:NULL];
when I write this code: NSLog(@"[%s,%d] dictInfoDictionary:%@",FUNCTION,LINE,[[NSBundle mainBundle] infoDictionary]);
console: *** -[__NSDictionaryM retain]: message sent to deallocated instance 0x155ef1580
Aspects is open source - I welcome you to debug and provide a pull request for this.