feat: port CTaskFilter::HandleMessage to Rust
Browse filesReplace the message subscription filter (vtable slot 2, 0x54F4A0).
Original is just 8 instructions — checks subscription_table[msg_type]
and either drops the message or tail-calls CTask::HandleMessage.
Rust replacement uses the typed subscription_table field directly:
messages with type < 98 are forwarded only if subscribed, messages
>= 98 always pass through. Unsubscribed messages are silently dropped.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
crates/openwa-wormkit/src/replacements/task/filter.rs
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//! CTaskFilter vtable hooks.
|
| 2 |
+
//!
|
| 3 |
+
//! Replaces CTaskFilter::HandleMessage (vtable slot 2).
|
| 4 |
+
//! Gate-keeps message propagation via a per-instance subscription table.
|
| 5 |
+
|
| 6 |
+
use openwa_core::address::va;
|
| 7 |
+
use openwa_core::log::log_line;
|
| 8 |
+
use openwa_core::task::filter::CTaskFilter;
|
| 9 |
+
use openwa_core::task::{CTask, Task};
|
| 10 |
+
|
| 11 |
+
/// CTaskFilter::HandleMessage replacement.
|
| 12 |
+
///
|
| 13 |
+
/// Messages with `msg_type < 98` are only forwarded if
|
| 14 |
+
/// `subscription_table[msg_type] != 0`. Messages >= 98 always pass through.
|
| 15 |
+
/// Forwarding means tail-calling base CTask::HandleMessage, which propagates
|
| 16 |
+
/// the message down to child tasks.
|
| 17 |
+
unsafe extern "thiscall" fn filter_handle_message(
|
| 18 |
+
this: *mut CTaskFilter,
|
| 19 |
+
sender: *mut CTask,
|
| 20 |
+
msg_type: u32,
|
| 21 |
+
size: u32,
|
| 22 |
+
data: *const u8,
|
| 23 |
+
) {
|
| 24 |
+
let filter = &*this;
|
| 25 |
+
|
| 26 |
+
// Check subscription table — messages >= 98 always pass through
|
| 27 |
+
if (msg_type as usize) < filter.subscription_table.len()
|
| 28 |
+
&& filter.subscription_table[msg_type as usize] == 0
|
| 29 |
+
{
|
| 30 |
+
return; // message not subscribed — drop silently
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
// Forward to base CTask::HandleMessage (propagates to children)
|
| 34 |
+
let base_handler: unsafe extern "thiscall" fn(*mut CTask, *mut CTask, u32, u32, *const u8) =
|
| 35 |
+
core::mem::transmute(openwa_core::rebase::rb(va::CTASK_VT2_HANDLE_MESSAGE) as usize);
|
| 36 |
+
base_handler(filter.as_task_ptr() as *mut CTask, sender, msg_type, size, data);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
pub fn install() -> Result<(), String> {
|
| 40 |
+
use openwa_core::vtable_replace;
|
| 41 |
+
|
| 42 |
+
vtable_replace!(openwa_core::task::filter::CTaskFilterVTable, va::CTASK_FILTER_VTABLE, {
|
| 43 |
+
handle_message => filter_handle_message,
|
| 44 |
+
})?;
|
| 45 |
+
|
| 46 |
+
let _ = log_line("[Filter] HandleMessage hooked via vtable_replace");
|
| 47 |
+
Ok(())
|
| 48 |
+
}
|
crates/openwa-wormkit/src/replacements/task/mod.rs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
mod cloud;
|
|
|
|
| 2 |
|
| 3 |
pub fn install() -> Result<(), String> {
|
| 4 |
cloud::install()?;
|
|
|
|
| 5 |
Ok(())
|
| 6 |
}
|
|
|
|
| 1 |
mod cloud;
|
| 2 |
+
mod filter;
|
| 3 |
|
| 4 |
pub fn install() -> Result<(), String> {
|
| 5 |
cloud::install()?;
|
| 6 |
+
filter::install()?;
|
| 7 |
Ok(())
|
| 8 |
}
|