iOS security attack and defense structure protection use

Source: Internet
Author: User

Objective-c code is easy to hook, so you need to protect some important business logic, you can use the form of a struct, the function name is hidden in the structure, as a function pointer member of the form of storage. This compiles only the next address, removes the name and the parameter table, improves the reverse cost and the attack threshold.

For example, protect the following code:

+ (BOOL) ispermission: (int) level; + (cgfloat) Totalamont; + (void) Somepravitemethod: (NSString *) paraStr1 numbervalue: (double) numbervalue;

instead. h:

  

#import <Foundation/Foundation.h>#import <UIKit/UIKit.h>struct Protectutil {    BOOL (*ispermission) (int level );    CGFloat (*totalamont) (void);     void Double numbervalue);} structprotectutil_t; @interface structprotectutil:nsobject+ (structprotectutil_t *) sharedutil; @end

. m File:

  

#import "StructProtectUtil.h"StaticBOOL _ispermission (intLevel ) {NSLog (@"****** level =%d", level); if(Level > A) {        returnYES; }    returnNO;}Staticcgfloat _totalamont () {NSLog (@"= = TotalAmount"); return 1900;}Static void_somepravitemethod (NSString *parastr1,Doublenumbervalue) {NSLog (@"paraStr1 =%@, Numbervalue =%f", PARASTR1, Numbervalue);}Staticstructprotectutil_t *protectutil =NULL;@implementationStructprotectutil+ (structprotectutil_t *) sharedutil{Staticdispatch_once_t Oncetoken; Dispatch_once (&oncetoken, ^{protectutil= malloc (sizeof(structprotectutil_t)); Protectutil->ispermission =_ispermission; Protectutil->totalamont =_totalamont; Protectutil->somepravitemethod =_somepravitemethod;    }); returnProtectutil;}+ (void) destory{Protectutil? Free (protectutil):0; Protectutil=NULL;}@end

When called:

[Structprotectutil Sharedutil], ispermission (Somepravitemethod (  @ "parastr"3820);

  

The project is then class-dump:

  Class-dump-h/users/zhangtibin/library/developer/xcode/deriveddata/ testsecurityadvance-gflhcslxswowdrfflsfchjmlzfdt/build/products/debug-iphoneos/testsecurityadvance.app/ Testsecurityadvance-o/users/zhangtibin/class-dump/struct

View the post-compilation file with the following results:

  

This enables the protection of sensitive logic.

The following class-dump the unprotected files after you see them.

  

iOS security attack and defense structure protection use

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.