Changeset 278

Show
Ignore:
Timestamp:
10/02/07 16:07:57 (1 year ago)
Author:
knok
Message:

Added 'regex' and 'search' type for magic entry.
Modified for stability.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • MMagic/trunk/ChangeLog

    r273 r278  
     12007-10-02  NOKUBI Takatsugu  <knok@daionet.gr.jp> 
     2 
     3        * MMagic.pm: Added 'regex' and 'search' support for magic entry, 
     4          and fixed fatal error when unknown type in magic entry. 
     5          (The patch made by Man Min Yan, thank you). 
     6 
    172006-09-19  NOKUBI Takatsugu  <knok@daionet.gr.jp> 
    28 
  • MMagic/trunk/MMagic.pm

    r275 r278  
    787787    if (@$item == 3){ 
    788788        my $tmp = readMagicLine(@$item); 
     789        return unless defined($tmp); 
    789790        @$item = @$tmp; 
    790791    } 
     
    825826    } 
    826827 
    827     if ($type =~ /^string/) { 
     828    if ($type =~ /^string/ || $type =~ /^regex/) { 
    828829        # read the length of the match string unless the 
    829830        # comparison is '>' ($numbytes == 0), in which case  
     
    850851            $match = ($data gt $testval); 
    851852        } 
     853        elsif ($op eq 'match') { 
     854            $data = ($data || '') ? $data : ''; 
     855            $match = $data =~ /$testval/; 
     856        } 
    852857        # else bogus op, but don't die, just skip 
    853858 
     
    856861        } 
    857862 
     863    } 
     864    elsif ($type =~ /^search\//) 
     865    { 
    858866    } 
    859867    else { 
     
    985993    } 
    986994 
    987     if ($type =~ /^string/) { 
     995    if ($type =~ /^string/ || $type =~ /^regex/) { 
    988996        # read the length of the match string unless the 
    989997        # comparison is '>' ($numbytes == 0), in which case  
     
    10071015            $match = ($data gt $testval); 
    10081016        } 
     1017        elsif ($op eq 'match') { 
     1018            $match = eval {($data || '') =~ /$testval/}; 
     1019        } 
     1020 
    10091021        # else bogus op, but don't die, just skip 
    10101022 
     
    10131025        } 
    10141026 
     1027    } 
     1028    elsif ($type =~ /^search\//) 
     1029    { 
    10151030    } 
    10161031    else { 
     
    12481263     
    12491264    # check if type is valid 
    1250     if (!exists($TEMPLATES{$type}) && $type !~ /^string/) { 
     1265    if (!exists($TEMPLATES{$type}) && $type !~ /^string/ && $type !~ /^regex/ && $type !~ /^search\//) { 
    12511266        warn "Invalid type '$type' at line $line_num\n"; 
    12521267        return; 
     
    12661281 
    12671282    # get the operator.  if 'x', must be alone.  default is '='. 
    1268     if ($line =~ s/^([><&^=!])//o) { 
    1269         $operator = $1; 
    1270     } 
    1271     elsif ($line eq 'x') { 
    1272         $operator = 'x'; 
    1273     } 
    1274     else { $operator = '='; } 
     1283    if ($type !~ /regex/) 
     1284    { 
     1285        if ($line =~ s/^([><&^=!])//o) { 
     1286            $operator = $1; 
     1287        } 
     1288        elsif ($line eq 'x') { 
     1289            $operator = 'x'; 
     1290        } 
     1291        else { $operator = '='; } 
     1292    } else { 
     1293        $operator = 'match'; 
     1294    } 
    12751295     
    12761296 
    1277     if ($type =~ /string/) { 
     1297    if ($type =~ /^string/ || $type =~ /^regex/) 
     1298    { 
    12781299        $testval = $line; 
    12791300 
     
    13011322            $numbytes = length($testval); 
    13021323            $operator = '='; 
     1324        } 
     1325        elsif ($operator eq 'match') { 
     1326            eval {"" =~ /$testval/};    # Check the regex 
     1327            warn "Invalid regex at line $line_num - $@\n" if ($@); 
     1328            $numbytes = 0; 
    13031329        } 
    13041330        else { 
     
    13111337            return; 
    13121338        } 
     1339    } 
     1340    elsif ($type =~ /^search\//) 
     1341    { 
    13131342    } 
    13141343    else { 
     
    13501379        if (@$entry == 3){ 
    13511380            my $tmp = readMagicLine(@$entry); 
     1381            next if (! $tmp); 
    13521382            @$entry = @$tmp; 
    13531383        }