Skip to content

Find all hex starting with #1996

Answered by paxcut
akshaybabloo asked this question in Get Help
Discussion options

You must be logged in to vote

You are missing some details as to how you want to find these sequences and what happens if the magic numbers 0x55,0xAA are not in the data. Assuming that data starts and end with said sequence and assuming you want to write a pattern to find these sequences the following should work:

import type.base;
import std.mem;

struct ReadRow {
    $ += 2;
    type::Hex<u8> data[while(($[$]!=0x55 || $[$+1] != 0xAA) && !std::mem::eof())];
};

str seq="\x55\xAA";

std::mem::MagicSearch<seq,ReadRow> find@0;

I tested it on some made-up data and it seems to work.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by akshaybabloo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants