You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// create TLS data, only once
if (__predict_false(NULL == stack)) {
if (__predict_false(NULL == (stack = bh_trampo_stack_create()))) goto end;
pthread_setspecific(bh_trampo_tls_key, (void *)stack);
}
// check whether a recursive call occurred
bool recursive = false;
for (size_t i = stack->frames_cnt; i > 0; i--) {
bh_trampo_frame_t *frame = &stack->frames[i - 1];
if (frame->orig_func == hook->orig_func) {
// recursive call found
recursive = true;
break;
}
}
// find and return the first enabled hook-function in the hook-chain
// (does not include the original function)
if (!recursive) {
bh_hook_call_t *running;
SLIST_FOREACH(running, &hook->running_list, link) {
if (running->enabled) {
// push a new frame for the current proxy
if (stack->frames_cnt >= BH_TRAMPO_STACK_FRAME_MAX) goto end;
stack->frames_cnt++;
bh_trampo_frame_t *frame = &stack->frames[stack->frames_cnt - 1];
frame->proxies = hook->running_list;
frame->orig_func = hook->orig_func;
frame->return_address = return_address;
return running->func;
}
}
}
// if not found enabled hook-function in the hook-chain, or recursive call found,
// just return the original-function
end:
return hook->orig_func;
}`
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
最近学习了一下bhook,研究代码时发现一个疑惑,在bh_trampo.c的bh_trampo_push_stack方法中,进行了循环检测
,检测到循环后直接调用了原始方法。
是否不应该直接调用原始方法,而是调用hook链中的上一个方法呢?
例如方法A、方法B都先后hook了方法C,那么方法B中产生了循环调用,应该调用方法A才符合预期吧,否则会跳过方法A的调用?
`static void *bh_trampo_push_stack(bh_hook_t *hook, void *return_address) {
bh_trampo_stack_t *stack = (bh_trampo_stack_t *)pthread_getspecific(bh_trampo_tls_key);
// create TLS data, only once
if (__predict_false(NULL == stack)) {
if (__predict_false(NULL == (stack = bh_trampo_stack_create()))) goto end;
pthread_setspecific(bh_trampo_tls_key, (void *)stack);
}
// check whether a recursive call occurred
bool recursive = false;
for (size_t i = stack->frames_cnt; i > 0; i--) {
bh_trampo_frame_t *frame = &stack->frames[i - 1];
}
// find and return the first enabled hook-function in the hook-chain
// (does not include the original function)
if (!recursive) {
bh_hook_call_t *running;
SLIST_FOREACH(running, &hook->running_list, link) {
if (running->enabled) {
// push a new frame for the current proxy
if (stack->frames_cnt >= BH_TRAMPO_STACK_FRAME_MAX) goto end;
stack->frames_cnt++;
bh_trampo_frame_t *frame = &stack->frames[stack->frames_cnt - 1];
frame->proxies = hook->running_list;
frame->orig_func = hook->orig_func;
frame->return_address = return_address;
}
// if not found enabled hook-function in the hook-chain, or recursive call found,
// just return the original-function
end:
return hook->orig_func;
}`
Beta Was this translation helpful? Give feedback.
All reactions