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:
authorMatthias <ilovemilk@wusa.io>2018-12-09 18:47:44 +0300
committerMatthias <ilovemilk@wusa.io>2018-12-09 18:47:44 +0300
commit2da65dd1856d882f34212196112157157630d3c7 (patch)
tree7550e88666438fb475d22112f9d22a7e9ec26b44 /lib
parent6c771bd6fc8f18bfeb26eb90aab3d41550cbbc88 (diff)
Fix blockwise entropy calculation
Diffstat (limited to 'lib')
-rw-r--r--lib/Analyzer/EntropyAnalyzer.php12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/Analyzer/EntropyAnalyzer.php b/lib/Analyzer/EntropyAnalyzer.php
index d3c7fdb..744ffe9 100644
--- a/lib/Analyzer/EntropyAnalyzer.php
+++ b/lib/Analyzer/EntropyAnalyzer.php
@@ -138,7 +138,7 @@ class EntropyAnalyzer
while (!feof($handle)) {
$data = fread($handle, $blockSize);
if (strlen($data) === $blockSize) {
- $entropyArray[$i] = $this->entropy->calculateEntropy($block);
+ array_push($entropyArray, $this->entropy->calculateEntropy($data));
}
}
fclose($handle);
@@ -176,16 +176,22 @@ class EntropyAnalyzer
return 0.0;
}
+ $entropy = 0.0;
+ $total = 0;
+
while (!feof($handle)) {
$data = fread($handle, 1024);
+ $total = $total + 1;
if (strlen($data) === 1024) {
- $entropy = $entropy + $this->entropy->calculateEntropy($block);
+ $entropy = $entropy + $this->entropy->calculateEntropy($data);
}
}
fclose($handle);
+ $entropy = $entropy / $total;
+
if ($entropy >= 0) {
- return $entopry;
+ return $entropy;
} else {
return -$entropy;
}