逆向掃雷

macos逆向初體驗。
找個別人逆向過的目標熟悉一下逆向過程。
原文地址:

http://iosre.com/t/mac/3373

iosre.com應(yīng)該是目前國內(nèi)ios逆向最專業(yè)的論壇了。

好了,接下來開始。
從appstore下載掃雷app。下載前看了一下評論,一堆吐槽收費貴的……貴是貴了點

就是這貨。

然后建立framework,引入JRSwizzle工具,定義好宏,寫好script,將schema的啟動項設(shè)置為這個游戲的app。

編寫hook。分析過程見原文,可以按照原作者的思路過一遍。
(其實逆向重點就是分析過程~)
項目結(jié)構(gòu):

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"

# 備份原始可執(zhí)行文件
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"

執(zhí)行過程中可能會遇到?jīng)]有權(quán)限的情況(備份文件的時候)。
這種情況是因為該目錄沒有權(quán)限,自己去那Macos目錄,執(zhí)行一下

cd /Applications/Minesweeper Deluxe.app/Contents
sudo chmod 777 MacOS/

然后執(zhí)行,注入,啟動。一切ok!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容