ByteScanner is a module for scanning binary files(or buffers) for specific byte patterns using the Boyer-Moore algorithm.
To install ByteScanner, use npm:
npm install byte-scanner
or bun
bun add byte-scanner
import { ByteScanner } from "byte-scanner";
// Create a new instance of ByteScanner
const filePath = "./path/to/your/binary/file";
/* or you can use a buffer
const Buffer = [72, 101, 108, 108, 111];
or if you want to use a hex string instead
import { hexStrToBuf } from "byte-scanner"
const Buffer = hexStrToBuf("fa e0")
*/
const scanner = new ByteScanner(filePath);
// Set pattern
scanner.setPattern("fa??"); // you can use "??" as a wildcard, this matches any byte
// Scan for occurrences
const occurrences = scanner.scan();
// Log the occurrences found
console.log(
"Occurrences found at indexes:",
occurrences.map((offset) => {
return `0x${offset.toString(16).toUpperCase()}`; // convert the address to a string
}),
);
Creates a new instance of ByteScanner with the specified options(a filepath or buffer).
options
: the file path option (filePath
) is where the scanning will be performed.
Sets the pattern to be searched for in the file.
pattern
: A string representing the byte pattern to search for. Use'??'
to match any byte.
Scans the file for occurrences of the set pattern and returns the result.
Returns the buffer of the input hex
Contributions are welcome! Please feel free to submit issues or pull requests.