Changeset 278
- Timestamp:
- 10/02/07 16:07:57 (1 year ago)
- Files:
-
- MMagic/trunk/ChangeLog (modified) (1 diff)
- MMagic/trunk/MMagic.pm (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
MMagic/trunk/ChangeLog
r273 r278 1 2007-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 1 7 2006-09-19 NOKUBI Takatsugu <knok@daionet.gr.jp> 2 8 MMagic/trunk/MMagic.pm
r275 r278 787 787 if (@$item == 3){ 788 788 my $tmp = readMagicLine(@$item); 789 return unless defined($tmp); 789 790 @$item = @$tmp; 790 791 } … … 825 826 } 826 827 827 if ($type =~ /^string/ ) {828 if ($type =~ /^string/ || $type =~ /^regex/) { 828 829 # read the length of the match string unless the 829 830 # comparison is '>' ($numbytes == 0), in which case … … 850 851 $match = ($data gt $testval); 851 852 } 853 elsif ($op eq 'match') { 854 $data = ($data || '') ? $data : ''; 855 $match = $data =~ /$testval/; 856 } 852 857 # else bogus op, but don't die, just skip 853 858 … … 856 861 } 857 862 863 } 864 elsif ($type =~ /^search\//) 865 { 858 866 } 859 867 else { … … 985 993 } 986 994 987 if ($type =~ /^string/ ) {995 if ($type =~ /^string/ || $type =~ /^regex/) { 988 996 # read the length of the match string unless the 989 997 # comparison is '>' ($numbytes == 0), in which case … … 1007 1015 $match = ($data gt $testval); 1008 1016 } 1017 elsif ($op eq 'match') { 1018 $match = eval {($data || '') =~ /$testval/}; 1019 } 1020 1009 1021 # else bogus op, but don't die, just skip 1010 1022 … … 1013 1025 } 1014 1026 1027 } 1028 elsif ($type =~ /^search\//) 1029 { 1015 1030 } 1016 1031 else { … … 1248 1263 1249 1264 # check if type is valid 1250 if (!exists($TEMPLATES{$type}) && $type !~ /^string/ ) {1265 if (!exists($TEMPLATES{$type}) && $type !~ /^string/ && $type !~ /^regex/ && $type !~ /^search\//) { 1251 1266 warn "Invalid type '$type' at line $line_num\n"; 1252 1267 return; … … 1266 1281 1267 1282 # 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 } 1275 1295 1276 1296 1277 if ($type =~ /string/) { 1297 if ($type =~ /^string/ || $type =~ /^regex/) 1298 { 1278 1299 $testval = $line; 1279 1300 … … 1301 1322 $numbytes = length($testval); 1302 1323 $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; 1303 1329 } 1304 1330 else { … … 1311 1337 return; 1312 1338 } 1339 } 1340 elsif ($type =~ /^search\//) 1341 { 1313 1342 } 1314 1343 else { … … 1350 1379 if (@$entry == 3){ 1351 1380 my $tmp = readMagicLine(@$entry); 1381 next if (! $tmp); 1352 1382 @$entry = @$tmp; 1353 1383 }
