Class ByteArrayUtilities
- Namespace
- Plugin.ByteArrays
- Assembly
- Plugin.ByteArrays.dll
Utility extensions for byte array analysis, formatting, and performance measurement.
public static class ByteArrayUtilities
- Inheritance
-
ByteArrayUtilities
- Inherited Members
Methods
AppearsCompressed(byte[])
Determines if the data appears to be compressed or encrypted based on entropy.
public static bool AppearsCompressed(this byte[] array)
Parameters
arraybyte[]The byte array to analyze.
Returns
- bool
True if the data appears compressed/encrypted, false otherwise.
CalculateEntropy(byte[])
Calculates the Shannon entropy of the byte-value distribution of the byte array, in bits per byte. It counts how often each value occurs and ignores their order, so any permutation of the same bytes has the same entropy.
public static double CalculateEntropy(this byte[] array)
Parameters
arraybyte[]The byte array to analyze.
Returns
- double
A value between 0.0 (a single distinct byte value) and 8.0 (all 256 values equally frequent).
CalculateThroughput(byte[], TimeSpan)
Calculates the throughput rate for a byte array operation.
public static double CalculateThroughput(this byte[] array, TimeSpan elapsedTime)
Parameters
Returns
- double
The throughput in bytes per second.
FromBinaryString(string, string)
Converts a binary string back to a byte array.
public static byte[] FromBinaryString(string binaryString, string separator = " ")
Parameters
binaryStringstringThe binary string to convert (e.g., "10101010 11110000").
separatorstringThe separator used between bytes (default is space).
Returns
- byte[]
The byte array represented by the binary string.
GetByteFrequency(byte[])
Counts the occurrences of each byte value in the array.
public static Dictionary<byte, int> GetByteFrequency(this byte[] array)
Parameters
arraybyte[]The byte array to analyze.
Returns
- Dictionary<byte, int>
A dictionary with byte frequencies.
MeasurePerformance<T>(byte[], Func<byte[], T>, int)
Measures the execution time of an operation on the byte array.
public static (T result, TimeSpan totalTime, TimeSpan averageTime) MeasurePerformance<T>(this byte[] array, Func<byte[], T> operation, int iterations = 1)
Parameters
arraybyte[]The byte array to operate on.
operationFunc<byte[], T>The operation to measure.
iterationsintNumber of iterations to run (default 1).
Returns
- (T result, TimeSpan totalTime, TimeSpan averageTime)
A tuple with the result, total time, and average time per iteration.
Type Parameters
TThe return type of the operation.
ToBinaryString(byte[], string)
Converts the byte array to a binary string representation. Each byte is represented as 8 bits separated by spaces.
public static string ToBinaryString(this byte[] array, string separator = " ")
Parameters
arraybyte[]The byte array to convert.
separatorstringThe separator between bytes (default is space).
Returns
- string
A binary string representation of the byte array.
ToHexDump(byte[], int, bool, bool)
Creates a formatted hex dump of the byte array similar to hex editors.
public static string ToHexDump(this byte[] array, int bytesPerLine = 16, bool showAscii = true, bool showOffsets = true)
Parameters
arraybyte[]The byte array to dump.
bytesPerLineintNumber of bytes per line (default 16).
showAsciiboolWhether to show ASCII representation (default true).
showOffsetsboolWhether to show byte offsets (default true).
Returns
- string
A formatted hex dump string.