Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ This library mainly read data from original binary file instead of from memory,
- Install trampoline to vtable with enough bytes padded with NOP (for safetyhook to hook empty virtual function)
- Find all CEmbeddedNetworkVar NetworkStateChanged function index
- Follow xref safely
- Dump vtables
- Dump entity classes (dumper)
- Dump vtable diffs (dumper)
- Dump game system overrides (dumper)
- Dump network var vtables (dumper)


## Project Layout

- `s2binlib`: core Rust library crate exposing safe APIs.
- `s2binlib_binding`: C ABI wrapper crate that links to `s2binlib` and produces the `s2binlib` DLL/LIB artifacts.
- `s2binlib_dumper`: A dumper based on s2binlib for dumping game related data.

## Compiling

Expand Down Expand Up @@ -58,7 +65,7 @@ On windows, if you are seeing linking error like `"__imp_NtReadFile"`, you also

## Example

Example code:
Example code:

```cpp
#include <s2binlib.h>
Expand Down
39 changes: 2 additions & 37 deletions s2binlib/src/s2binlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,6 @@ impl S2BinLib {
))
}

fn find_pattern_string(&self, binary_name: &str, string: &str) -> Result<u64> {
let bytes = string.as_bytes().to_vec();
// bytes.push(0); // null terminato

self.find_pattern_bytes(binary_name, &bytes)
}

fn find_pattern_string_in_section(
&self,
binary_name: &str,
Expand All @@ -347,12 +340,6 @@ impl S2BinLib {
self.find_pattern_bytes_in_section(binary_name, section_name, &bytes)
}

fn find_pattern_bytes(&self, binary_name: &str, pattern: &[u8]) -> Result<u64> {
let binary_data = self.get_binary(binary_name)?;
let pattern_wildcard = vec![];
find_pattern_simd(binary_data, pattern, &pattern_wildcard)
}

fn find_pattern_int32_in_section(
&self,
binary_name: &str,
Expand Down Expand Up @@ -396,7 +383,7 @@ impl S2BinLib {

fn find_pattern_va(&self, binary_name: &str, pattern_string: &str) -> Result<u64> {
let result = Cell::new(0);
self.pattern_scan_all_va(binary_name, pattern_string, |index, address| {
self.pattern_scan_all_va(binary_name, pattern_string, |_, address| {
result.set(address);
true
})?;
Expand Down Expand Up @@ -848,17 +835,6 @@ impl S2BinLib {
Ok(self.va_to_mem_address(binary_name, result)?)
}

/// Dump cross-references from all executable sections
///
/// This function scans all executable sections in the binary, disassembles
/// the instructions using iced-x86, and extracts cross-references (xrefs).
/// The results are cached in the `xrefs_cache` HashMap.
///
/// # Arguments
/// * `binary_name` - The name of the binary to analyze
///
/// # Returns
/// Returns Ok(()) on success, or an error if the binary cannot be processed
pub fn dump_xrefs(&mut self, binary_name: &str) -> Result<()> {
let binary_data = self.get_binary(binary_name)?;
let object = object::File::parse(binary_data)?;
Expand Down Expand Up @@ -981,17 +957,6 @@ impl S2BinLib {
Ok(())
}

/// Get cached cross-references for a target virtual address
///
/// Returns None if the binary hasn't been analyzed with `dump_xrefs` yet,
/// or if there are no references to the target address.
///
/// # Arguments
/// * `binary_name` - The name of the binary
/// * `target_va` - The target virtual address to find references to
///
/// # Returns
/// An optional reference to a vector of virtual addresses that reference the target
pub fn find_xrefs_cached(&self, binary_name: &str, target_va: u64) -> Option<&Vec<u64>> {
self.xrefs_cache
.get(binary_name)
Expand Down Expand Up @@ -1239,7 +1204,7 @@ impl S2BinLib {

let success = Cell::new(false);

if (warmup < warmup_threshold) {
if warmup < warmup_threshold {
warmup += 1;
continue;
}
Expand Down
19 changes: 19 additions & 0 deletions s2binlib/src/vtable.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/************************************************************************************
* S2BinLib - A static library that helps resolving memory from binary file
* and map to absolute memory address, targeting source 2 game engine.
* Copyright (C) 2025 samyyc
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
***********************************************************************************/

use std::collections::{HashMap, HashSet};

use anyhow::{anyhow, Result};
Expand Down
Loading