iOS Security Defense (24): Sensitive logic Protection Scheme (1)

Source: Internet
Author: User

iOS Security Defense (24): Sensitive logic Protection Scheme (1)



Objective-c code is easy to hook, exposing information is too naked, for security, instead of C to write it!





Of course not all the code is written in C, I mean the sensitive business logic code.

This article introduces a kind of low-learning cost, simple, objective-c logic code rewrite to C code method.


Perhaps there is a class like this in the program:

@interface xxutil:nsobject+ (BOOL) isverified;+ (BOOL) isneedsomething;+ (void) ResetPassword: (NSString *) password;@ End


After being class-dump out, the use of cycript is easy to achieve attacks, easy to hook, there is a great security risk.

Want to change, but do not want to change the program structure, swollen?





Hides the function name in the struct and stores it as a function pointer member.

The advantage of this is that after compiling, only the address is left, the name and parameter table are removed, and the reverse cost and attack threshold are improved.



The program is rewritten as follows:

Xxutil.h#import <foundation/foundation.h>typedef struct _util {    BOOL (*isverified) (void);    BOOL (*isneedsomething) (void);    void (*resetpassword) (NSString *password);} xxutil_t, #define XXUTIL ([_xxutil sharedutil]) @interface _xxutil:nsobject+ (xxutil_t *) Sharedutil; @end


Xxutil.m#import "XXUtil.h" static BOOL _isverified (void) {    //bala bala ...    return YES;} Static BOOL _isneedsomething (void) {    //bala bala    ... return YES;} static void _resetpassword (NSString *password) {    //bala Bala ...} Static xxutil_t * util = NULL, @implementation _xxutil+ (xxutil_t *) sharedutil{    static dispatch_once_t Oncetoken;    Dispatch_once (&oncetoken, ^{        util = malloc (sizeof (xxutil_t));        util->isverified = _isverified;        util->isneedsomething = _isneedsomething;        Util->resetpassword = _resetpassword;    });    return util;} + (void) destroy{    util free (util): 0;    Util = NULL;} @end



Finally, according to Xcode's error guidelines, the previous call

[Xxutil isverified];

corresponding change to:

Xxutil->isverified ();

You can do it.


Yes, not a bit of brain.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.