lewisclark / patternscan Goto Github PK
View Code? Open in Web Editor NEWSearches for a contiguous array of bytes determined by a wild-carded pattern
License: MIT License
Searches for a contiguous array of bytes determined by a wild-carded pattern
License: MIT License
A pattern between the chunk boundary defined by CHUNK_SIZE will not be found. The failing test below demonstrates this:
#[test]
fn find_across_chunk_boundary() {
let mut bytes = vec![0; super::CHUNK_SIZE - 2];
bytes.push(0xaa);
bytes.push(0xbb);
bytes.push(0xcc);
bytes.push(0xdd);
let pattern = "aa bb cc dd";
assert!(crate::scan_first_match(Cursor::new(bytes), &pattern).unwrap().is_some())
}
One thought I've had while working with this crate is that it would be nice if the Pattern
and PatternByte
APIs were publicly exposed. My reasoning for this is that it would allow developers who know the search pattern at compile time to just pass a Pattern
to scan
directly, without the need for parsing a pattern string. Furthermore, this goes some way to enforce compile-time checking of known patterns, as if a Pattern
is constructed from u8
s directly, it must inherently be valid.
I'm happy to put together a pull request for this if you agree it would be useful, just interested to hear your thoughts before I go ahead.
The current implementation of both scan
and scan_first_match
returns the position of each pattern match within a given chunk, rather than within the overall byte string read. This is because we don't keep track of what chunk we're in, and the loop through the bytes in each chunk starts from i = 0
each time. Here's a quick test case demonstrating the issue:
use patternscan;
use std::io::Cursor;
let mut bytes = vec![0; 0x800];
let mut more_bytes = vec![0x10, 0x20, 0x30, 0x40];
bytes.append(&mut more_bytes);
let pattern = "10 20 30 40";
assert_eq!(patternscan::scan_first_match(Cursor::new(bytes), &pattern)
.unwrap()
.unwrap(),
0x800); // Fails: left = 0, right = 2048
I'm currently working on a fix for this and #4, as well as updating the API a bit, so hopefully I'll be able to submit a pull request for that this evening, just need to escape from my family for a while to have the time ๐
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.