Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问下怎么集成到Xcode工程? #44

Closed
kobe1941 opened this issue Oct 28, 2018 · 20 comments
Closed

请问下怎么集成到Xcode工程? #44

kobe1941 opened this issue Oct 28, 2018 · 20 comments

Comments

@kobe1941
Copy link

如题,readme看不懂里边的步骤,我现在有一个Xcode工程,想用hookzz来打印函数的调用,如何集成呢?

@jmpews
Copy link
Owner

jmpews commented Oct 28, 2018

用下面的生成 Xcode 工程

cmake .. -G Xcode \
-DCMAKE_TOOLCHAIN_FILE=cmake/ios.toolchain.cmake \
-DIOS_PLATFORM=OS \
-DIOS_ARCH=arm64 \
-DENABLE_ARC=FALSE \
-DENABLE_BITCODE=OFF \
-DDEBUG=ON \
-DSHARED=ON \
-DPLATFORM=iOS \
-DARCH=armv8 \
-DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release

@kobe1941
Copy link
Author

我没看到这个是啥操作,直接复制到命令行会提示不能识别cmake这个命令 😳
另外就是,我已经有一个Xcode工程了,如何直接引入你的框架呢?我用monkeyDev去生成这个工程的,如果直接再来一个工程,不知道能不能兼容。。

@kobe1941
Copy link
Author

打错,没看懂这是要怎么操作?

@jmpews
Copy link
Owner

jmpews commented Oct 28, 2018

用过 cmake 么?

@kobe1941
Copy link
Author

@jmpews 安装好cmake了,也编译通过了,怎么集成到我的已有的工程呢?

@jmpews
Copy link
Owner

jmpews commented Oct 29, 2018

