I am trying to write a simple program to download the latest sysclean and the relevant virus pattern from Trend Micro's website. The first regex I trying to match is the md5 hash, but having trouble to match it.
The code is as follow:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <regex.h>
int main()
{
char filename[100] , buf[4096] , output[102400];
_regmatch_t matches;
_regex_t regex;
FILE *pipe;
strcpy(buf , "[:alnum:]{32}");
_regcomp(®ex , buf , _REG_EXTENDED);
strcpy(filename , "c:\\tools\\curl\\curl.exe -s http://www.trendmicro.com/download/dcs.asp");
pipe = _popen(filename , "r");
while (fgets(buf , 4096 , pipe) != NULL)
{
strncat(output , buf , 4096);
}
_pclose(pipe);
_regexec(®ex , output , 1 , &matches , 0);
strncpy(buf , output + matches.rm_so , matches.rm_eo - matches.rm_so);
buf[matches.rm_eo - matches.rm_so] = '\0';
printf("//%s//%d//%d//" , buf , matches.rm_so , matches.rm_eo);
return 0;
}
I can't match the md5 using [:alnum:]{32}, but is able to match if I use hardcode (46d289a5c4b0c835e5624a7be840cdeb). Can anyone point out where the problem is ?
By the way, I am able to finish a similiar script in PHP in minutes, but have worked for days on C code #-o