| 1497 | } |
| 1498 | |
| 1499 | void java_hook_on_enter(int hook_index, uint64_t* saved_regs) { |
| 1500 | if (hook_index < 0 || hook_index >= g_java_hook_count) { |
| 1501 | LOGE("Invalid Java hook index: %d", hook_index); |
| 1502 | return; |
| 1503 | } |
| 1504 | |
| 1505 | JavaHookInfo* hook = &g_java_hooks[hook_index]; |
| 1506 | |
| 1507 | if (g_hook_call_stack.depth < MAX_HOOK_CALL_DEPTH) { |
| 1508 | g_hook_call_stack.hook_indices[g_hook_call_stack.depth] = hook_index; |
| 1509 | g_hook_call_stack.depth++; |
| 1510 | } else { |
| 1511 | LOGW("Hook call stack overflow! depth=%d, skipping hook #%d", |
| 1512 | g_hook_call_stack.depth, hook_index); |
| 1513 | return; |
| 1514 | } |
| 1515 | |
| 1516 | g_current_java_hook_index = hook_index; |
| 1517 | |
| 1518 | LOGI("=== Java Hook #%d onEnter: %s.%s%s (depth=%d) ===", |
| 1519 | hook_index, hook->class_name, hook->method_name, hook->method_sig, |
| 1520 | g_hook_call_stack.depth); |
| 1521 | |
| 1522 | uint64_t x0 = saved_regs[0]; |
| 1523 | uint64_t x1 = saved_regs[1]; |
| 1524 | uint64_t x2 = saved_regs[2]; |
| 1525 | uint64_t x3 = saved_regs[3]; |
| 1526 | |
| 1527 | LOGI(" Args: X0=0x%llx X1=0x%llx X2=0x%llx X3=0x%llx", |
| 1528 | (unsigned long long)x0, (unsigned long long)x1, |
| 1529 | (unsigned long long)x2, (unsigned long long)x3); |
| 1530 | |
| 1531 | hook->skip_original = false; |
| 1532 | |
| 1533 | if (hook->lua_onEnter_ref != LUA_NOREF && g_lua_engine) { |
| 1534 | pthread_mutex_lock(&g_java_lua_mutex); |
| 1535 | lua_State* L = lua_engine_get_state(g_lua_engine); |
| 1536 | if (L) { |
| 1537 | lua_rawgeti(L, LUA_REGISTRYINDEX, hook->lua_onEnter_ref); |
| 1538 | |
| 1539 | lua_newtable(L); |
| 1540 | |
| 1541 | lua_pushstring(L, hook->class_name); |
| 1542 | lua_setfield(L, -2, "class"); |
| 1543 | lua_pushstring(L, hook->method_name); |
| 1544 | lua_setfield(L, -2, "method"); |
| 1545 | lua_pushstring(L, hook->method_sig); |
| 1546 | lua_setfield(L, -2, "signature"); |
| 1547 | lua_pushboolean(L, hook->is_static); |
| 1548 | lua_setfield(L, -2, "isStatic"); |
| 1549 | |
| 1550 | for (int i = 0; i < 8; i++) { |
| 1551 | lua_pushinteger(L, saved_regs[i]); |
| 1552 | lua_rawseti(L, -2, i); |
| 1553 | } |
| 1554 | |
| 1555 | lua_pushvalue(L, -1); |
| 1556 | int args_ref = luaL_ref(L, LUA_REGISTRYINDEX); |
nothing calls this directly
no test coverage detected