hmm 两个 Xcode 不会集成嘛? :(

@kobe1941
Copy link
Author

我用第一种方式的,编译完了生成了一些文件,不知道怎么用到Xcode工程里
image

@jmpews
Copy link
Owner

jmpews commented Oct 30, 2018

emmmmmm... 建议你先看下 cmake 怎么用.

@jmpews jmpews closed this as completed Oct 30, 2018
@kobe1941
Copy link
Author

kobe1941 commented Oct 31, 2018

生成了Xcode工程,尝试做最后一步:make -j4
终端里报错了:

/Users/hufeng/Documents/backup/HookZz/./srcxx/AssemblyClosureTrampoline.h/Users/hufeng/Documents/backup/HookZz/./srcxx/vm_core/platform/platform.h::44::1010::  fatal errorfatal error: : 
      
'iostream'       'cstdarg'file  filenot  notfound found

#include <iostream>#include <cstdarg>

         ^~~~~~~~~~         ^~~~~~~~~

1 warning generated.
In file included from /Users/hufeng/Documents/backup/HookZz/srcxx/vm_core/arch/cpu.cc:2:
In file included from /Users/hufeng/Documents/backup/HookZz/./srcxx/vm_core/arch/cpu.h:4:
In file included from /Users/hufeng/Documents/backup/HookZz/./srcxx/vm_core/globals.h:4:
In file included from /Users/hufeng/Documents/backup/HookZz/./srcxx/vm_core/macros.h:7:
In file included from /Users/hufeng/Documents/backup/HookZz/./srcxx/vm_core/logging.h:4:
/Users/hufeng/Documents/backup/HookZz/./srcxx/vm_core/platform/platform.h:4:10: fatal error: 
      'cstdarg' file not found
#include <cstdarg>
         ^~~~~~~~~
[ 20%] Building CXX object CMakeFiles/hookzz.dir/srcxx/vm_core/objects/code.cc.o
1 warning and 1 error generated.
make[2]: *** [CMakeFiles/hookzz.dir/srcxx/vm_core/logging.cc.o] Error 1
make[2]: *** Waiting for unfinished jobs....
warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the
      command line to use the libc++ standard library instead
      [-Wstdlibcxx-not-found]
1 warning and 1 error generated.
1 warning and 1 error generated.
make[2]: *** [CMakeFiles/hookzz.dir/srcxx/vm_core/arch/cpu.cc.o] Error 1
make[2]: *** [CMakeFiles/hookzz.dir/srcxx/intercept_routing_handler.cc.o] Error 1
In file included from /Users/hufeng/Documents/backup/HookZz/srcxx/vm_core/objects/code.cc:1:
In file included from /Users/hufeng/Documents/backup/HookZz/./srcxx/vm_core/objects/code.h:4:
In file included from /Users/hufeng/Documents/backup/HookZz/./srcxx/vm_core/globals.h:4:
In file included from /Users/hufeng/Documents/backup/HookZz/./srcxx/vm_core/macros.h:7:
In file included from /Users/hufeng/Documents/backup/HookZz/./srcxx/vm_core/logging.h:4:
/Users/hufeng/Documents/backup/HookZz/./srcxx/vm_core/platform/platform.h:4:10: fatal error: 
      'cstdarg' file not found
#include <cstdarg>
         ^~~~~~~~~
1 warning and 1 error generated.
make[2]: *** [CMakeFiles/hookzz.dir/srcxx/vm_core/objects/code.cc.o] Error 1
make[1]: *** [CMakeFiles/hookzz.dir/all] Error 2
make: *** [all] Error 2

大神指教一下?

@kobe1941
Copy link
Author

cstdarg这个文件,在Xcode的工程里,是可以找到的。。

@kobe1941
Copy link
Author

我用这个仓库提供的静态库直接拖到工程里可以运行了 https://github.com/yuzhouheike/HookZz-Learn
虽然自己编译失败了,还是感谢作者~

@chenzhengxu
Copy link

@kobe1941 @jmpews hookobjc_msgSend方法的时候,一些系统调用的方法并不会获取到,比如viewDidLoad是故意屏蔽了吗

@kobe1941
Copy link
Author

kobe1941 commented Apr 8, 2019

@chenzhengxu 你是怎么hook的,截图放一下?
我用旧版本可以hook到所有的函数,不过太耗性能了就去掉了

@chenzhengxu
Copy link

+ (void)load {
    [self hook_objc_msgSend];
}

+ (void)hook_objc_msgSend {
    ZzHookGOT(NULL,"objc_msgSend", NULL, NULL, objc_msgSend_pre_call, objc_msgSend_post_call);
}

void objc_msgSend_pre_call(RegState *rs, ThreadStackPublic *ts, CallStackPublic *cs, const HookEntryInfo *info) {
    char *selector = (char *)rs->ZREG(1);
    id tmpObject = (id)rs->ZREG(0);
    Class tmpClass  = object_getClass(tmpObject);
    if (!tmpClass)
        return;
    const char *className = class_getName(tmpClass);
    
    long log_time = log_timeInterval();
    stack.push({className, selector, log_time, 0});
}

void objc_msgSend_post_call(RegState *rs, ThreadStackPublic *ts, CallStackPublic *cs, const HookEntryInfo *info) {
    long log_time = log_timeInterval();
    MethodItem *item = &stack.top();
    item->post_time = log_time;
    
    printf("end:[thread:|%ld] [%s %s] startTime:[%ld] endTime:[%ld]\n", ts->thread_id, item->className, item->selector, item->pre_time, item->post_time);
    stack.pop();
}

https://github.com/yuzhouheike/HookZz-Learn的方式一样 @kobe1941

@kobe1941
Copy link
Author

kobe1941 commented Apr 8, 2019

我可以hook到所有的函数的,你看看是不是被过滤掉了

@chenzhengxu
Copy link

我这边没有过滤操作,https://github.com/everettjf/AppleTrace这个库也用了hookzz,也不会打印所有函数,你有哪个工程可以hook所有函数的吗,有没有地址给看下

@kobe1941
Copy link
Author

kobe1941 commented Apr 8, 2019

我用旧版本的可以hook,不过用了新版本后就不行了,hook失败,作者也没告诉我怎么用o(╯□╰)o

@jmpews
Copy link
Owner

jmpews commented Apr 9, 2019 via email

@chenzhengxu
Copy link

@jmpews 请问下,hookobjc_msg_send的时候是如何屏蔽一大堆系统方法的

@jmpews
Copy link
Owner

jmpews commented Apr 10, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants