Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c++;cli比较不工作文件中的十六进制字节_C++_Windows_File_C++ Cli_Byte - Fatal编程技术网

C++ c++;cli比较不工作文件中的十六进制字节

C++ c++;cli比较不工作文件中的十六进制字节,c++,windows,file,c++-cli,byte,C++,Windows,File,C++ Cli,Byte,我有一个名为ab.exe的文件,它包含十六进制的 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

我有一个名为ab.exe的文件,它包含十六进制的

0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 BBAAE8CAFDFFF83C40800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000054AAE8CAFDFFF83C40800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000AAE8CAFDFFF83C4088D000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

< >我有C++中的代码,它可以检测十六进制的字符串是否在文件中,如果将它添加到列表框中。
array<Byte>^ target1 = { 0xAA,0xE8,0xCA,0xFD,0xFF,0xFF,0x83,0xC4,0x08,0x8D };
array<Byte>^ target2 = { 0x54,0xAA,0xE8,0xCA,0xFD,0xFF,0xFF,0x83,0xC4,0x08 };
array<Byte>^ target3 = { 0xBB,0xAA,0xE8,0xCA,0xFD,0xFF,0xFF,0x83,0xC4,0x08 };


int matched1 = 0;
int matched2 = 0;
int matched3 = 0;
FileStream^ fs2 = gcnew FileStream(line, FileMode::Open, FileAccess::Read, FileShare::ReadWrite);

int value;
do
{
    value = fs2->ReadByte();
    if (value == target1[matched1]) {
        matched1++;
    }
    else
        matched1 = 0;

    if (value == target2[matched2]) {
        matched2++;
    }
    else
        matched2 = 0;

    if (value == target3[matched3]) {
        matched3++;
    }
    else
        matched3 = 0;

    if(matched1 == target1->Length)
    {
        listBox1->Items->Add(line + "1");

    }

    if(matched2 == target2->Length)
    {
        listBox1->Items->Add(line + "2");

    }

    if(matched3 == target3->Length)
    {
        listBox1->Items->Add(line + "3");

    }
} while (value != -1);

fs2->Close();

在我看来,在第一次匹配一个模式(此处为target3)后,您读取的数据超过了target3的最后一个字节(因为
matched3++
),这可能会导致不期望的行为

更新1:

if(matched1 == target1->Length)
{
  matched1 = 0; // pattern matched so reset counter
  ...
}

你能解释一下怎么修吗。我还添加了一个更新的问题
if(matched1 == target1->Length)
{
  matched1 = 0; // pattern matched so reset counter
  ...
}