@@ -94,22 +94,22 @@ |
||
94 | 94 | } |
95 | 95 | // starting byte sequence |
96 | 96 | if (array_key_exists('starting', $signature['signature'])) { |
97 | - foreach ($signature['signature']['starting']['bytes'] as $bytes) { |
|
98 | - if (preg_match($bytes, strtolower(bin2hex(substr($data, $signature['signature']['starting']['offset'], strlen($bytes) / 2))))) { |
|
99 | - $isFileCorrupted = false; |
|
100 | - } |
|
101 | - } |
|
97 | + foreach ($signature['signature']['starting']['bytes'] as $bytes) { |
|
98 | + if (preg_match($bytes, strtolower(bin2hex(substr($data, $signature['signature']['starting']['offset'], strlen($bytes) / 2))))) { |
|
99 | + $isFileCorrupted = false; |
|
100 | + } |
|
101 | + } |
|
102 | 102 | } |
103 | 103 | // trailing byte sequence |
104 | 104 | if (array_key_exists('trailing', $signature['signature'])) { |
105 | 105 | $trailingIsNotMatching = true; |
106 | - foreach ($signature['signature']['trailing']['bytes'] as $bytes) { |
|
107 | - $trailingOffset = strlen($data) - $signature['signature']['trailing']['offset'] - strlen($bytes) / 2; |
|
108 | - if (preg_match($bytes, strtolower(bin2hex(substr($data, $trailingOffset, strlen($bytes) / 2))))) { |
|
109 | - $trailingIsNotMatching = false; |
|
110 | - } |
|
111 | - } |
|
112 | - $isFileCorrupted = $isFileCorrupted || $trailingIsNotMatching; |
|
106 | + foreach ($signature['signature']['trailing']['bytes'] as $bytes) { |
|
107 | + $trailingOffset = strlen($data) - $signature['signature']['trailing']['offset'] - strlen($bytes) / 2; |
|
108 | + if (preg_match($bytes, strtolower(bin2hex(substr($data, $trailingOffset, strlen($bytes) / 2))))) { |
|
109 | + $trailingIsNotMatching = false; |
|
110 | + } |
|
111 | + } |
|
112 | + $isFileCorrupted = $isFileCorrupted || $trailingIsNotMatching; |
|
113 | 113 | return new FileCorruptionResult($isFileCorrupted); |
114 | 114 | } |
115 | 115 | return new FileCorruptionResult($isFileCorrupted); |
@@ -144,23 +144,23 @@ |
||
144 | 144 | return 0.0; |
145 | 145 | } |
146 | 146 | |
147 | - /** |
|
148 | - * Calculates the median of an array. |
|
149 | - * |
|
150 | - * @param array $array |
|
151 | - * |
|
152 | - * @return float |
|
153 | - */ |
|
154 | - public function median($array) |
|
155 | - { |
|
156 | - if (is_array($array) && count($array) > 0) { |
|
157 | - $count = count($array); |
|
158 | - sort($array); |
|
159 | - $mid = floor(($count - 1) / 2); |
|
160 | - |
|
161 | - return ($array[$mid] + $array[$mid + 1 - $count % 2]) / 2; |
|
162 | - } |
|
163 | - |
|
164 | - return 0.0; |
|
165 | - } |
|
147 | + /** |
|
148 | + * Calculates the median of an array. |
|
149 | + * |
|
150 | + * @param array $array |
|
151 | + * |
|
152 | + * @return float |
|
153 | + */ |
|
154 | + public function median($array) |
|
155 | + { |
|
156 | + if (is_array($array) && count($array) > 0) { |
|
157 | + $count = count($array); |
|
158 | + sort($array); |
|
159 | + $mid = floor(($count - 1) / 2); |
|
160 | + |
|
161 | + return ($array[$mid] + $array[$mid + 1 - $count % 2]) / 2; |
|
162 | + } |
|
163 | + |
|
164 | + return 0.0; |
|
165 | + } |
|
166 | 166 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | |
28 | 28 | class FilesEvents { |
29 | 29 | |
30 | - /** @var string */ |
|
30 | + /** @var string */ |
|
31 | 31 | private $userId; |
32 | 32 | |
33 | 33 | /** @var ILogger */ |
@@ -37,74 +37,74 @@ discard block |
||
37 | 37 | private $monitor; |
38 | 38 | |
39 | 39 | |
40 | - /** |
|
40 | + /** |
|
41 | 41 | * @param ILogger $logger |
42 | 42 | * @param Monitor $monitor |
43 | - * @param string $userId |
|
44 | - */ |
|
45 | - public function __construct( |
|
43 | + * @param string $userId |
|
44 | + */ |
|
45 | + public function __construct( |
|
46 | 46 | ILogger $logger, |
47 | 47 | Monitor $monitor, |
48 | 48 | $userId |
49 | 49 | |
50 | - ) { |
|
50 | + ) { |
|
51 | 51 | $this->logger = $logger; |
52 | 52 | $this->monitor = $monitor; |
53 | - $this->userId = $userId; |
|
54 | - } |
|
53 | + $this->userId = $userId; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @param array $params |
|
58 | - */ |
|
59 | - public function onFileUpdate(array $params) { |
|
56 | + /** |
|
57 | + * @param array $params |
|
58 | + */ |
|
59 | + public function onFileUpdate(array $params) { |
|
60 | 60 | $this->logger->debug("Updating ".$params['path'].": Params: ".print_r($params, true), ['app' => Application::APP_ID]); |
61 | 61 | $this->analyze([$params['path']], Monitor::WRITE); |
62 | - } |
|
62 | + } |
|
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * @param array $params |
|
67 | - */ |
|
68 | - public function onFileRename(array $params) { |
|
65 | + /** |
|
66 | + * @param array $params |
|
67 | + */ |
|
68 | + public function onFileRename(array $params) { |
|
69 | 69 | $this->logger->debug("Renaming ".$params['oldpath']." to ".$params['newpath'].": Params: ".print_r($params, true), ['app' => Application::APP_ID]); |
70 | 70 | $this->analyze([$params['oldpath'], $params['newpath']], Monitor::RENAME); |
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
74 | - * @param array $params |
|
75 | - */ |
|
74 | + * @param array $params |
|
75 | + */ |
|
76 | 76 | public function onFileCreate(array $params) { |
77 | 77 | $this->logger->debug("Creating ".$params['path'].": Params: ".print_r($params, true), ['app' => Application::APP_ID]); |
78 | 78 | $this->analyze([$params['path']], Monitor::CREATE); |
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
82 | - * @param array $params |
|
83 | - */ |
|
82 | + * @param array $params |
|
83 | + */ |
|
84 | 84 | public function onFileWrite(array $params) { |
85 | 85 | $this->logger->debug("Writing ".$params['path'].": Params: ".print_r($params, true), ['app' => Application::APP_ID]); |
86 | 86 | $this->analyze([$params['path']], Monitor::WRITE); |
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
90 | - * @param array $params |
|
91 | - */ |
|
90 | + * @param array $params |
|
91 | + */ |
|
92 | 92 | public function onFileDelete(array $params) { |
93 | 93 | $this->logger->debug("Deleting ".$params['path'].": Params: ".print_r($params, true), ['app' => Application::APP_ID]); |
94 | 94 | $this->analyze([$params['path']], Monitor::DELETE); |
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
98 | - * @param array $params |
|
99 | - */ |
|
98 | + * @param array $params |
|
99 | + */ |
|
100 | 100 | public function onFileCopy(array $params) { |
101 | 101 | $this->logger->debug("Copying ".$params['oldpath']." to ".$params['newpath'].": Params: ".print_r($params, true), ['app' => Application::APP_ID]); |
102 | 102 | $this->analyze([$params['oldpath'], $params['newpath']], Monitor::RENAME); |
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
106 | - * @param array $params |
|
107 | - */ |
|
106 | + * @param array $params |
|
107 | + */ |
|
108 | 108 | public function onFileTouch(array $params) { |
109 | 109 | $this->logger->debug("Touching ".$params['path'].": Params: ".print_r($params, true), ['app' => Application::APP_ID]); |
110 | 110 | $this->analyze([$params['path']], Monitor::WRITE); |
@@ -26,86 +26,86 @@ |
||
26 | 26 | |
27 | 27 | class FilesHooks { |
28 | 28 | |
29 | - /** |
|
30 | - * Retrieve the FilesEvents' Controller. |
|
31 | - * |
|
32 | - * @return FilesEvents |
|
33 | - */ |
|
34 | - protected static function getController(): FilesEvents { |
|
35 | - $app = new Application(); |
|
29 | + /** |
|
30 | + * Retrieve the FilesEvents' Controller. |
|
31 | + * |
|
32 | + * @return FilesEvents |
|
33 | + */ |
|
34 | + protected static function getController(): FilesEvents { |
|
35 | + $app = new Application(); |
|
36 | 36 | |
37 | - return $app->getContainer() |
|
38 | - ->query(FilesEvents::class); |
|
39 | - } |
|
37 | + return $app->getContainer() |
|
38 | + ->query(FilesEvents::class); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Hook events: file is updated. |
|
43 | - * |
|
44 | - * @param array $params |
|
45 | - */ |
|
46 | - public static function onFileUpdate(array $params) { |
|
47 | - self::getController() |
|
48 | - ->onFileUpdate($params); |
|
49 | - } |
|
41 | + /** |
|
42 | + * Hook events: file is updated. |
|
43 | + * |
|
44 | + * @param array $params |
|
45 | + */ |
|
46 | + public static function onFileUpdate(array $params) { |
|
47 | + self::getController() |
|
48 | + ->onFileUpdate($params); |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * Hook events: file is renamed. |
|
54 | - * |
|
55 | - * @param array $params |
|
56 | - */ |
|
57 | - public static function onFileRename(array $params) { |
|
58 | - self::getController() |
|
59 | - ->onFileRename($params); |
|
52 | + /** |
|
53 | + * Hook events: file is renamed. |
|
54 | + * |
|
55 | + * @param array $params |
|
56 | + */ |
|
57 | + public static function onFileRename(array $params) { |
|
58 | + self::getController() |
|
59 | + ->onFileRename($params); |
|
60 | 60 | } |
61 | 61 | |
62 | - /** |
|
63 | - * Hook events: file is created. |
|
64 | - * |
|
65 | - * @param array $params |
|
66 | - */ |
|
62 | + /** |
|
63 | + * Hook events: file is created. |
|
64 | + * |
|
65 | + * @param array $params |
|
66 | + */ |
|
67 | 67 | public static function onFileCreate(array $params) { |
68 | - self::getController() |
|
69 | - ->onFileCreate($params); |
|
68 | + self::getController() |
|
69 | + ->onFileCreate($params); |
|
70 | 70 | } |
71 | 71 | |
72 | - /** |
|
73 | - * Hook events: file is written. |
|
74 | - * |
|
75 | - * @param array $params |
|
76 | - */ |
|
72 | + /** |
|
73 | + * Hook events: file is written. |
|
74 | + * |
|
75 | + * @param array $params |
|
76 | + */ |
|
77 | 77 | public static function onFileWrite(array $params) { |
78 | - self::getController() |
|
79 | - ->onFileWrite($params); |
|
78 | + self::getController() |
|
79 | + ->onFileWrite($params); |
|
80 | 80 | } |
81 | 81 | |
82 | - /** |
|
83 | - * Hook events: file is deleted. |
|
84 | - * |
|
85 | - * @param array $params |
|
86 | - */ |
|
82 | + /** |
|
83 | + * Hook events: file is deleted. |
|
84 | + * |
|
85 | + * @param array $params |
|
86 | + */ |
|
87 | 87 | public static function onFileDelete(array $params) { |
88 | - self::getController() |
|
89 | - ->onFileDelete($params); |
|
88 | + self::getController() |
|
89 | + ->onFileDelete($params); |
|
90 | 90 | } |
91 | 91 | |
92 | - /** |
|
93 | - * Hook events: file is touched. |
|
94 | - * |
|
95 | - * @param array $params |
|
96 | - */ |
|
92 | + /** |
|
93 | + * Hook events: file is touched. |
|
94 | + * |
|
95 | + * @param array $params |
|
96 | + */ |
|
97 | 97 | public static function onFileTouch(array $params) { |
98 | - self::getController() |
|
99 | - ->onFileTouch($params); |
|
98 | + self::getController() |
|
99 | + ->onFileTouch($params); |
|
100 | 100 | } |
101 | 101 | |
102 | - /** |
|
103 | - * Hook events: file is copied. |
|
104 | - * |
|
105 | - * @param array $params |
|
106 | - */ |
|
102 | + /** |
|
103 | + * Hook events: file is copied. |
|
104 | + * |
|
105 | + * @param array $params |
|
106 | + */ |
|
107 | 107 | public static function onFileCopy(array $params) { |
108 | - self::getController() |
|
109 | - ->onFileCopy($params); |
|
110 | - } |
|
108 | + self::getController() |
|
109 | + ->onFileCopy($params); |
|
110 | + } |
|
111 | 111 | } |
112 | 112 | \ No newline at end of file |