I am intercepting some packets, and then put them into an structure.
#pragma pack(push, 1)
struct PacketHeader {
short Size;
short Checksum;
short Index;
};
#pragma pack(pop)
I have a packet with PacketHeader and some other bytes that fill this structure:
struct STRUCT_SVC_ROOM_CREATE {
PacketHeader Header;
unsigned char TitleLength; // 1 byte
char* RoomTitle[23];
short Unknow;
short Unknow2;
short Password1;
short Password2;
char LastByte;
};
In the above struct, TitleLength is one byte, that in decimal can 0x17 (23) or any number. This number the numbers of chars contained in RoomTitle.
I need to set size of RoomTitle accortng to TitleLenght byte (as decimal number).
How could I modify the struct to handle the text size in the right location inside the struct?
char* RoomTitle[23]It seems extremely unlikely that you will receive, over the network, 23 pointers that are valid in your process' address space. Did you meanchar RoomTitle[23]?structthat would magically fit a message of any size. You can define structs for fixed-size parts of the message - for example, you can definePacketFooterfor fieldsUnknownthroughLastByte. But you need to determine programmatically at what offset in the messagePacketFooterbegins.HeaderthroughRoomTitle, and another forUnknownthroughLastByte. That second structure is at a variable offset - namely,offsetof(FirstStructure, RoomTitle) + firstStructure->TitleLength.