Giter VIP home page Giter VIP logo

patternscan's People

Contributors

lewisclark avatar tomstoneham avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

patternscan's Issues

Patterns that cross reader chunk boundaries are not found

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())
}

Consider making Pattern API public

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 u8s 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.

scan & scan_first_match return incorrect indices for patterns occurring past the first chunk

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 ๐Ÿ˜†

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.