Simple byte reader distributed as an assembly. ByteReaderCLI shows an example usage.
Several functions are available, namely:
Prints bytes in HEX up to amount (if within zero and file length) or file length, whichever comes first.
string filename = @"C:\Windows\System32\notepad.exe"
ByteReader.ByteReader.PrintBytes(filename, 10);
// Output: 4D 5A 90 00 03 00 00 00 04 00
Return true if the signature provided appears exactly at the beginning of the file; false otherwise.
string filename = @"C:\Windows\System32\notepad.exe"
string signature = "4D 5A" // Signature of an exe
if (ByteReader.ByteReader.CheckFileSignature(filename, signature))
Console.WriteLine($"Signature {signature} was found");
// Output: Signature 4D 5A was found
Parse a byte[]
to a string separating the elements with the specified string.
string filename = @"C:\Windows\System32\notepad.exe"
byte[] ba = ByteReader.ByteReader.GetHexFromFile(filename);
Console.WriteLine(ByteReader.ByteReader.ByteArrayToString(ba, "-"));
// Output: 4D-5A-90-00-03-00-00-00-04-00-...
Convert a string into a byte[]
.
string byteString = "4D 5A 90 00 03 00 00 00 04 00";
byte[] ba = ByteReader.ByteReader.StringToByteArray(byteString);
Write a byte[]
to a file of a given name.
string filename = "test.txt";
string byteString = "4D 5A 90 00 03 00 00 00 04 00";
ByteReader.ByteReader.ByteArrayToFile(filename, ByteReader.ByteReader.StringToByteArray(byteString));
ByteReader.ByteReader.PrintBytes(filename);
// Output: 4D 5A 90 00 03 00 00 00 04 00
Return an array containing the bytes of the file.
string filename = @"C:\Windows\System32\notepad.exe"
byte[] ba = ByteReader.ByteReader.GetHexFromFile(filename);