AloneMonkey / MonkeyDev

CaptainHook Tweak、Logos Tweak and Command-line Tool、Patch iOS Apps, Without Jailbreak.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

App occurs "Bus error" when running

TLHorse opened this issue · comments

I'm now trying to hook an app using MonkeyAppMac. The .m code is as follows:
我正在用MonkeyAppMac hook一个软件,下面是代码

#import "MBTweak.h"
#import "substrate.h"

@class MBInputLicenseViewController;

static void (*orig_activateClick)(MBInputLicenseViewController*, SEL, void *);
static void new_activateClick(MBInputLicenseViewController* self, SEL _cmd, void *arg2) {
    NSLog(@"NET_SUCCESS");
    [NSNotificationCenter.defaultCenter postNotificationName:@"kIsPro" object:@(YES)];
    [NSUserDefaults.standardUserDefaults setObject:@(YES) forKey:@"updateType"];
    [NSUserDefaults.standardUserDefaults synchronize];
    [NSNotificationCenter.defaultCenter postNotificationName:@"FinishedActivate" object:0];
}

static void __attribute__((constructor)) initialize(void) {
    MSHookMessageEx(objc_getClass("MBInputLicenseViewController"), @selector(activateClick:), (IMP)&new_activateClick, (IMP*)&orig_activateClick);
}

I'm handling an function and I'm sure that all the symbols in the code are correct.
我正在hook一个函数,我很确定我代码里的symbol没有问题。
Then I started building. The packing process was successful, but the app failed to start with a bus error.
我build的时候,运行mpack没有问题,但最后打开软件的时候失败了,显示bus error(总线错误)
The log in Xcode is as follows:
这是我Xcode里的log:

packing...
2022-02-13 18:18:47.764 MBApp [12808:127896] [AntiAntiDebug Init]
/opt/MonkeyDev/Tools/mpack.sh: line 57: 12808 Bus error: 10           "$APP_BINARY_PATH"
Command PhaseScriptExecution failed with a nonzero exit code

I opened the executable in Terminal, and got the same following error:
我把软件的二进制在终端里打开,也看到了一样的错误:

tlhorse@TLHorse-Book ~ % /Users/tlhorse/Developer/MBAppTweak/MBAppTweak/TargetApp/MBApp\ 8.app/Contents/MacOS/MBApp\ 8 ; exit;
2022-02-13 19:45:23.118 MacBooster 8[15640:165565] [AntiAntiDebug Init]
zsh: bus error  

Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

After that, I wrote an another dylib hooking the same functions, but using objc-runtime instead of MonkeyAppMac, and injected the dylib into the executable file using insert-dylib. As a result, the app ran successfully. So I infer that there must be some kind of error in MonkeyAppMac. But I'm not sure what happenend about it.
之后,我又用objc-runtime写了一个dylib,hook的相通的函数,用insert-dylib注入,结果app可以正常打开。我总觉得MonkeyAppMac有问题,但不太确定这个错误怎么修复,在线求助:(