8
8
* License: GNU/GPLv2
9
9
* @see LICENSE.txt
10
10
*
11
- * This file: The scanner (last modified: 2020.10.30 ).
11
+ * This file: The scanner (last modified: 2020.11.20 ).
12
12
*/
13
13
14
14
namespace phpMussel \Core ;
@@ -581,7 +581,7 @@ private function recursor($Files = '', int $Depth = -1)
581
581
}
582
582
583
583
/** Cleanup. */
584
- unset($ CompressionResults , $ CompressionObject );
584
+ unset($ CompressionObject );
585
585
}
586
586
587
587
$ inLen = strlen ($ in );
@@ -736,6 +736,15 @@ private function dataHandler(string $str = '', int $Depth = 0, string $OriginalF
736
736
$ $ Algo = hash ($ Algo , $ str );
737
737
}
738
738
739
+ /** Scan target has no name? That's a little suspicious. */
740
+ if (!$ OriginalFilename ) {
741
+ $ this ->Loader ->atHit ($ sha256 , $ StringLength , '' , sprintf (
742
+ $ this ->Loader ->L10N ->getString ('grammar_exclamation_mark ' ),
743
+ $ this ->Loader ->L10N ->getString ('scan_missing_filename ' )
744
+ ), 2 , $ Depth );
745
+ return ;
746
+ }
747
+
739
748
/** Needed for hash caching plus some other checks. */
740
749
$ AtInstanceLookupKey = sprintf ('%s:%d:%s ' , $ sha256 , $ StringLength , $ OriginalFilename );
741
750
@@ -751,21 +760,12 @@ private function dataHandler(string $str = '', int $Depth = 0, string $OriginalF
751
760
*/
752
761
$ CoExMeta = '' ;
753
762
foreach (['OriginalFilename ' , 'Depth ' , 'StringLength ' , 'md5 ' , 'sha1 ' , 'sha256 ' , 'crc32b ' , 'fourcc ' , 'twocc ' ] as $ AppendToCoExMeta ) {
754
- if (!empty ($ $ $ AppendToCoExMeta )) {
763
+ if (!empty ($ $ AppendToCoExMeta )) {
755
764
$ CoExMeta .= '$ ' . $ AppendToCoExMeta . ': ' . $ $ AppendToCoExMeta . '; ' ;
756
765
}
757
766
}
758
767
unset($ AppendToCoExMeta );
759
768
760
- /** Scan target has no name? That's a little suspicious. */
761
- if (!$ OriginalFilename ) {
762
- $ this ->Loader ->atHit ($ sha256 , $ StringLength , '' , sprintf (
763
- $ this ->Loader ->L10N ->getString ('grammar_exclamation_mark ' ),
764
- $ this ->Loader ->L10N ->getString ('scan_missing_filename ' )
765
- ), 2 , $ Depth );
766
- return ;
767
- }
768
-
769
769
/**
770
770
* Check whether the file being scanned has already been recently
771
771
* scanned before, to reduce needless work.
@@ -2414,10 +2414,14 @@ private function archiveRecursor(string $Data, string $File = '', int $ScanDepth
2414
2414
$ Handler = 'TarHandler ' ;
2415
2415
$ ConType = 'TarFile ' ;
2416
2416
$ this ->Loader ->InstanceCache ['container ' ] = 'tarfile ' ;
2417
- } elseif (substr ($ Data , 0 , 4 ) === 'Rar! ' || substr ($ Data , 0 , 4 ) === "\x52\x45\x7e\x5e" ) {
2417
+ } elseif (substr ($ Data , 0 , 4 ) === 'Rar! ' || substr ($ Data , 0 , 4 ) === ' RE~^ ' ) {
2418
2418
$ Handler = 'RarHandler ' ;
2419
2419
$ ConType = 'RarFile ' ;
2420
2420
$ this ->Loader ->InstanceCache ['container ' ] = 'rarfile ' ;
2421
+ } elseif (substr ($ Data , 0 , 4 ) === "\x25PDF " ) {
2422
+ $ Handler = 'PdfHandler ' ;
2423
+ $ ConType = 'PdfFile ' ;
2424
+ $ this ->Loader ->InstanceCache ['container ' ] = 'pdffile ' ;
2421
2425
}
2422
2426
2423
2427
/** Not an archive. Exit early. */
@@ -2454,7 +2458,7 @@ private function archiveRecursor(string $Data, string $File = '', int $ScanDepth
2454
2458
}
2455
2459
2456
2460
/** Guard. */
2457
- if (!class_exists ('ZipArchive ' )) {
2461
+ if (!class_exists ('\ ZipArchive ' )) {
2458
2462
if (!$ this ->Loader ->Configuration ['signatures ' ]['fail_extensions_silently ' ]) {
2459
2463
$ this ->Loader ->atHit ($ DataHash , $ DataLen , $ ItemRef , $ this ->Loader ->L10N ->getString ('scan_extensions_missing ' ), -1 , $ ScanDepth );
2460
2464
return ;
@@ -2494,7 +2498,7 @@ private function archiveRecursor(string $Data, string $File = '', int $ScanDepth
2494
2498
if ($ Handler === 'RarHandler ' ) {
2495
2499
2496
2500
/** Guard. */
2497
- if (!class_exists ('RarArchive ' ) || !class_exists ('RarEntry ' )) {
2501
+ if (!class_exists ('\ RarArchive ' ) || !class_exists ('\ RarEntry ' )) {
2498
2502
if (!$ this ->Loader ->Configuration ['signatures ' ]['fail_extensions_silently ' ]) {
2499
2503
$ this ->Loader ->atHit ($ DataHash , $ DataLen , $ ItemRef , $ this ->Loader ->L10N ->getString ('scan_extensions_missing ' ), -1 , $ ScanDepth );
2500
2504
return ;
@@ -2523,6 +2527,28 @@ private function archiveRecursor(string $Data, string $File = '', int $ScanDepth
2523
2527
}
2524
2528
}
2525
2529
2530
+ /** Handle PDF files. */
2531
+ if ($ Handler === 'PdfHandler ' ) {
2532
+
2533
+ /** Encryption guard. */
2534
+ if ($ this ->Loader ->Configuration ['files ' ]['block_encrypted_archives ' ]) {
2535
+ if (preg_match ('~xref.*/Encrypt .*startxref$~ ' , $ Data )) {
2536
+ $ this ->Loader ->atHit ($ DataHash , $ DataLen , $ ItemRef , sprintf (
2537
+ $ this ->Loader ->L10N ->getString ('grammar_exclamation_mark ' ),
2538
+ sprintf (
2539
+ $ this ->Loader ->L10N ->getString ('grammar_brackets ' ),
2540
+ $ this ->Loader ->L10N ->getString ('encrypted_archive ' ),
2541
+ $ ItemRef
2542
+ )
2543
+ ), -4 , $ ScanDepth );
2544
+ return ;
2545
+ }
2546
+ }
2547
+
2548
+ /** PdfHandler can work with data directly. */
2549
+ $ ArchiveObject = new PdfHandler ($ Data );
2550
+ }
2551
+
2526
2552
/** Archive object has been instantiated. Let's proceed. */
2527
2553
if (isset ($ ArchiveObject ) && is_object ($ ArchiveObject )) {
2528
2554
@@ -3006,7 +3032,7 @@ private function memoryUse(string $Path, int $Delete = 0, int $DeleteFiles = 0):
3006
3032
$ List = new \RecursiveIteratorIterator (new \RecursiveDirectoryIterator ($ Path ), \RecursiveIteratorIterator::SELF_FIRST );
3007
3033
foreach ($ List as $ Item => $ List ) {
3008
3034
$ File = str_replace ("\\" , '/ ' , substr ($ Item , $ Offset ));
3009
- if ($ File && preg_match ( ' ~\.qfu$~i ' , $ Item ) && is_file ($ Item ) && !is_link ($ Item ) && is_readable ($ Item )) {
3035
+ if ($ File && strtolower ( substr ( $ Item , - 4 )) === ' .qfu ' && is_file ($ Item ) && !is_link ($ Item ) && is_readable ($ Item )) {
3010
3036
$ Files [$ File ] = filemtime ($ Item );
3011
3037
}
3012
3038
}
@@ -3088,7 +3114,7 @@ function_exists('gzinflate') &&
3088
3114
}
3089
3115
if ($ c = preg_match_all (
3090
3116
'/(hex2bin\s*\(\s*[" \'])([\da-f]{1,4096})([" \']\s*\))/i ' ,
3091
- $ str , $ matches )) {
3117
+ $ str , $ matches )) {
3092
3118
for ($ i = 0 ; $ c > $ i ; $ i ++) {
3093
3119
$ str = str_ireplace (
3094
3120
$ matches [0 ][$ i ],
@@ -3758,7 +3784,7 @@ private function metaDataScan(string $ItemRef, string $Filename, string &$Data,
3758
3784
3759
3785
/** Determine whether the file being scanned is a macro. */
3760
3786
$ this ->Loader ->InstanceCache ['file_is_macro ' ] = (
3761
- preg_match ( ' ~vbaProject\.bin$~i ' , $ Filename ) ||
3787
+ strtolower ( substr ( $ Filename , - 14 )) === ' vbaproject.bin ' ||
3762
3788
preg_match ('~^\xd0\xcf|\x00Attribut|\x01CompObj|\x05Document~ ' , $ Data )
3763
3789
);
3764
3790
@@ -3805,7 +3831,7 @@ private function metaDataScan(string $ItemRef, string $Filename, string &$Data,
3805
3831
}
3806
3832
3807
3833
/** Cleanup. */
3808
- unset($ CompressionResults , $ CompressionObject );
3834
+ unset($ CompressionObject );
3809
3835
}
3810
3836
3811
3837
/** Reset Crx variables. */
0 commit comments