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