首页 / IOS / iOS安全攻防之结构体保护使用
iOS安全攻防之结构体保护使用
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了iOS安全攻防之结构体保护使用,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2150字,纯文字阅读大概需要4分钟。
内容图文
![iOS安全攻防之结构体保护使用](/upload/InfoBanner/zyjiaocheng/1319/a1635af81cd444c587f10b9acb7195cf.jpg)
Objective-C 代码很容易被 hook,因此需要对一些重要的业务逻辑进行保护,可以改用结构体的形式,把函数名隐藏在结构体里,以函数指针成员的形式存储。这样编译后只留了下地址,去掉了名字和参数表,提高了逆向成本和攻击门槛。
例如,把以下代码进行保护:
+ (BOOL)isPermission:(int)level; + (CGFloat)totalAmont; + (void)somePraviteMethod:(NSString *)paraStr1 numberValue:(double)numberValue;
改为.h:
#import <Foundation/Foundation.h> #import <UIKit/UIKit.h> typedef struct protectUtil { BOOL (*isPermission)(int level); CGFloat (*totalAmont)(void); void (*somePraviteMethod)(NSString *paraStr1, double numberValue); }StructProtectUtil_t; @interface StructProtectUtil : NSObject + (StructProtectUtil_t *)sharedUtil; @end
.m 文件:
#import " StructProtectUtil.h " static BOOL _isPermission (int level) { NSLog(@"****** level = %d", level); if (level > 12) { return YES; } return NO; } static CGFloat _totalAmont() { NSLog(@"==== totalAmount"); return1900; } staticvoid _somePraviteMethod (NSString *paraStr1, double numberValue) { NSLog(@"paraStr1 = %@, numberValue = %f", paraStr1, numberValue); } static StructProtectUtil_t *protectUtil = NULL; @implementation StructProtectUtil + (StructProtectUtil_t *)sharedUtil { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ protectUtil = malloc(sizeof(StructProtectUtil_t)); protectUtil->isPermission = _isPermission; protectUtil->totalAmont = _totalAmont; protectUtil->somePraviteMethod = _somePraviteMethod; }); return protectUtil; } + (void)destory { protectUtil ? free(protectUtil) : 0; protectUtil = NULL; } @end
调用时:
[StructProtectUtil sharedUtil] -> isPermission(1000); [StructProtectUtil sharedUtil] -> totalAmont(); [StructProtectUtil sharedUtil] -> somePraviteMethod(@"ParaStr", 3820);
然后对工程进行 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
查看反编译后的文件,结果如下:
这样就实现了敏感逻辑的保护。
以下对没有保护的文件进行 Class-dump 后看到的。
原文:http://www.cnblogs.com/ZachRobin/p/6898452.html
内容总结
以上是互联网集市为您收集整理的iOS安全攻防之结构体保护使用全部内容,希望文章能够帮你解决iOS安全攻防之结构体保护使用所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。