简体   繁体   English

在字节数组中查找字节模式

[英]Find Pattern of Bytes in Byte Array

today I am trying to find a pattern of bytes in an array (in this case pointer) 今天,我试图在数组中找到字节模式(在这种情况下为指针)

I do know I could use std::string needle() and haystack etc. but I was wondering if I could use that with BYTE (unsigned char)? 我知道我可以使用std :: stringneedle()和haystack等。但是我想知道是否可以将其与BYTE(无符号字符)一起使用?

I also know the length of the BYTE *_zone so that's not an issue either. 我也知道BYTE * _zone的长度,所以这也不是问题。 Any ways I could go forth to do this? 我有什么办法可以做到这一点? (also any code examples are appreciated :)) (也欢迎任何代码示例:)

Thanks again! 再次感谢!

std::string is actually a typedef for std::basic_string<char> . std::string实际上是std::basic_string<char>的typedef。 You can use std::basic_string<BYTE> instead, and most (all?) std::string functionality, in particular .find() , will just work. 您可以改用std::basic_string<BYTE> ,并且大多数(全部?) std::string功能(尤其是.find()都可以使用。

如果您不想使用现有的库函数,请实现自己喜欢的通用字符串匹配算法,例如Knuth-Morris-PrattBoyer-MooreRabin-Karp

The find() method of std::string is a member function that is intended to find another std::string or a character array char* inside the std::string std::stringfind()方法是一个成员函数,旨在在std::string查找另一个std::string或字符数组char*

So to answer your question if the haystack is a std::string you should be able to pass the char* arrays directly to the find methods. 因此,如果干草堆是std::string来回答您的问题,则应该可以将char*数组直接传递给find方法。

If the haystack is not a std::string you can make a std::string out of it and then do the same. 如果干草堆不是std::string ,则可以用它制成std::string ,然后执行相同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM