Skip to content

Add JSON string dump C binding and avoid function lookup panic - #15

Merged
samyycX merged 1 commit into
masterfrom
agent/dump-strings-json
Aug 8, 2026
Merged

Add JSON string dump C binding and avoid function lookup panic#15
samyycX merged 1 commit into
masterfrom
agent/dump-strings-json

Conversation

@samyycX

@samyycX samyycX commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

What changed

  • Added S2BinLib::dump_strings_to_json to rescan a loaded binary and write printable ASCII strings as a deterministic pretty-printed JSON object mapping string values to RVAs.
  • Added the global C API s2binlib_dump_strings_to_json(binary_name, output_path), including UTF-8/null validation, automatic binary loading, error-code propagation, the static header declaration, and a README example.
  • Replaced the unchecked vtable lookup in find_func_start_rva with safe optional handling. It now falls back to the xref-derived function start and returns an error when neither source has a candidate.
  • Added focused tests for JSON output ordering/RVAs, xref fallback, and the no-candidate error path.

Why

The existing string dumper only populated an in-memory cache, so C consumers could not persist the result. The function-start lookup also unconditionally unwrapped an optional vtable candidate, which could panic when a function was discoverable only through xrefs or when no candidate existed.

Impact

C callers can now write all discovered printable ASCII strings for a binary to a caller-selected JSON path with:

s2binlib_dump_strings_to_json("server", "server_strings.json");

Function-start lookup now fails through the existing Result/C error-code path instead of panicking.

Validation

  • cargo test -p s2binlib s2binlib::tests:: — 3 passed
  • cargo check --workspace — passed (existing warnings remain)
  • cargo build -p s2binlib_binding — passed
  • Verified s2binlib_dump_strings_to_json is exported from the generated Windows DLL with dumpbin /exports

The repository's full pre-existing unit suite still has three unrelated failures: test_find_vtable depends on F:/cs2server/..., and two Windows JIT tests fail while restoring memory protection.

@samyycX
samyycX marked this pull request as ready for review August 8, 2026 10:26
@samyycX
samyycX merged commit 69500ba into master Aug 8, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant