Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
More OCRuntime
Browse files Browse the repository at this point in the history
  • Loading branch information
Naville committed Mar 12, 2016
1 parent 1978322 commit 0bb0567
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ wax.txt
*.log
theos
Cycript.framework
*.zip
56 changes: 54 additions & 2 deletions Hooks/API/ObjCRuntime.xm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -19,13 +17,16 @@ And Runtime Method Implementation Related Funcs
*/


//Old Func Pointers
Class (*old_NSClassFromString)(NSString *aClassName);
NSString* (*old_NSStringFromClass)(Class aClass);
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
Expand Down Expand Up @@ -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() {
Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
339
340

0 comments on commit 0bb0567

Please sign in to comment.