bytedance / bhook

:fire: ByteHook is an Android PLT hook library which supports armeabi-v7a, arm64-v8a, x86 and x86_64.
https://github.com/bytedance/bhook/tree/main/doc#readme
MIT License
2.05k stars 315 forks source link

bytesig被初始化多次时, 后面的会失败 #87

Closed pxb1988 closed 7 months ago

pxb1988 commented 8 months ago

bytehook Version

1.0.9

Android OS Version

android 13

Android ABIs

arm64-v8a

Device Manufacturers and Models

红米K60

Describe the Bug

项目中同时使用bytehook与shadowhook, 使用源码编译到同一个so. 两个sdk都使用了bytesig模块, 后面启动的会失败.

SHADOWHOOK_ERRNO_INIT_SIGSEGV或者BYTEHOOK_STATUS_CODE_INITERR_SIG

目前通过如下代码临时解决.

static bool init_SIGSEGV = false;
static int last_init_SIGSEGV = 0;
static bool init_SIGBUS = false;
static int last_init_SIGBUS = 0;
int bytesig_init(int signum) {
  if (signum == SIGSEGV && init_SIGSEGV) {
    return last_init_SIGSEGV;
  }
  if (signum == SIGBUS && init_SIGBUS) {
    return last_init_SIGBUS;
  }

  int result = bytesig_init0(signum);

  if (signum == SIGSEGV ) {
    last_init_SIGSEGV = result;
    init_SIGSEGV = true;
  }
  if (signum == SIGBUS ) {
    last_init_SIGBUS = result;
    init_SIGBUS = true;
  }
  return result;
}
caikelun commented 8 months ago

bytesig 设计中假设了“在同一个elf中只有一份bytesig实现”。

caikelun commented 8 months ago

如果合并两个sdk的话,源码中保留一份bytesig代码,然后初始化一次就可以了。编译和兼容上可能需要调整下。

viewZz commented 8 months ago

我把shadowhook和bytehook源码都拷贝了,同时使用时,注释掉shadowhook_init或者bytehook_init 中bytesig_init相关代码也能用