Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/undo-ransomware/ransomware_detection.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorUnknown <ilovemilk@wusa.io>2018-12-01 18:18:19 +0300
committerMatthias Held <ilovemilk@wusa.io>2018-12-01 18:29:46 +0300
commit3856ca7560847f0b14acc3134bbbcc6163346d10 (patch)
tree74c719506bb614de459cc4cd4c07f2efe9d39052 /lib
parentc7c886cd3d1b3a7e0f312bdaa86e6bd8da2e9aa7 (diff)
Read data blockwise not everything at once
Diffstat (limited to 'lib')
-rw-r--r--lib/Analyzer/EntropyAnalyzer.php31
1 files changed, 9 insertions, 22 deletions
diff --git a/lib/Analyzer/EntropyAnalyzer.php b/lib/Analyzer/EntropyAnalyzer.php
index 4d6d682..ad913cd 100644
--- a/lib/Analyzer/EntropyAnalyzer.php
+++ b/lib/Analyzer/EntropyAnalyzer.php
@@ -126,35 +126,22 @@ class EntropyAnalyzer
*/
protected function createEntropyArrayFromFile($node, $blockSize)
{
- $data = $node->getContent();
- if (!$data) {
- $this->logger->debug('createEntropyArrayFromFile: Getting data failed.', array('app' => Application::APP_ID));
+ $entropyArray = array();
+
+ $handle = $node->fopen('r');
+ if (!$handle) {
+ $this->logger->debug('createEntropyArrayFromFile: Getting file handle failed.', array('app' => Application::APP_ID));
return [];
}
- return $this->createEntropyArrayFromData($data, $blockSize);
- }
-
- /**
- * Creates an array with the entropy of the data blocks.
- *
- * @param string $data
- * @param int $blockSize
- *
- * @return array
- */
- protected function createEntropyArrayFromData($data, $blockSize)
- {
- $entropyArray = array();
- $size = strlen($data);
-
- for ($i = 0; $i < $size / $blockSize; $i++) {
- if ($size >= $i * $blockSize + $blockSize) {
- $block = substr($data, $i * $blockSize, $blockSize);
+ while (!feof($handle)) {
+ $data = fread($handle, $blockSize);
+ if (strlen($data) === $blockSize) {
$entropyArray[$i] = $this->entropy->calculateEntropy($block);
}
}
+ fclose($handle);
return $entropyArray;
}