All Projects → qhd → Anymethodlog

qhd / Anymethodlog

Licence: mit
Log any method call of object in Objective-C

Projects that are alternatives of or similar to Anymethodlog

Icmethoddigger
An easy way to print almost methods including private methods (supported arm64 architecture devices).
Stars: ✭ 103 (-71.47%)
Mutual labels:  hook, log, runtime
CJMethodLog
Objective-C 函数日志监听系统,可监听任意类,任意类的任意方法的调用日志。
Stars: ✭ 26 (-92.8%)
Mutual labels:  log, runtime
sudohulk
try privilege escalation changing sudo command
Stars: ✭ 114 (-68.42%)
Mutual labels:  hook, hacking-tool
Katana
A Python Tool For google Hacking
Stars: ✭ 355 (-1.66%)
Mutual labels:  hacking, hacking-tool
Ysf
YSF Server Functions
Stars: ✭ 77 (-78.67%)
Mutual labels:  hook, hacking
Swifthook
A library to hook methods in Swift and Objective-C.
Stars: ✭ 93 (-74.24%)
Mutual labels:  hook, runtime
Ethical Hacking Tools
Complete Listing and Usage of Tools used for Ethical Hacking
Stars: ✭ 272 (-24.65%)
Mutual labels:  hacking, hacking-tool
Cameradar
Cameradar hacks its way into RTSP videosurveillance cameras
Stars: ✭ 2,775 (+668.7%)
Mutual labels:  hacking, hacking-tool
Cheatsheet God
Penetration Testing Reference Bank - OSCP / PTP & PTX Cheatsheet
Stars: ✭ 3,521 (+875.35%)
Mutual labels:  hacking, hacking-tool
Windows Post Exploitation
Windows post-exploitation tools, resources, techniques and commands to use during post-exploitation phase of penetration test. Contributions are appreciated. Enjoy!
Stars: ✭ 296 (-18.01%)
Mutual labels:  hacking, hacking-tool
Quack
Quack Toolkit is a set of tools to provide denial of service attacks. Quack Toolkit includes SMS attack tool, HTTP attack tool and many other attack tools.
Stars: ✭ 305 (-15.51%)
Mutual labels:  hacking, hacking-tool
Vault
swiss army knife for hackers
Stars: ✭ 346 (-4.16%)
Mutual labels:  hacking, hacking-tool
Icg Autoexploiterbot
Wordpress 🔥 Joomla 🔥 Drupal 🔥 OsCommerce 🔥 Prestashop 🔥 Opencart 🔥
Stars: ✭ 242 (-32.96%)
Mutual labels:  hacking, hacking-tool
Awesome Hacking Lists
平常看到好的渗透hacking工具和多领域效率工具的集合
Stars: ✭ 311 (-13.85%)
Mutual labels:  hacking, hacking-tool
Tangalanga
Tangalanga: the Zoom conference scanner hacking tool
Stars: ✭ 236 (-34.63%)
Mutual labels:  hacking, hacking-tool
Bopscrk
Tool to generate smart and powerful wordlists
Stars: ✭ 273 (-24.38%)
Mutual labels:  hacking, hacking-tool
T Load
New Interface And Loading Screen For Termux Users
Stars: ✭ 207 (-42.66%)
Mutual labels:  hacking, hacking-tool
Phonia
Phonia Toolkit is one of the most advanced toolkits to scan phone numbers using only free resources. The goal is to first gather standard information such as country, area, carrier and line type on any international phone numbers with a very good accuracy.
Stars: ✭ 221 (-38.78%)
Mutual labels:  hacking, hacking-tool
Osmedeus
Fully automated offensive security framework for reconnaissance and vulnerability scanning
Stars: ✭ 3,391 (+839.34%)
Mutual labels:  hacking, hacking-tool
Ctftools
Personal CTF Toolkit
Stars: ✭ 312 (-13.57%)
Mutual labels:  hacking, hacking-tool

ANYMethodLog - log any method call of object in Objective-C

打印 Objective-C 对象中的任何方法

running show

调用说明:

+ (void)logMethodWithClass:(Class)aClass
                 condition:(BOOL(^)(SEL sel)) condition
                    before:(void(^)(id target, SEL sel, NSArray *args, int deep)) before
                     after:(void(^)(id target, SEL sel, NSArray *args, NSTimeInterval interval, int deep, id retValue)) after;

aClass:要打印的类

condition:根据此 block 来决定是否追踪方法(sel 是方法名)

before:方法调用前会调用该 block(target 是检测的对象,sel 是方法名,args 是参数列表,deep 是调用层级)

after:方法调用后会调用该 block(interval 是执行方法的耗时,retValue 是返回值)

功能:

1.打印一个类定义的所有方法,包括公开方法和私有方法:

