Ejemplo n.º 1
0
// just like pre_call, wow!
void function_context_begin_invocation(ZzHookFunctionEntry *entry, zpointer next_hop, RegState *rs,
                                       zpointer caller_ret_addr) {

    Xdebug("target %p call begin-invocation", entry->target_ptr);

    ZzThreadStack *threadstack = ZzGetCurrentThreadStack(entry->thread_local_key);
    if (!threadstack) {
        threadstack = ZzNewThreadStack(entry->thread_local_key);
    }
    ZzCallStack *callstack = ZzNewCallStack();
    ZzPushCallStack(threadstack, callstack);

    /* call pre_call */
    if (entry->pre_call) {
        PRECALL pre_call;
        pre_call = entry->pre_call;
        (*pre_call)(rs, (ThreadStack *)threadstack, (CallStack *)callstack);
    }

    /* set next hop */
    if (entry->replace_call) {
        *(zpointer *)next_hop = entry->replace_call;
    } else {
        *(zpointer *)next_hop = entry->on_invoke_trampoline;
    }

    if (entry->hook_type == HOOK_FUNCTION_TYPE) {
        callstack->caller_ret_addr = *(zpointer *)caller_ret_addr;
        *(zpointer *)caller_ret_addr = entry->on_leave_trampoline;
    }
}
Ejemplo n.º 2
0
// just like post_call, wow!
void function_context_end_invocation(ZzHookFunctionEntry *entry, zz_ptr_t next_hop, RegState *rs) {
    ZZ_DEBUG_LOG("%p call end-invocation", entry->target_ptr);

    ZzThreadStack *stack = ZzGetCurrentThreadStack(entry->thread_local_key);
    if (!stack) {
#if defined(DEBUG_MODE)
        debug_break();
#endif
    }
    ZzCallStack *callstack = ZzPopCallStack(stack);

    /* call post_call */
    if (entry->post_call) {
        POSTCALL post_call;
        HookEntryInfo entry_info;
        entry_info.hook_id      = entry->id;
        entry_info.hook_address = entry->target_ptr;
        post_call               = entry->post_call;
        (*post_call)(rs, (ThreadStack *)stack, (CallStack *)callstack, (const HookEntryInfo *)&entry_info);
    }

    /* set next hop */
    *(zz_ptr_t *)next_hop = callstack->caller_ret_addr;
    ZzFreeCallStack(callstack);
}
Ejemplo n.º 3
0
// just like post_call, wow!
void function_context_end_invocation(ZzHookFunctionEntry *entry, zpointer next_hop, RegState *rs) {
    Xdebug("%p call end-invocation", entry->target_ptr);

    ZzThreadStack *threadstack = ZzGetCurrentThreadStack(entry->thread_local_key);
    if (!threadstack) {
#if defined(DEBUG_MODE)
        debug_break();
#endif
    }
    ZzCallStack *callstack = ZzPopCallStack(threadstack);

    /* call post_call */
    if (entry->post_call) {
        POSTCALL post_call;
        post_call = entry->post_call;
        (*post_call)(rs, (ThreadStack *)threadstack, (CallStack *)callstack);
    }

    /* set next hop */
    *(zpointer *)next_hop = callstack->caller_ret_addr;

    ZzFreeCallStack(callstack);
}
Ejemplo n.º 4
0
// just like pre_call, wow!
void function_context_begin_invocation(ZzHookFunctionEntry *entry, zz_ptr_t next_hop, RegState *rs,
                                       zz_ptr_t caller_ret_addr) {
    ZZ_DEBUG_LOG("target %p call begin-invocation", entry->target_ptr);

    /* for easy debug */
    // if (!strcmp((char *)(rs->general.regs.x1), "_beginBackgroundTaskWithName:expirationHandler:")) {
    // }

    ZzThreadStack *stack = ZzGetCurrentThreadStack(entry->thread_local_key);
    if (!stack) {
        stack = ZzNewThreadStack(entry->thread_local_key);
    }
    ZzCallStack *callstack = ZzNewCallStack();
    ZzPushCallStack(stack, callstack);

    /* call pre_call */
    if (entry->pre_call) {
        PRECALL pre_call;
        HookEntryInfo entry_info;
        entry_info.hook_id      = entry->id;
        entry_info.hook_address = entry->target_ptr;
        pre_call                = entry->pre_call;
        (*pre_call)(rs, (ThreadStack *)stack, (CallStack *)callstack, &entry_info);
    }

    /* set next hop */
    if (entry->replace_call) {
        *(zz_ptr_t *)next_hop = entry->replace_call;
    } else {
        *(zz_ptr_t *)next_hop = entry->on_invoke_trampoline;
    }

    if (entry->hook_type == HOOK_FUNCTION_TYPE) {
        callstack->caller_ret_addr   = *(zz_ptr_t *)caller_ret_addr;
        *(zz_ptr_t *)caller_ret_addr = entry->on_leave_trampoline;
    }
}
Ejemplo n.º 5
0
void function_context_half_invocation(ZzHookFunctionEntry *entry, zpointer next_hop, RegState *rs,
                                      zpointer caller_ret_addr) {
    Xdebug("target %p call half-invocation", entry->target_ptr);

    ZzThreadStack *threadstack = ZzGetCurrentThreadStack(entry->thread_local_key);
    if (!threadstack) {
#if defined(DEBUG_MODE)
        debug_break();
#endif
    }
    ZzCallStack *callstack = ZzPopCallStack(threadstack);

    /* call half_call */
    if (entry->half_call) {
        HALFCALL half_call;
        half_call = entry->half_call;
        (*half_call)(rs, (ThreadStack *)threadstack, (CallStack *)callstack);
    }

    /* set next hop */
    *(zpointer *)next_hop = (zpointer)entry->target_half_ret_addr;

    ZzFreeCallStack(callstack);
}