Skip to content

Fix packet send hook, JNI class lookups, and script timer reset - #22

Merged
Lynxifyy merged 1 commit into
mainfrom
fix/verified-audit-findings
Dec 1, 2026
Merged

Lynxifyy merged 1 commit into
mainfrom
fix/verified-audit-findings

Conversation

@Lynxifyy

@Lynxifyy Lynxifyy commented Dec 1, 2026

Copy link
Copy Markdown
Owner

This PR was created by an AI agent (OpenHands) on behalf of @Lynxifyy.

Four verified defects, each confirmed against current main and fixed with a test where the code is host-buildable.

1. Outbound packet hook targeted the receive function

BerryClient::BuildPacketCapture installed the send hook on cfg.packetReceiveTarget, which is already hooked a few lines above. PacketReceiveHook::Install then always failed with AlreadyHooked, so outbound capture never worked.

-  if (cfg.captureOutboundPackets) {
+  if (cfg.captureOutboundPackets && cfg.packetSendTarget) {
     packetSendHook_ = std::make_unique<PacketReceiveHook>();
-    if (!packetSendHook_->Install(cfg.packetReceiveTarget, ...
+    if (!packetSendHook_->Install(cfg.packetSendTarget, ...

ClientConfig gains a packetSendTarget (null by default, so the send path stays off unless the embedder supplies it). tests/test_packet_capture.cpp now asserts both paths: no send target leaves the send hook uninstalled, and a real send target hooks the send function (original still runs, one packet captured).

2. FindClass("android.app.ActivityThread") always threw

JNI class names use /. The dotted form raised ClassNotFoundException and left a pending exception that aborted the next JNI call. Now android/app/ActivityThread, with pending exceptions cleared on each failure path.

3. Script execution timer could underflow into a spurious Timeout

vmctx_.nativeMs was accumulated but never reset on Load/Start/Resume, so SteadyMs() - startMs - nativeMs wrapped as u64 and tripped ScriptStatus::Timeout. It is now reset at each (re)start.

4. CMake did not register the tests

Added enable_testing() before the per-file test loop so ctest sees them.

Verification

make test (full suite, including check-warnings/check-werror) passes: == all tests passed ==, with test_packet_capture, test_luau, and test_multicast_lock green.

@Lynxifyy can click here to continue refining the PR

- Install the outbound packet hook on a distinct packetSendTarget instead of
  reusing packetReceiveTarget (which is already hooked, so the install always
  failed with AlreadyHooked). Add packetSendTarget to ClientConfig and cover the
  no-target and real-target paths in the packet-capture test.
- Use the JNI '/' name for android/app/ActivityThread and clear pending
  exceptions so a missing class no longer aborts the process.
- Reset vmctx_.nativeMs on every (re)start so the execution deadline cannot
  underflow into a spurious Timeout.
- Call enable_testing() so ctest sees the per-file test binaries.
@Lynxifyy
Lynxifyy merged commit 0221a8f into main Dec 1, 2026
7 checks passed
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

Successfully merging this pull request may close these issues.

1 participant