Using the Macro SEC_IS_BEING_DEBUGGED_RETURN_NIL in iOS app

放肆的年华 提交于 2019-12-10 10:55:10

问题


I learnt about the below piece of code, which is claimed to prevent Method Swizzling to some extent.

#ifndef DEBUG
SEC_IS_BEING_DEBUGGED_RETURN_NIL();
#endif

But while including in my project for testing, I get an error.

Implicit declaration of function 'SEC_IS_BEING_DEBUGGED_RETURN_NIL' is invalid in C99

Can someone help me out on this error, if I need to include any library header for the same.


回答1:


I didn't intend to answer my own question. From the comment above, I did a search for any such implementation. And Found this In a GitHub Project. Which is a category of NSObject

Perhaps, it would help anyone in future.

#define SEC_IS_BEING_DEBUGGED_RETURN_NIL()  size_t size = sizeof(struct kinfo_proc); \
                                            struct kinfo_proc info; \
                                            int ret, name[4]; \
                                            memset(&info, 0, sizeof(struct kinfo_proc)); \
                                            name[0] = CTL_KERN; \
                                            name[1] = KERN_PROC; \
                                            name[2] = KERN_PROC_PID; \
                                            name[3] = getpid(); \
                                            if ((ret = (sysctl(name, 4, &info, &size, NULL, 0)))) { \
                                            if (ret) return nil; \
                                            } \
                                            if (info.kp_proc.p_flag & P_TRACED) return nil

Credits to maker of this

// Created by Derek Selander on a happy day. //
// Copyright (c)
// 2013 Derek Selander. All rights reserved. //



来源:https://stackoverflow.com/questions/28480282/using-the-macro-sec-is-being-debugged-return-nil-in-ios-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!