Skip to content

Commit 9024c01

Browse files
authored
Merge pull request #6 from swiftly-solution/dev
2 parents 6a4f969 + ab5b9c4 commit 9024c01

File tree

4 files changed

+482
-11
lines changed

4 files changed

+482
-11
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
edition = "2024"
55

66
[lib]
7-
crate-type = ["staticlib", "dylib", "rlib"]
7+
crate-type = ["staticlib", "dylib"]
88

99
[profile.release]
1010
opt-level = 3

s2binlib.h

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,132 @@ extern "C"
244244
*/
245245
int s2binlib_find_vtable_va(const char *binary_name, const char *vtable_name, void **result);
246246

247+
/**
248+
* Find a vtable by mangled name and return its virtual address
249+
*
250+
* Searches for a vtable using the mangled/decorated RTTI name directly.
251+
* Unlike s2binlib_find_vtable_va which auto-decorates the name, this function
252+
* uses the provided name as-is.
253+
*
254+
* If the binary is not yet loaded, it will be loaded automatically.
255+
*
256+
* @param binary_name Name of the binary to search (null-terminated C string)
257+
* @param vtable_name Mangled RTTI name to search for (null-terminated C string)
258+
* - Windows: ".?AVClassName@@" format
259+
* - Linux: "{length}ClassName" format
260+
* @param result Pointer to store the resulting vtable virtual address
261+
*
262+
* @return 0 on success (address written to result)
263+
* -1 if S2BinLib not initialized
264+
* -2 if invalid parameters
265+
* -3 if failed to load binary
266+
* -4 if vtable not found
267+
* -5 if internal error
268+
*
269+
* @example
270+
* // Windows mangled name example
271+
* void* vtable_va;
272+
* int result = s2binlib_find_vtable_mangled_va("server", ".?AVCBaseEntity@@", &vtable_va);
273+
* if (result == 0) {
274+
* printf("VTable VA: %p\n", vtable_va);
275+
* }
276+
*
277+
* // Linux mangled name example
278+
* int result = s2binlib_find_vtable_mangled_va("server", "11CBaseEntity", &vtable_va);
279+
*/
280+
int s2binlib_find_vtable_mangled_va(const char *binary_name, const char *vtable_name, void **result);
281+
282+
/**
283+
* Find a vtable by mangled name and return its runtime memory address
284+
*
285+
* Searches for a vtable using the mangled/decorated RTTI name directly and
286+
* returns its runtime memory address.
287+
*
288+
* If the binary is not yet loaded, it will be loaded automatically.
289+
*
290+
* @param binary_name Name of the binary to search (null-terminated C string)
291+
* @param vtable_name Mangled RTTI name to search for (null-terminated C string)
292+
* - Windows: ".?AVClassName@@" format
293+
* - Linux: "{length}ClassName" format
294+
* @param result Pointer to store the resulting vtable memory address
295+
*
296+
* @return 0 on success (address written to result)
297+
* -1 if S2BinLib not initialized
298+
* -2 if invalid parameters
299+
* -3 if failed to load binary
300+
* -4 if vtable not found
301+
* -5 if internal error
302+
*
303+
* @example
304+
* void* vtable_addr;
305+
* int result = s2binlib_find_vtable_mangled("server", ".?AVCBaseEntity@@", &vtable_addr);
306+
* if (result == 0) {
307+
* printf("VTable at: %p\n", vtable_addr);
308+
* }
309+
*/
310+
int s2binlib_find_vtable_mangled(const char *binary_name, const char *vtable_name, void **result);
311+
312+
/**
313+
* Find a nested vtable (2 levels) by class names and return its virtual address
314+
*
315+
* Searches for a vtable of a nested class (e.g., Class1::Class2).
316+
* The function automatically decorates the names according to the platform's
317+
* RTTI name mangling scheme:
318+
* - Windows: ".?AVClass2@Class1@@"
319+
* - Linux: "N{len1}Class1{len2}Class2E"
320+
*
321+
* If the binary is not yet loaded, it will be loaded automatically.
322+
*
323+
* @param binary_name Name of the binary to search (null-terminated C string)
324+
* @param class1_name Outer class name (null-terminated C string)
325+
* @param class2_name Inner/nested class name (null-terminated C string)
326+
* @param result Pointer to store the resulting vtable virtual address
327+
*
328+
* @return 0 on success (address written to result)
329+
* -1 if S2BinLib not initialized
330+
* -2 if invalid parameters
331+
* -3 if failed to load binary
332+
* -4 if vtable not found
333+
* -5 if internal error
334+
*
335+
* @example
336+
* void* vtable_va;
337+
* int result = s2binlib_find_vtable_nested_2_va("server", "CEntitySystem", "CEntitySubsystem", &vtable_va);
338+
* if (result == 0) {
339+
* printf("Nested VTable VA: %p\n", vtable_va);
340+
* }
341+
*/
342+
int s2binlib_find_vtable_nested_2_va(const char *binary_name, const char *class1_name, const char *class2_name, void **result);
343+
344+
/**
345+
* Find a nested vtable (2 levels) by class names and return its runtime memory address
346+
*
347+
* Searches for a vtable of a nested class (e.g., Class1::Class2) and returns
348+
* its runtime memory address.
349+
*
350+
* If the binary is not yet loaded, it will be loaded automatically.
351+
*
352+
* @param binary_name Name of the binary to search (null-terminated C string)
353+
* @param class1_name Outer class name (null-terminated C string)
354+
* @param class2_name Inner/nested class name (null-terminated C string)
355+
* @param result Pointer to store the resulting vtable memory address
356+
*
357+
* @return 0 on success (address written to result)
358+
* -1 if S2BinLib not initialized
359+
* -2 if invalid parameters
360+
* -3 if failed to load binary
361+
* -4 if vtable not found
362+
* -5 if internal error
363+
*
364+
* @example
365+
* void* vtable_addr;
366+
* int result = s2binlib_find_vtable_nested_2("server", "CEntitySystem", "CEntitySubsystem", &vtable_addr);
367+
* if (result == 0) {
368+
* printf("Nested VTable at: %p\n", vtable_addr);
369+
* }
370+
*/
371+
int s2binlib_find_vtable_nested_2(const char *binary_name, const char *class1_name, const char *class2_name, void **result);
372+
247373
/**
248374
* Find a symbol by name in the specified binary
249375
*

0 commit comments

Comments
 (0)