@@ -389,6 +389,70 @@ extern "C"
389389 */
390390 int s2binlib_find_vtable_nested_2 (const char * binary_name , const char * class1_name , const char * class2_name , void * * result );
391391
392+ /**
393+ * Get the number of virtual functions in a vtable
394+ *
395+ * Returns the count of virtual functions (vfuncs) in the specified vtable.
396+ * This counts valid function pointers in the vtable until it encounters a null
397+ * or invalid pointer.
398+ *
399+ * If the binary is not yet loaded, it will be loaded automatically.
400+ *
401+ * @param binary_name Name of the binary to search (e.g., "server", "client")
402+ * @param vtable_name Name of the vtable/class to search for
403+ * @param result Pointer to store the resulting count of virtual functions
404+ *
405+ * @return 0 - Success, result contains the vfunc count
406+ * -1 - S2BinLib not initialized
407+ * -2 - Invalid input (null pointer or invalid UTF-8)
408+ * -4 - Operation failed (vtable not found or other error)
409+ * -5 - Failed to acquire lock
410+ *
411+ * @example
412+ * size_t vfunc_count;
413+ * int result = s2binlib_get_vtable_vfunc_count("server", "CBaseEntity", &vfunc_count);
414+ * if (result == 0) {
415+ * printf("VTable has %zu virtual functions\n", vfunc_count);
416+ * }
417+ */
418+ int s2binlib_get_vtable_vfunc_count (const char * binary_name , const char * vtable_name , size_t * result );
419+
420+ /**
421+ * Get the number of virtual functions in a vtable by virtual address
422+ *
423+ * Returns the count of virtual functions (vfuncs) in a vtable at the specified
424+ * virtual address. This counts valid function pointers in the vtable until it
425+ * encounters a null or invalid pointer.
426+ *
427+ * Unlike s2binlib_get_vtable_vfunc_count, this function takes a virtual address
428+ * directly instead of looking up the vtable by name.
429+ *
430+ * If the binary is not yet loaded, it will be loaded automatically.
431+ *
432+ * @param binary_name Name of the binary (e.g., "server", "client")
433+ * @param vtable_va Virtual address of the vtable
434+ * @param result Pointer to store the resulting count of virtual functions
435+ *
436+ * @return 0 - Success, result contains the vfunc count
437+ * -1 - S2BinLib not initialized
438+ * -2 - Invalid input (null pointer or invalid UTF-8)
439+ * -4 - Operation failed (invalid address or other error)
440+ * -5 - Failed to acquire lock
441+ *
442+ * @example
443+ * void* vtable_va;
444+ * // First get the vtable virtual address
445+ * s2binlib_find_vtable_va("server", "CBaseEntity", &vtable_va);
446+ *
447+ * // Then count its virtual functions
448+ * size_t vfunc_count;
449+ * int result = s2binlib_get_vtable_vfunc_count_by_va("server", (uint64_t)vtable_va, &vfunc_count);
450+ * if (result == 0) {
451+ * printf("VTable has %zu virtual functions\n", vfunc_count);
452+ * }
453+ */
454+ int s2binlib_get_vtable_vfunc_count_by_va (const char * binary_name , uint64_t vtable_va , size_t * result );
455+
392456 /**
393457 * Find a symbol by name in the specified binary
394458 *
@@ -1123,6 +1187,59 @@ extern "C"
11231187 */
11241188 int s2binlib_follow_xref_va_to_va (const char * binary_name , uint64_t va , uint64_t * target_va_out );
11251189
1190+ /**
1191+ * @brief Find the NetworkVar_StateChanged vtable index by virtual address
1192+ *
1193+ * This function scans the vtable at the given virtual address to find the
1194+ * index of the NetworkVar_StateChanged virtual function. It analyzes each
1195+ * virtual function in the vtable looking for the specific instruction pattern
1196+ * that identifies the StateChanged function (cmp dword ptr [reg+56], 0xFF).
1197+ *
1198+ * @param vtable_va Virtual address of the vtable to analyze
1199+ * @param result Pointer to store the resulting index (as uint64_t)
1200+ *
1201+ * @return 0 on success (index written to result)
1202+ * -1 if S2BinLib not initialized
1203+ * -2 if invalid parameters
1204+ * -4 if NetworkVar_StateChanged not found in vtable
1205+ * -5 if internal error
1206+ *
1207+ * @example
1208+ * uint64_t index;
1209+ * int result = s2binlib_find_networkvar_vtable_statechanged_va(0x140001000, &index);
1210+ * if (result == 0) {
1211+ * printf("StateChanged index: %llu\n", index);
1212+ * }
1213+ */
1214+ int s2binlib_find_networkvar_vtable_statechanged_va (uint64_t vtable_va , uint64_t * result );
1215+
1216+ /**
1217+ * @brief Find the NetworkVar_StateChanged vtable index by memory address
1218+ *
1219+ * This function converts the runtime memory address to a virtual address,
1220+ * then scans the vtable to find the index of the NetworkVar_StateChanged
1221+ * virtual function. It analyzes each virtual function in the vtable looking
1222+ * for the specific instruction pattern that identifies the StateChanged function.
1223+ *
1224+ * @param vtable_mem_address Runtime memory address of the vtable
1225+ * @param result Pointer to store the resulting index (as uint64_t)
1226+ *
1227+ * @return 0 on success (index written to result)
1228+ * -1 if S2BinLib not initialized
1229+ * -2 if invalid parameters
1230+ * -3 if address conversion failed
1231+ * -4 if NetworkVar_StateChanged not found in vtable
1232+ * -5 if internal error
1233+ *
1234+ * @example
1235+ * uint64_t index;
1236+ * int result = s2binlib_find_networkvar_vtable_statechanged(vtable_ptr, &index);
1237+ * if (result == 0) {
1238+ * printf("StateChanged index: %llu\n", index);
1239+ * }
1240+ */
1241+ int s2binlib_find_networkvar_vtable_statechanged (uint64_t vtable_mem_address , uint64_t * result );
1242+
11261243#ifdef __cplusplus
11271244}
11281245#endif
0 commit comments