.NET Data Files
A data file is a generic representation of data, typically data that represents memory of an embedded device. The data files library provides methods for loading and storing
the generic data in different file formats. The library is provided with full source code
within the .NET Software Download.
DZX.DataFiles.dll Library
Data file support is provided by the DZX.DataFiles.dll library. The library contains the DataFile class provides methods for loading, storing and
manipulating data files in various storage formats. The DataFile class keeps its data arranged
within addressable sections. The sections provide a method of describing data at different addresses.
Supported Formats
The library supports loading and storing data files in the following formats:
- Raw Binary (.bin)
- Motorola S-Record (.srec)
- Intel Hex (.hex)
Loading and Storing
The library contains methods for reading and writing data files. By default, the library will use the file extension to determine the format of the
specified file. For example, the snippet below shows how to convert an Intel hex file into a binary file.
using DZX.DataFiles;
// Read and load a data file
DataFile file = DataFile.FromFile("C:\\DZX\\some-file.hex");
// Save the file in binary (specify a different extension)
file.Save("C:\\DZX\\some-file.bin");
Alternatively, a specific format can be specified when loading or storing files. The code snippet below shows the same operation as above, but
with the file formats explicitly specified.
using DZX.DataFiles;
// Read and load a data file
DataFile file = DataFile.FromFile(DataFileFormat.Hex, "C:\\DZX\\some-file.hex");
// Save the file in binary (specify a different extension)
file.Save(DataFileFormat.Binary, "C:\\DZX\\some-file.bin");
AES Encryption
The library also provides support for encrypting and decrypting the data within a data file. The encryption methods match those that are provided
within our device bootloaders to enable deployment of secure device updates.
The snippet below shows how to encrypt a data file using AES-128 with a key generated from a pass phrase. The file is then decrypted back to
it's original data values.
using DZX.DataFiles;
// Read and load the data file
DataFile file = DataFile.FromFile("C:\\DZX\\some-file.bin");
// Encrypt the contents using AES-128
file.Encrypt(128, "password");
// Store the data back to file
file.Save("C:\\DZX\\some-file-encrypted.bin");
// Decrypt the contents back to their original values
file.Decrypt(128, "password");
// Store the data back to another file
file.Save("C:\\DZX\\some-file-decrypted.bin");