You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import os
import math
from collections import Counter
def file_is_empty(filepath):
try:
with open(filepath, 'rb') as file:
data = file.read(1024) # Read the first 1024 bytes
if not data:
return True # File is empty or has no readable content
if data.count(data[:1]) == len(data):
return True # All bytes in the sample are the same
except IOError as e:
print(f"Error reading {filepath}: {e}")
return False
def calculate_entropy(filepath):
try:
with open(filepath, 'rb') as file:
data = file.read()
if not data:
return 0
entropy = 0
for x in Counter(data).values():
p_x = x / len(data)
entropy -= p_x * math.log2(p_x)
return entropy
except IOError as e:
print(f"Error reading {filepath}: {e}")
return None
# Example usage
path = '/path/to/suspected/file'
print("Empty:", file_is_empty(path))
print("Entropy:", calculate_entropy(path))
Sometimes sensors produce allocated space but otherwise empty files. We should add a detector for those.
This problem seems to be distinct from OE004.
corrupt_to_investigate.zip
The text was updated successfully, but these errors were encountered: