- 论坛徽章:
- 0
|
想用boost的正则匹配任意二进制文件中的"http.exe"字符串,但regex_search()的第一个参数是字符串,文件中遇到NULL就结束了,请问有没有别的办法?
#include <cstdlib>
#include <stdlib.h>
#include <boost/regex.hpp>
#include <string>
#include <iostream>
#include <windows.h>
using namespace std;
using namespace boost;
regex expression("http");
int main(int argc, char* argv[])
{
// char *databuff="wo \nselect name from MZ table where id=8--jj";
cmatch what;
HANDLE hfile=CreateFile("C:\\11.bin",
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ,
0,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
if (hfile==INVALID_HANDLE_VALUE)
{
printf("Open File Err:%d\n",GetLastError());
return 1;
}
DWORD size=GetFileSize(hfile,NULL);
char *databuff=new char[size];
DWORD NumRead;
if (!ReadFile(hfile,databuff,size,&NumRead,NULL))
{
printf("Read File Err:%d",GetLastError());
return 1;
}
if(regex_search(databuff, what, expression,match_default))
{
cout<<"str :"<<what[0]<<endl;
}
else
{
cout<<"Error"<<endl;
}
return 0;
} |
|
|