IOS security defense (24): Protection against sensitive logic (1)

Source: Internet
Author: User

IOS security defense (24): Protection against sensitive logic (1)



Objective-C code is easy to hook and exposed information is too naked. For security purposes, use C to write it!





Of course, not all code must be written in C. I mean sensitive business logic code.

This article introduces a simple method to rewrite Objective-C logic code to C code at a low learning cost.


Maybe, there is a class like this in the program:

@interface XXUtil : NSObject+ (BOOL)isVerified;+ (BOOL)isNeedSomething;+ (void)resetPassword:(NSString *)password;@end


After being dumped by class-dump, cylinder is easy to implement attacks and hook, posing a great security risk.

I want to change it, but I don't want to change the program structure. Is it swollen?





Hide the function name in the struct and store it as a function pointer member.

The advantage of doing so is that after compilation, only the address is left, the name and parameter table are removed, and the reverse cost and attack threshold are increased.



The rewritten program is 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 Reporting Guidelines

[XXUtil isVerified];

Changed:

XXUtil->isVerified();

You can.


Yes, no worries.




Related Article

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.