#pattern-matching #binary-data #match #help #flexible #search #reverse-engineering

bmatcher

bmatcher is a flexible and efficient binary pattern matching library designed to help you search and match binary data

7 releases

new 0.2.4 Dec 10, 2024
0.2.3 Dec 10, 2024
0.1.2 Dec 2, 2024
0.1.1 Nov 30, 2024

#1025 in Text processing

Download history 188/week @ 2024-11-25 215/week @ 2024-12-02 433/week @ 2024-12-09

836 downloads per month

Custom license

105KB
2K SLoC

bmatcher - Your Easy Binary Pattern Matcher   Latest Version License: GPL v3 GitHub build status

bmatcher is a flexible and efficient binary pattern matching library designed to help you search and match binary data.

Motivation

Reverse engineering is challenging. When you identify an interesting address, such as a function or global variable, you don't want to lose all that effort when the program is updated.

The good news is that, during updates, programs usually don't change drastically. While some functions and data may be altered, much of the program remains unchanged. However, this means that the unchanged parts might be moved to different addresses.

This is where patterns come in. Patterns allow you to track these interesting parts of a program, even as it evolves and updates. By using patterns, you can identify specific functions, data references, or other critical locations, regardless of where they end up after a program update.

Getting Started

To use bmatcher, add it as a dependency in your Cargo.toml:

[dependencies]
bmatcher = "0.1"

Creating a pattern

An exhausive overview of the pattern syntax and operads can be found here.

Basic Usage

Here's a simple example demonstrating how to use bmatcher to match a call signature binary pattern:

let data: &[u8] = ...;
let pattern = pattern!("
    /*
     * call my_function
     * $ = follow 4 byte relative jump
     * ' = save cursor position to the matched stack
     */
    E8 $ { ' }

    /* mov QWORD PTR [rsp], rax */
    48 89 04 24

    /* jmp somewhere */
    E9 [4]
");

let mut matcher = BinaryMatcher::new(&pattern, &data);
let Some(match_stack) = matcher.next_match() else {
    panic!("failed to find pattern");
};

println!("Matched at location 0x{:X}", match_stack[0]);
println!("Target function located at 0x{:X}", match_stack[1]);

Dependencies

~220–660KB
~16K SLoC