From 0bb0567ec42e48f4602e3ab7dbebe00d5a07b244 Mon Sep 17 00:00:00 2001 From: Naville <403799106@qq.com> Date: Sat, 12 Mar 2016 14:43:07 +0000 Subject: [PATCH] More OCRuntime --- .gitignore | 1 + Hooks/API/ObjCRuntime.xm | 56 ++++++++++++++++++++++++++++++++++++++-- VERSION | 2 +- 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 40548ec..a484cc2 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ wax.txt *.log theos Cycript.framework +*.zip diff --git a/Hooks/API/ObjCRuntime.xm b/Hooks/API/ObjCRuntime.xm index b6afc9c..20c7651 100644 --- a/Hooks/API/ObjCRuntime.xm +++ b/Hooks/API/ObjCRuntime.xm @@ -9,8 +9,6 @@ const char *object_getClassName(id obj) objc_getMetaClass(const char *name) IMP class_getMethodImplementation(Class cls, SEL name) BOOL class_respondsToSelector(Class cls, SEL sel) -class_addMethod(Class cls, SEL name, IMP imp, - const char *types) class_replaceMethod(Class cls, SEL name, IMP imp, const char *types) @@ -19,6 +17,7 @@ And Runtime Method Implementation Related Funcs */ + //Old Func Pointers Class (*old_NSClassFromString)(NSString *aClassName); NSString* (*old_NSStringFromClass)(Class aClass); @@ -26,6 +25,8 @@ NSString* (*old_NSStringFromProtocol)(Protocol* proto); Protocol* (*old_NSProtocolFromString)(NSString* namestr); NSString* (*old_NSStringFromSelector)(SEL aSelector); SEL (*old_NSSelectorFromString)(NSString* aSelectorName); +BOOL (*old_class_addMethod)(Class cls, SEL name, IMP imp,const char *types); +BOOL (*old_class_addIvar)(Class cls, const char *name, size_t size,uint8_t alignment, const char *types); //New Func @@ -91,6 +92,55 @@ SEL new_NSSelectorFromString(NSString* aSelectorName){ } return old_NSSelectorFromString(aSelectorName); +} +BOOL new_class_addMethod(Class cls, SEL name, IMP imp,const char *types){ + if(WTShouldLog){ + NSString* TypeString=[NSString stringWithUTF8String:types]; + NSString* ClassName; + NSString* SelectorName=NSStringFromSelector(name); + NSString* IMPAddress=[NSString stringWithFormat:@"%p",imp]; + if(SelectorName!=nil&&[SelectorName isEqualToString:@""]==false){ + ClassName=NSStringFromClass(cls); + } + else{ + ClassName=@"WTFJH-UnknownClassName"; + } + WTInit(@"ObjCRuntime",@"class_addMethod"); + WTAdd(TypeString,@"Type"); + WTAdd(ClassName,@"ClassName"); + WTAdd(SelectorName,@"SelectorName"); + WTAdd(IMPAddress,@"IMPAddress"); + WTSave; + WTRelease; + + + [TypeString release]; + [ClassName release]; + [SelectorName release]; + [IMPAddress release]; + } + return old_class_addMethod(cls,name,imp,types); + +} + +BOOL new_class_addIvar(Class cls, const char *name, size_t size,uint8_t alignment, const char *types){ + if(WTShouldLog){ + NSString* ClassName=NSStringFromClass(cls); + NSString* IvarName=[NSString stringWithUTF8String:name]; + NSString* Types=[NSString stringWithUTF8String:types]; + WTInit(@"ObjCRuntime",@"class_addIvar"); + WTAdd(ClassName,@"ClassName"); + WTAdd(IvarName,@"IvarName"); + WTAdd(Types,@"Types"); + WTSave; + WTRelease; + [ClassName release]; + [IvarName release]; + [Types release]; + } + + return old_class_addIvar(cls,name,size,alignment,types); + } extern void init_ObjCRuntime_hook() { @@ -100,4 +150,6 @@ extern void init_ObjCRuntime_hook() { MSHookFunction((void*)NSProtocolFromString,(void*)new_NSProtocolFromString, (void**)&old_NSProtocolFromString); MSHookFunction((void*)NSStringFromSelector,(void*)new_NSStringFromSelector, (void**)&old_NSStringFromSelector); MSHookFunction((void*)NSSelectorFromString,(void*)new_NSSelectorFromString, (void**)&old_NSSelectorFromString); + MSHookFunction((void*)class_addMethod,(void*)new_class_addMethod, (void**)&old_class_addMethod); + MSHookFunction((void*)class_addIvar,(void*)new_class_addIvar, (void**)&old_class_addIvar); } diff --git a/VERSION b/VERSION index 832f62a..91a3d42 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -339 \ No newline at end of file +340 \ No newline at end of file