[ANYMethodLog logMethodWithClass:[UIViewController class] condition:^BOOL(SEL sel) {
    NSLog(@"method:%@", NSStringFromSelector(sel));
    return NO;
} before:nil after:nil];

2.打印在运行过程中调用了哪些方法:

[ANYMethodLog logMethodWithClass:[UIViewController class] condition:^BOOL(SEL sel) {
    return YES;
} before:^(id target, SEL sel, NSArray *args, int deep) {
    NSLog(@"target:%@ sel:%@", target, NSStringFromSelector(sel));
} after:nil];

3.打印特定几个方法的调用顺序:

[ANYMethodLog logMethodWithClass:[UIViewController class] condition:^BOOL(SEL sel) {
    
    NSArray *whiteList = @[@"loadView", @"viewWillAppear:", @"viewDidAppear:", @"viewWillDisappear:", @"viewDidDisappear:", @"viewWillLayoutSubviews", @"viewDidLayoutSubviews"];
    return [whiteList containsObject:NSStringFromSelector(sel)];
    
} before:^(id target, SEL sel, NSArray *args, int deep) {
    
    NSLog(@"target:%@ sel:%@", target, NSStringFromSelector(sel));
    
} after:nil];

4.打印调用方法时的参数值:

[ANYMethodLog logMethodWithClass:NSClassFromString(@"UIViewController") condition:^BOOL(SEL sel) {
    
    return [NSStringFromSelector(sel) isEqualToString:@"viewWillAppear:"];

} before:^(id target, SEL sel, NSArray *args, int deep) {

    NSLog(@"before target:%@ sel:%@ args:%@", target, NSStringFromSelector(sel), args);

} after:nil];

5.打印某个方法调用前后的变化:

[ANYMethodLog logMethodWithClass:NSClassFromString(@"ListController") condition:^BOOL(SEL sel) {

    return [NSStringFromSelector(sel) isEqualToString:@"changeBackground"];

} before:^(id target, SEL sel, NSArray *args, int deep) {

    NSLog(@"before background color:%@", [(ListController *)target view].backgroundColor);

} after:^(id target, SEL sel, NSArray *args, NSTimeInterval interval, int deep, id retValue) {
    
    NSLog(@"after background color:%@", [(ListController *)target view].backgroundColor);
    
}];

6.打印某个方法调用的耗时:

[ANYMethodLog logMethodWithClass:NSClassFromString(@"ListController") condition:^BOOL(SEL sel) {
    
    return [NSStringFromSelector(sel) isEqualToString:@"changeBackground"];
    
} before:^(id target, SEL sel, NSArray *args, int deep) {
    
    
} after:^(id target, SEL sel, NSArray *args, NSTimeInterval interval, int deep, id retValue) {
    
    NSLog(@"interval::%@", [@(interval) stringValue]);
    
}];

7.追踪方法调用顺序:

[ANYMethodLog logMethodWithClass:NSClassFromString(@"ListController") condition:^BOOL(SEL sel) {
    return  YES;
} before:^(id target, SEL sel, NSArray *args, int deep) {
    NSString *selector = NSStringFromSelector(sel);
    NSArray *selectorArrary = [selector componentsSeparatedByString:@":"];
    selectorArrary = [selectorArrary filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"length > 0"]];
    NSMutableString *selectorString = [NSMutableString new];
    for (int i = 0; i < selectorArrary.count; i++) {
        [selectorString appendFormat:@"%@:%@ ", selectorArrary[i], args[i]];
    }
    NSMutableString *deepString = [NSMutableString new];
    for (int i = 0; i < deep; i++) {
        [deepString appendString:@"-"];
    }
    NSLog(@"%@[%@ %@]", deepString , target, selectorString);
} after:^(id target, SEL sel, NSArray *args, NSTimeInterval interval, int deep, id retValue) {
    NSMutableString *deepString = [NSMutableString new];
    for (int i = 0; i < deep; i++) {
        [deepString appendString:@"-"];
    }
    NSLog(@"%@ret:%@", deepString, retValue);
}];

TODO:

  • 解决真机上运行出现的问题。 (已完成)
  • 打印调用时的参数值。 (已完成)
  • 打印返回值。 (已完成)
  • 计算某个方法的耗时。 (已完成)

原理:

利用runtime交换方法的实现。动态创建新方法,在新方法里再调用原来的方法。现阶段还不是很完美地调用原来方法,在需要传参的方法会出现传参失败,在真机问题较多,在模拟器问题较少,在用的时候可以过滤掉需要传参的方法。

1.把原方法的 IMP 换成 _objc_msgForward ,使之触发 forwardInvocation 方法;

2.把方法 forwardInvocationIMP 换成 qhd_forwardInvocation

3.创建一个新方法,IMP 就是原方法的原来的 IMP,那么只要在 qhd_forwardInvocation 调用新方法即可。那么就可以在 qhd_forwardInvocation 插入 log 。

欢迎提 Issues 和 Pull requests

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].