iOS逆向之iOSOpenDev


上篇談到使用TheOS進行越獄開發,但是流程相對而言較復雜,本篇我們談一下iOSOpenDev進行越獄開發。通過使用iOSOpenDev,我們可以使用Xcode進行開發、編譯、生成並運行到設備上。

1.安裝iOSOpenDev

  • 打開網址:http://iosopendev.com/download/,選擇“iOSOpenDev 1.6-2 Installer”,下載完成之后,直接安裝pkg文件。在安裝過程中,有可能出現失敗,按照 這篇文章 介紹的方法,進行處理。
  • 安裝成功后,打開XCode,新建工程,我們可以看到iOSOpenDev已經集成在XCode中了,並附帶了很多模板:

2.使用iOSOpenDev

第一步:新建工程,這里選擇“Logos Tweak”,新建完成之后,工程結構如下圖所示:

可以看到有一個.xm文件,我們打開看一下內容:

// Logos by Dustin Howett
// See http://iphonedevwiki.net/index.php/Logos

#error iOSOpenDev post-project creation from template requirements (remove these lines after completed) -- \
    Link to libsubstrate.dylib: \ (1) go to TARGETS > Build Phases > Link Binary With Libraries and add /opt/iOSOpenDev/lib/libsubstrate.dylib \ (2) remove these lines from *.xm files (not *.mm files as they're automatically generated from *.xm files)

%hook ClassName

+ (id)sharedInstance
{
    %log;

    return %orig;
}

- (void)messageWithNoReturnAndOneArgument:(id)originalArgument
{
    %log;

    %orig(originalArgument);
    
    // or, for exmaple, you could use a custom value instead of the original argument: %orig(customValue);
}

- (id)messageWithReturnAndNoArguments
{
    %log;

    id originalReturnOfMessage = %orig;
    
    // for example, you could modify the original return value before returning it: [SomeOtherClass doSomethingToThisObject:originalReturnOfMessage];

    return originalReturnOfMessage;
}

%end

.xm文件提示需要鏈接 libsubstrate.dylib,另外看一下很多%開頭的語句。%是Legos中的指示符,和TheOS中一樣。

這里先把.xm文件的內容清空,然后ibsubstrate.dylib鏈接進來,另外也把UIKit(因為我們需要一個提示框顯示信息)鏈接進來:

TheOS一樣,這里我們也只是顯示一個Alert框,代碼也一樣:

#import <UIKit/UIKit.h>

%hook SpringBoard

-(void)applicationDidFinishLaunching:(id)application {
    %orig;

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello, Gof!" message:@"LeeGof is very handsome" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
}

%end

再看一下.mm文件,已經自動根據.xm文件生成了如下代碼:

#line 1 "/Users/GofLee/Desktop/逆向工程/code/TweakDemo/TweakDemo/TweakDemo.xm"
#import <UIKit/UIKit.h>


#include <substrate.h>
#if defined(__clang__)
#if __has_feature(objc_arc)
#define _LOGOS_SELF_TYPE_NORMAL __unsafe_unretained
#define _LOGOS_SELF_TYPE_INIT __attribute__((ns_consumed))
#define _LOGOS_SELF_CONST const
#define _LOGOS_RETURN_RETAINED __attribute__((ns_returns_retained))
#else
#define _LOGOS_SELF_TYPE_NORMAL
#define _LOGOS_SELF_TYPE_INIT
#define _LOGOS_SELF_CONST
#define _LOGOS_RETURN_RETAINED
#endif
#else
#define _LOGOS_SELF_TYPE_NORMAL
#define _LOGOS_SELF_TYPE_INIT
#define _LOGOS_SELF_CONST
#define _LOGOS_RETURN_RETAINED
#endif

@class SpringBoard; 
static void (*_logos_orig$_ungrouped$SpringBoard$applicationDidFinishLaunching$)(_LOGOS_SELF_TYPE_NORMAL SpringBoard* _LOGOS_SELF_CONST, SEL, id); static void _logos_method$_ungrouped$SpringBoard$applicationDidFinishLaunching$(_LOGOS_SELF_TYPE_NORMAL SpringBoard* _LOGOS_SELF_CONST, SEL, id); 

#line 3 "/Users/GofLee/Desktop/逆向工程/code/TweakDemo/TweakDemo/TweakDemo.xm"


static void _logos_method$_ungrouped$SpringBoard$applicationDidFinishLaunching$(_LOGOS_SELF_TYPE_NORMAL SpringBoard* _LOGOS_SELF_CONST self, SEL _cmd, id application) {
    _logos_orig$_ungrouped$SpringBoard$applicationDidFinishLaunching$(self, _cmd, application);

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello, Gof!" message:@"LeeGof is very handsome" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
}


static __attribute__((constructor)) void _logosLocalInit() {
{Class _logos_class$_ungrouped$SpringBoard = objc_getClass("SpringBoard"); if (_logos_class$_ungrouped$SpringBoard) {MSHookMessageEx(_logos_class$_ungrouped$SpringBoard, @selector(applicationDidFinishLaunching:), (IMP)&_logos_method$_ungrouped$SpringBoard$applicationDidFinishLaunching$, (IMP*)&_logos_orig$_ungrouped$SpringBoard$applicationDidFinishLaunching$);} else {HBLogError(@"logos: nil class %s", "SpringBoard");}} }
#line 13 "/Users/GofLee/Desktop/逆向工程/code/TweakDemo/TweakDemo/TweakDemo.xm"

接着我們看一下Target中的“User-Defined”:

在這里,配置“iOSOpenDevDevice”字段為聯調的設備IP。直接連接真機運行(選擇Build For -- Profiling),可以看到代碼已經生效。如下圖所示:

3.常見錯誤

錯誤一:Failed to create directory /var/root/iOSOpenDevPackages on device 10.1.xx.xx,如下圖所示:

【解決方案】:在終端輸入如下指令:

iosod sshkey -h 10.1.xx.xx

重新再試即可。

錯誤二:運行的時候,有可能出現這樣的錯誤:Use of undeclared identifier 'HBLogError',如下圖所示:

【解決方案】:在.xm文件中加入如下宏定義:

#define HBLogError NSLog

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM