I have this hexadecimal data:
byte[] data = new Byte[] {
0xC1, 0x3A, 0x00, 0x01, 0x5D, 0xDA, 0x47, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xF0, 0xFC, 0x12, 0x00, 0x00, 0x00
};
I have C++ struct:
struct SERVICE
{
unsigned char c;
unsigned char size;
unsigned char headcode;
unsigned char Type;
unsigned short Port;
char ServiceName[50];
unsigned short ServiceCode;
};
My question is: How to get from data ServiceName, Port and etc…?
Sorry for my bad english
Here is one way to do it:
This assumes, that the binary array uses the same Endianess as your architecture. If that is not the case you can use the EndianBinaryReader from the MiscUtil library.
Edit: this is also a nice solution, that avoids the reader altogether. You can’t directly specify the encoding to use for the string however and the memory layout of the structure has to match the layout used in the byte array.