Note
This system is still in an experimental phase, so there may be several problems.
Important
Technical Purpose: These files provide the low-level "Firewall" mechanism that allows Wasabi to use high-performance, event-driven networking without crashing Excel during development.
In standard VBA networking, using WSAAsyncSelect (Event-driven IO) is dangerous. When you click the Reset (Blue Square) button in the Visual Basic Editor:
- VBA clears all variables and pointers from memory.
- The Windows OS, however, still holds the network socket and attempts to send messages to the now-deleted memory address (
AddressOf). - This "Jump to Nowhere" causes an immediate and fatal Excel Crash.
The files in this directory contain the Assembly (x86/x64) source for a "Safe Thunk." This thunk acts as an intermediary between Windows and VBA.
- Heartbeat Check: Before forwarding a network event to the VBA code, the Thunk checks a specific memory address (the "Flag").
- Safe Routing: * If Flag = 1: The VBA project is active; the Thunk forwards the message to
Wasabi_WndProc.- If Flag = 0: The user clicked Reset; the Thunk ignores the VBA code and safely redirects the message to the default Windows handler (
DefWindowProcW).
- If Flag = 0: The user clicked Reset; the Thunk ignores the VBA code and safely redirects the message to the default Windows handler (
Beyond stability, the Wasabi project utilizes specialized thunks to handle data processing tasks that are inefficient in native VBA:
- WebSocket Masking: Implements the high-speed XOR bitwise operations required by the WebSocket protocol for all client-to-server data frames.
- Fast Memory Zero: A lightweight alternative to
RtlZeroMemoryfor clearing buffers or network structures with minimal overhead. - High-Speed Memory Search: An ultra-fast implementation using hardware-level byte comparison (
repe cmpsb) to find byte patterns (needle in a haystack) within large TCP buffers, bypassing slow VBA loops. - Fast Tick Difference: A micro-optimized subtraction routine that safely handles 32-bit unsigned integer wraparound for precise time calculations (e.g., ping intervals and timeouts), bypassing slow native VBA workarounds.
These thunks are injected into executable memory at runtime using the VirtualAlloc API with PAGE_EXECUTE_READWRITE permissions.
To prevent memory leaks (Zombies) after a Reset, Wasabi uses Window Properties (SetProp) to tag the allocated memory addresses on the invisible event window. Upon the next initialization, the system:
- Scans for existing windows named
WasabiEvents. - Recovers the memory addresses from the previous session.
- Frees the "Zombie" memory before allocating a fresh Thunk.
The Thunk adds approximately 5-10 CPU cycles of overhead per network event. This is negligible compared to the thousands of cycles saved by eliminating the standard DoEvents polling loops.
To test and verify the Assembly thunks, you need to assemble the .asm source files into raw machine code (binary format). This allows you to extract the exact opcodes used in the RtlMoveMemory operations within the VBA module.
The Netwide Assembler (NASM) is the industry standard for this task. It is lightweight and can output raw binary files without the overhead of headers (like PE or ELF).
- Download the NASM executable from nasm.us.
- Add the NASM directory to your Windows System PATH or run it directly from the folder.
You must compile these files using the -f bin flag. This ensures the output is a pure stream of processor instructions.
nasm -f bin safe_thunk_x64.asm -o safe_thunk_x64.bin