macos逆向初体验。
找个别人逆向过的目标熟悉一下逆向过程。
原文地址:
http://iosre.com/t/mac/3373
iosre.com应该是目前国内ios逆向最专业的论坛了。
好了,接下来开始。
从appstore下载扫雷app。下载前看了一下评论,一堆吐槽收费贵的……贵是贵了点
就是这货。
然后建立framework,引入JRSwizzle工具,定义好宏,写好script,将schema的启动项设置为这个游戏的app。
编写hook。分析过程见原文,可以按照原作者的思路过一遍。
(其实逆向重点就是分析过程~)
项目结构:
Main.h文件:
#import <objc/runtime.h>
#import "HookDeluxe.h"
Main.mm文件
#import "Main.h"
#import <objc/runtime.h>
#import <objc/message.h>
@implementation NSObject (HookDeluxe)
#pragma mark - GameState
- (BOOL)hook_fullgame {
return YES;
}
- (int)hook_robot{
Class c = objc_getClass("GameState");
SEL sel = NSSelectorFromString(@"sharedInstance");
id gameState = [c performSelector:sel];
SEL sel2 = NSSelectorFromString(@"setRobot:");
[gameState performSelector:sel2 withObject:[NSNumber numberWithInteger:99] afterDelay:0];
return 99;
}
@end
static void __attribute__((constructor)) initialize(void) {
NSLog(@"------- skcwiiur loaded ++++++++");
//允许扫雷难度
CBHookInstanceMethod(GameState, @selector(fullgame), @selector(hook_fullgame));
CBHookInstanceMethod(GameState, @selector(robot), @selector(hook_robot));
}
HookDeluxe.h 文件:
#import <Cocoa/Cocoa.h>
#import "JRSwizzle.h"
//! Project version number for HookDeluxe.
FOUNDATION_EXPORT double HookDeluxeVersionNumber;
//! Project version string for HookDeluxe.
FOUNDATION_EXPORT const unsigned char HookDeluxeVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <HookDeluxe/PublicHeader.h>
#define CBGetClass(classname) objc_getClass(#classname)
#define CBRegisterClass(superclassname, subclassname) { Class class = objc_allocateClassPair(CBGetClass(superclassname), #subclassname, 0);objc_registerClassPair(class); }
#define CBHookInstanceMethod(classname, ori_sel, new_sel) { NSError *error; [CBGetClass(classname) jr_swizzleMethod:ori_sel withMethod:new_sel error:&error]; if(error) NSLog(@"%@", error); }
#define CBHookClassMethod(classname, ori_sel, new_sel) { NSError *error; [CBGetClass(classname) jr_swizzleClassMethod:ori_sel withClassMethod:new_sel error:&error]; if(error) NSLog(@"%@", error); }
#define CBGetInstanceValue(obj, valuename) object_getIvar(obj, class_getInstanceVariable([obj class], #valuename))
#define CBSetInstanceValue(obj, valuename, value) object_setIvar(obj, class_getInstanceVariable([obj class], #valuename), value)
在BuildPhases中的脚本
#!/bin/bash
app_name="Minesweeper Deluxe"
framework_name="HookDeluxe"
app_bundle_path="/Applications/${app_name}.app/Contents/MacOS"
app_executable_path="${app_bundle_path}/${app_name}"
app_executable_backup_path="${app_executable_path}_"
framework_path="${app_bundle_path}/${framework_name}.framework"
# 备份原始可执行文件
if [ ! -f "$app_executable_backup_path" ]
then
cp "$app_executable_path" "$app_executable_backup_path"
fi
cp -r "${BUILT_PRODUCTS_DIR}/${framework_name}.framework" ${app_bundle_path}
/opt/iOSOpenDev/bin/insert_dylib --all-yes "${framework_path}/${framework_name}" "$app_executable_backup_path" "$app_executable_path"
执行过程中可能会遇到没有权限的情况(备份文件的时候)。
这种情况是因为该目录没有权限,自己去那Macos目录,执行一下
cd /Applications/Minesweeper Deluxe.app/Contents
sudo chmod 777 MacOS/
然后执行,注入,启动。一切ok!
网友评论