Skip to content

Commit 0680548

Browse files
committed
Refactoring.
1 parent 2a7a0a5 commit 0680548

File tree

2 files changed

+33
-31
lines changed

2 files changed

+33
-31
lines changed

src/Scanner.php

+31-29
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: The scanner (last modified: 2020.10.18).
11+
* This file: The scanner (last modified: 2020.10.30).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -58,6 +58,8 @@ class Scanner
5858

5959
/**
6060
* Construct the scanner.
61+
*
62+
* @param \phpMussel\Core\Loader $Loader The instantiated loader object, passed by reference.
6163
*/
6264
public function __construct(\phpMussel\Core\Loader &$Loader)
6365
{
@@ -992,13 +994,13 @@ private function dataHandler(string $str = '', int $Depth = 0, string $OriginalF
992994
if (
993995
strpos(',FD,FD-RX,FD-NORM,FD-NORM-RX,', ',' . $Fragment[0] . ',') === false || (
994996
$Fragment[0] === 'FD' &&
995-
strpos("\x01" . substr($str_hex, 0, $Fragment[3] * 2), "\x01" . $Fragment[1]) === false
997+
strpos("\1" . substr($str_hex, 0, $Fragment[3] * 2), "\1" . $Fragment[1]) === false
996998
) || (
997999
$Fragment[0] === 'FD-RX' &&
9981000
!preg_match('/\A(?:' . $Fragment[1] . ')/i', substr($str_hex, 0, $Fragment[3] * 2))
9991001
) || (
10001002
$Fragment[0] === 'FD-NORM' &&
1001-
strpos("\x01" . substr($str_hex_norm, 0, $Fragment[3] * 2), "\x01" . $Fragment[1]) === false
1003+
strpos("\1" . substr($str_hex_norm, 0, $Fragment[3] * 2), "\1" . $Fragment[1]) === false
10021004
) || (
10031005
$Fragment[0] === 'FD-NORM-RX' &&
10041006
!preg_match('/\A(?:' . $Fragment[1] . ')/i', substr($str_hex_norm, 0, $Fragment[3] * 2))
@@ -1031,13 +1033,13 @@ private function dataHandler(string $str = '', int $Depth = 0, string $OriginalF
10311033
!preg_match('/\A(?:' . $Fragment[1] . ')/i', $OriginalFilename)
10321034
) || (
10331035
$Fragment[0] === 'FD' &&
1034-
strpos("\x01" . $str_hex, "\x01" . $Fragment[1]) === false
1036+
strpos("\1" . $str_hex, "\1" . $Fragment[1]) === false
10351037
) || (
10361038
$Fragment[0] === 'FD-RX' &&
10371039
!preg_match('/\A(?:' . $Fragment[1] . ')/i', $str_hex)
10381040
) || (
10391041
$Fragment[0] === 'FD-NORM' &&
1040-
strpos("\x01" . $str_hex_norm, "\x01" . $Fragment[1]) === false
1042+
strpos("\1" . $str_hex_norm, "\1" . $Fragment[1]) === false
10411043
) || (
10421044
$Fragment[0] === 'FD-NORM-RX' &&
10431045
!preg_match('/\A(?:' . $Fragment[1] . ')/i', $str_hex_norm)
@@ -1174,7 +1176,7 @@ private function dataHandler(string $str = '', int $Depth = 0, string $OriginalF
11741176
'SectionHead' => substr($str, $PEArr['Offset'] + 24 + $PEArr['OptHdrSize'] + ($PEArr['k'] * 40), $NumOfSections * 40)
11751177
];
11761178
$PEArr['SectionArr'][$PEArr['k']]['SectionName'] =
1177-
str_ireplace("\x00", '', substr($PEArr['SectionArr'][$PEArr['k']]['SectionHead'], 0, 8));
1179+
str_ireplace("\0", '', substr($PEArr['SectionArr'][$PEArr['k']]['SectionHead'], 0, 8));
11781180
$PEArr['SectionArr'][$PEArr['k']]['VirtualSize'] =
11791181
$this->Loader->unpackSafe('S', substr($PEArr['SectionArr'][$PEArr['k']]['SectionHead'], 8, 4));
11801182
$PEArr['SectionArr'][$PEArr['k']]['VirtualSize'] =
@@ -1210,22 +1212,22 @@ private function dataHandler(string $str = '', int $Depth = 0, string $OriginalF
12101212
$SizeOfRawData . ':' . $PEArr['SectionArr'][$PEArr['k']]['sha256'] . ':'
12111213
];
12121214
}
1213-
if (strpos($str, "V\x00a\x00r\x00F\x00i\x00l\x00e\x00I\x00n\x00f\x00o\x00\x00\x00\x00\x00\x24") !== false) {
1214-
$PEArr['Parts'] = $this->Loader->substrAfterLast($str, "V\x00a\x00r\x00F\x00i\x00l\x00e\x00I\x00n\x00f\x00o\x00\x00\x00\x00\x00\x24");
1215+
if (strpos($str, "V\0a\0r\0F\0i\0l\0e\0I\0n\0f\0o\0\0\0\0\0\x24") !== false) {
1216+
$PEArr['Parts'] = $this->Loader->substrAfterLast($str, "V\0a\0r\0F\0i\0l\0e\0I\0n\0f\0o\0\0\0\0\0\x24");
12151217
$PEArr['FINFO'] = [];
12161218
foreach ([
1217-
["F\x00i\x00l\x00e\x00D\x00e\x00s\x00c\x00r\x00i\x00p\x00t\x00i\x00o\x00n\x00\x00\x00", 'PEFileDescription'],
1218-
["F\x00i\x00l\x00e\x00V\x00e\x00r\x00s\x00i\x00o\x00n\x00\x00\x00", 'PEFileVersion'],
1219-
["P\x00r\x00o\x00d\x00u\x00c\x00t\x00N\x00a\x00m\x00e\x00\x00\x00", 'PEProductName'],
1220-
["P\x00r\x00o\x00d\x00u\x00c\x00t\x00V\x00e\x00r\x00s\x00i\x00o\x00n\x00\x00\x00", 'PEProductVersion'],
1221-
["L\x00e\x00g\x00a\x00l\x00C\x00o\x00p\x00y\x00r\x00i\x00g\x00h\x00t\x00\x00\x00", 'PECopyright'],
1222-
["O\x00r\x00i\x00g\x00i\x00n\x00a\x00l\x00F\x00i\x00l\x00e\x00n\x00a\x00m\x00e\x00\x00\x00", 'PEOriginalFilename'],
1223-
["C\x00o\x00m\x00p\x00a\x00n\x00y\x00N\x00a\x00m\x00e\x00\x00\x00", 'PECompanyName'],
1219+
["F\0i\0l\0e\0D\0e\0s\0c\0r\0i\0p\0t\0i\0o\0n\0\0\0", 'PEFileDescription'],
1220+
["F\0i\0l\0e\0V\0e\0r\0s\0i\0o\0n\0\0\0", 'PEFileVersion'],
1221+
["P\0r\0o\0d\0u\0c\0t\0N\0a\0m\0e\0\0\0", 'PEProductName'],
1222+
["P\0r\0o\0d\0u\0c\0t\0V\0e\0r\0s\0i\0o\0n\0\0\0", 'PEProductVersion'],
1223+
["L\0e\0g\0a\0l\0C\0o\0p\0y\0r\0i\0g\0h\0t\0\0\0", 'PECopyright'],
1224+
["O\0r\0i\0g\0i\0n\0a\0l\0F\0i\0l\0e\0n\0a\0m\0e\0\0\0", 'PEOriginalFilename'],
1225+
["C\0o\0m\0p\0a\0n\0y\0N\0a\0m\0e\0\0\0", 'PECompanyName'],
12241226
] as $PEVars) {
12251227
if (strpos($PEArr['Parts'], $PEVars[0]) !== false && (
1226-
${$PEVars[1]} = trim(str_ireplace("\x00", '', $this->Loader->substrBeforeFirst(
1228+
${$PEVars[1]} = trim(str_ireplace("\0", '', $this->Loader->substrBeforeFirst(
12271229
$this->Loader->substrAfterLast($PEArr['Parts'], $PEVars[0]),
1228-
"\x00\x00\x00"
1230+
"\0\0\0"
12291231
)))
12301232
)) {
12311233
foreach (['md5', 'sha1', 'sha256'] as $TryHash) {
@@ -1309,7 +1311,7 @@ private function dataHandler(string $str = '', int $Depth = 0, string $OriginalF
13091311
) {
13101312
$this->Loader->InstanceCache['LookupCount'] = 0;
13111313
$URLScanner = [
1312-
'FixedSource' => preg_replace('~(data|f(ile|tps?)|https?|sftp):~i', "\x01\\1:", str_replace("\\", '/', $str_norm)) . "\x01",
1314+
'FixedSource' => preg_replace('~(data|f(ile|tps?)|https?|sftp):~i', "\x01\\1:", str_replace("\\", '/', $str_norm)) . "\1",
13131315
'DomainsNoLookup' => [],
13141316
'DomainsCount' => 0,
13151317
'Domains' => [],
@@ -1638,13 +1640,13 @@ private function dataHandler(string $str = '', int $Depth = 0, string $OriginalF
16381640
if ($ThisSigPart[2] === 'A') {
16391641
if (strpos(',FD,FD-RX,FD-NORM,FD-NORM-RX,META,', ',' . $ThisSigPart[0] . ',') === false || (
16401642
$ThisSigPart[0] === 'FD' &&
1641-
strpos("\x01" . substr($str_hex, 0, $ThisSigPart[3] * 2), "\x01" . $ThisSigPart[1]) === false
1643+
strpos("\1" . substr($str_hex, 0, $ThisSigPart[3] * 2), "\1" . $ThisSigPart[1]) === false
16421644
) || (
16431645
$ThisSigPart[0] === 'FD-RX' &&
16441646
!preg_match('/\A(?:' . $ThisSigPart[1] . ')/i', substr($str_hex, 0, $ThisSigPart[3] * 2))
16451647
) || (
16461648
$ThisSigPart[0] === 'FD-NORM' &&
1647-
strpos("\x01" . substr($str_hex_norm, 0, $ThisSigPart[3] * 2), "\x01" . $ThisSigPart[1]) === false
1649+
strpos("\1" . substr($str_hex_norm, 0, $ThisSigPart[3] * 2), "\1" . $ThisSigPart[1]) === false
16481650
) || (
16491651
$ThisSigPart[0] === 'FD-NORM-RX' &&
16501652
!preg_match('/\A(?:' . $ThisSigPart[1] . ')/i', substr($str_hex_norm, 0, $ThisSigPart[3] * 2))
@@ -1682,13 +1684,13 @@ private function dataHandler(string $str = '', int $Depth = 0, string $OriginalF
16821684
!preg_match('/\A(?:' . $ThisSigPart[1] . ')/i', $OriginalFilename)
16831685
) || (
16841686
$ThisSigPart[0] === 'FD' &&
1685-
strpos("\x01" . $str_hex, "\x01" . $ThisSigPart[1]) === false
1687+
strpos("\1" . $str_hex, "\1" . $ThisSigPart[1]) === false
16861688
) || (
16871689
$ThisSigPart[0] === 'FD-RX' &&
16881690
!preg_match('/\A(?:' . $ThisSigPart[1] . ')/i', $str_hex)
16891691
) || (
16901692
$ThisSigPart[0] === 'FD-NORM' &&
1691-
strpos("\x01" . $str_hex_norm, "\x01" . $ThisSigPart[1]) === false
1693+
strpos("\1" . $str_hex_norm, "\1" . $ThisSigPart[1]) === false
16921694
) || (
16931695
$ThisSigPart[0] === 'FD-NORM-RX' &&
16941696
!preg_match('/\A(?:' . $ThisSigPart[1] . ')/i', $str_hex_norm)
@@ -1954,12 +1956,12 @@ private function dataHandler(string $str = '', int $Depth = 0, string $OriginalF
19541956
$ThisString = $$DataSource;
19551957
$this->dataConfineByOffsets($ThisString, $xstrf, $xstrt, $SectionOffsets);
19561958
if ($xstrf === 'A') {
1957-
$ThisString = "\x01" . $ThisString;
1958-
$ThisSig[0] = "\x01" . $ThisSig[0];
1959+
$ThisString = "\1" . $ThisString;
1960+
$ThisSig[0] = "\1" . $ThisSig[0];
19591961
}
19601962
if ($xstrt === 'Z') {
1961-
$ThisString .= "\x01";
1962-
$ThisSig[$ThisSigCount - 1] .= "\x01";
1963+
$ThisString .= "\1";
1964+
$ThisSig[$ThisSigCount - 1] .= "\1";
19631965
}
19641966
for ($ThisSigi = 0; $ThisSigi < $ThisSigCount; $ThisSigi++) {
19651967
if (strpos($ThisString, $ThisSig[$ThisSigi]) === false) {
@@ -2406,7 +2408,7 @@ private function archiveRecursor(string $Data, string $File = '', int $ScanDepth
24062408
$this->Loader->InstanceCache['container'] = 'pkfile';
24072409
}
24082410
} elseif (
2409-
substr($Data, 257, 6) === "ustar\x00" ||
2411+
substr($Data, 257, 6) === "ustar\0" ||
24102412
strpos(',tar,tgz,tbz,tlz,tz,', ',' . $xt . ',') !== false
24112413
) {
24122414
$Handler = 'TarHandler';
@@ -2936,7 +2938,7 @@ public function quarantine(string $In, string $Key, string $IP, string $ID): boo
29362938
}
29372939
$k = strlen($Key);
29382940
$FileSize = strlen($In);
2939-
$Head = "\xa1phpMussel\x21" . $this->Loader->hexSafe(hash('md5', $In)) . pack('l*', $FileSize) . "\x01";
2941+
$Head = "\xa1phpMussel\x21" . $this->Loader->hexSafe(hash('md5', $In)) . pack('l*', $FileSize) . "\1";
29402942
$In = gzdeflate($In, 9);
29412943
$Out = '';
29422944
$i = 0;
@@ -2947,7 +2949,7 @@ public function quarantine(string $In, string $Key, string $IP, string $ID): boo
29472949
}
29482950
$L = substr($In, $i, 1);
29492951
$R = substr($Key, $j, 1);
2950-
$Out .= ($L === false ? "\x00" : $L) ^ ($R === false ? "\x00" : $R);
2952+
$Out .= ($L === false ? "\0" : $L) ^ ($R === false ? "\0" : $R);
29512953
}
29522954
}
29532955
$Out =

src/TarHandler.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: Tar handler (last modified: 2020.07.12).
11+
* This file: Tar handler (last modified: 2020.10.26).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -43,7 +43,7 @@ class TarHandler extends ArchiveHandler
4343
public function __construct($Pointer)
4444
{
4545
/** Guard against wrong type of file used as pointer. */
46-
if (empty($Pointer) || substr($Pointer, 257, 6) !== "ustar\x00") {
46+
if (empty($Pointer) || substr($Pointer, 257, 6) !== "ustar\0") {
4747
$this->ErrorState = 2;
4848
return;
4949
}

0 commit comments

Comments
 (0)