Find all hex starting with and has fixed length #2103
-
Improving on top of #1996 (comment). I want to find all packets starting from import type.base;
import std.mem;
u32 PACKET_SIZE = 74;
struct Packet {
$ += 2;
u16 length;
type::Hex<u8> data[while((length > PACKET_SIZE) && ($[$]!=0x55 || $[$+1] != 0xAA) && !std::mem::eof())];
};
std::mem::MagicSearch<"\x55\xAA", Packet> find@0; This doesn't seem to work, because the loop doesn't wait for the length for the packet, here is a screenshot You can see that the size differs between each |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
The instructions of what you want to accomplish seem contradictory. First you imply that you want to read from the magic sequence for a fixed length but then you state that the sizes between magic numbers is not the same. Depending on which of the two is the one you are after the code will have to be different. |
Beta Was this translation helpful? Give feedback.
There is a mistake. if you wanted to find the magic sequence you would write
the while inside the array wants to avoid finding them which is the negative of finding them so it should be
So in the code change
($[$]!=0x55 && $[$+1] != 0xAA)
to($[$]!=0x55 || $[$+1] != 0xAA)
and then it should work for you. The reason it didnt read the 0x55 is because the&&
makes it avoid either0x55
or0xAA
so when it finds0x55
it stops.It actually was correct in the code you posted.