一个用于代码混淆和字符串加密的Mac小Demo

2021-12-17  本文已影响0人  德惟

MJCodeObfuscation

一个用于代码混淆和字符串加密的Mac小Demo

代码混淆

将需要混淆的类名、方法名生成随机字符串的宏定义

@interface MJPerson : NSObject
- (void)mj_run;
- (void)mj_setupName:(NSString *)name mj_no:(int)no mj_age:(int)age;
@end
    
@implementation MJPerson
- (void)mj_run {
    NSLog(@"%s", __func__);
}

- (void)mj_setupName:(NSString *)name mj_no:(int)no mj_age:(int)age {
    NSLog(@"%s - %@ %d %d", __func__, name, no, age);
}
@end
68747470733a2f2f696d61676573323031382e636e626c6f67732e636f6d2f626c6f672f3439373237392f3230313830382f3439373237392d32303138303832303135323230373836372d313038343034353134372e676966.gif
#define mj_run OmWJoTZfCqoPshvr
#define MJPerson egnjoOFDrFiQVRgr
#define mj_setupName HrZLzcgSoPhwMBwW
#define mj_age reXYcdSKKEUSMalJ
#define mj_no mHEQViTuoOvRtMuB
68747470733a2f2f696d61676573323031382e636e626c6f67732e636f6d2f626c6f672f3439373237392f3230313830382f3439373237392d32303138303832303135323231393435302d313037343631373535302e676966.gif
#ifndef PrefixHeader_pch
#define PrefixHeader_pch

#import "MJCodeObfuscation.h"

#endif /* PrefixHeader_pch */
MJPerson *person = [[MJPerson alloc] init];
[person mj_run];
[person mj_setupName:@"jack" mj_no:20 mj_age:21];

// 打印结果
-[egnjoOFDrFiQVRgr OmWJoTZfCqoPshvr]
-[egnjoOFDrFiQVRgr HrZLzcgSoPhwMBwW:mHEQViTuoOvRtMuB:reXYcdSKKEUSMalJ:] - jack 20 21

字符串加密(方式1)

仅仅是将字符串进行了一个简单的异或处理(开发者可以自行制定加密算法)

NSString *str1 = @"小码哥mj123go";
const char *str2 = "小码哥mj123go";
NSLog(@"%@ %s", str1, str2);
3.gif
/* 小码哥mj123go */
extern const MJEncryptStringData * const _761622619;

/* 小码哥mj123go */
const MJEncryptStringData * const _761622619 = &(MJEncryptStringData){
    .factor = (char)-100,
    .value = (char []){121,44,19,123,60,29,121,15,57,-15,-10,-83,-82,-81,-5,-13,0},
    .length = 16
};
4.png
#import "MJEncryptString.h"

NSString *str1 = mj_OCString(_761622619);
const char *str2 = mj_CString(_761622619);
NSLog(@"%@ %s", str1, str2);

// 打印结果如下
小码哥mj123go 小码哥mj123go

字符串加密(方式2)

5.gif 6.gif
#ifndef PrefixHeader_pch
#define PrefixHeader_pch

#import "MJEncryptStringData.h"

#endif /* PrefixHeader_pch */
#ifndef MJEncryptStringData_h
#define MJEncryptStringData_h
#include "MJEncryptString.h"
/* %@ %s */
extern const MJEncryptStringData * const _1302706645;
/* 小码哥mj123go */
extern const MJEncryptStringData * const _761622619;
#endif
NSString *str1 = mj_OCString(_761622619);
const char *str2 = mj_CString(_761622619);
NSLog(@"%@ %s", str1, str2);

// 打印结果如下
小码哥mj123go 小码哥mj123go
上一篇下一篇

猜你喜欢

热点阅读