Mon Dec 22 2025
S2BinLib - A Multifunctional Memory Tool Library Written in Rust
To provide convenient memory tools for plugins (pattern scanning, finding vtables, and so on) while keeping compatibility, I developed the S2BinLib subproject. The main focus of this project is that most memory lookup operations are done by reading the binary file rather than the module in memory. The advantage is that it avoids the problem where another framework has already hooked some functions, changing the signature so it can't be scanned, or has already replaced a function pointer in a vtable, etc. S2BinLib does all its lookups from the binary file and provides an easy way to go from a real memory address to the module's RVA and then to a file offset for reading.
This Rust library can export both statically linked and dynamically linked versions, and can be compiled for whichever one you need. It was originally designed to support only static linking, but later I found that, unless explicitly declared otherwise, functions on Linux are exported by default. That means if the library is used in two projects at the same time and both are loaded into one process, it can lead to ELF symbol hijacking, which isn't very elegant.
Project: swiftly-solution/s2binlib
Initialization
Starting with initialization, s2binlib provides a simple initialization method; one line of code sets up the paths it needs ahead of time.
s2binlib_initialize("/home/csgo/cs2server/game", "csgo");
You can also use the s2binlib_initialize_with_os method. In theory, all functions that don't involve memory addresses or modules are cross-platform compatible, which is why a dumper can absolutely read binaries for two platforms on one platform.
If you're using Metamod, you also need to reset the server module's base address. Metamod injects its own server.dll with the same name at startup, hijacking the DLL load path so it can load plugins.
GET_V_IFACE_ANY(GetServerFactory, g_pSource2Server, ISource2Server, SOURCE2SERVER_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, g_pEngineServer2, IVEngineServer2, SOURCE2ENGINETOSERVER_INTERFACE_VERSION);
s2binlib_set_module_base_from_pointer("server", g_pSource2Server);
s2binlib_set_module_base_from_pointer("engine2", g_pEngineServer2);
Pattern Scan (Memory Signatures)
Pattern scan is a way to find the same function across different module versions using a memory signature. It mainly identifies the first few instruction bytes of a function and replaces immediate values with wildcards to keep the signature stable. However, if the function has been inline-hooked in the module, its beginning is often replaced with a jump instruction, which makes the signature fail. s2binlib can scan the original binary file and automatically convert the RVA to a real memory address for the return value.
In addition, s2binlib provides SIMD instruction support for CPUs that support SIMD, making scanning faster.
void* result;
s2binlib_pattern_scan("server", "01 02 03 AA BB CC ? ? DD", &result);
This line of code scans for this memory signature in the server module (cross-platform).
See the docs for return values.
Finding a VTable
When RTTI symbols haven't been stripped, we can get a vtable's real name and inheritance information from its type descriptor name. s2binlib can automatically mangle the vtable name and find the type descriptor's location, thereby locating the vtable. The API call is also simple.
void* vtable_addr;
s2binlib_find_vtable("server", "CBaseEntity", &vtable_addr);
There are many more features like this, such as reading a vtable from the binary file and converting it to real pointers, which prevents runtime vtable pointers from being replaced, etc.
Finding Special NetworkStateChanged Functions
In Source 2's SchemaSystem, some special Network fields have their own vtables. They generate their own NetworkStateChanged functions through macros, and most of them are at different locations. To find all these functions, s2binlib has a built-in search function that can automatically locate them (by matching instruction patterns).
Finding All Xrefs
With Rust's iced disassembly engine, we can parse xref instructions across the whole binary. This helps us locate a lot of information, such as where a vtable is used and so on. But this operation is somewhat time-consuming, so s2binlib provides a function for you to dump it manually, with a built-in cache for later use.
