Table of Contents

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

array byte[]

The byte array to analyze.

Returns

bool

True if the data appears compressed/encrypted, false otherwise.

CalculateEntropy(byte[])

Calculates the entropy of the byte array (0-8, where 8 is maximum entropy).

public static double CalculateEntropy(this byte[] array)

Parameters

array byte[]

The byte array to analyze.

Returns

double

The entropy value.

CalculateThroughput(byte[], TimeSpan)

Calculates the throughput rate for a byte array operation.

public static double CalculateThroughput(this byte[] array, TimeSpan elapsedTime)

Parameters

array byte[]

The byte array.

elapsedTime TimeSpan

The time taken to process the array.

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

binaryString string

The binary string to convert (e.g., "10101010 11110000").

separator string

The 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

array byte[]

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

array byte[]

The byte array to operate on.

operation Func<byte[], T>

The operation to measure.

iterations int

Number 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

T

The 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

array byte[]

The byte array to convert.

separator string

The 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

array byte[]

The byte array to dump.

bytesPerLine int

Number of bytes per line (default 16).

showAscii bool

Whether to show ASCII representation (default true).

showOffsets bool

Whether to show byte offsets (default true).

Returns

string

A formatted hex dump string.