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.