Advertisement

Packet Parsing and Vectors

Started by September 20, 2005 09:39 AM
3 comments, last by hplus0603 19 years, 5 months ago
Since this involves parsing a UDP packet, I thought posting this in Network Programming was the spot. Sorry if not. I'm reading in a UDP packet. The protocol/structure of this packet is known. In order to try to make this clearer: I define a structure with all the datatypes each field in the packet. I copymemory the packet into the structure. So far so good. Type DemoField ID as DWORD Flag as DWORD Success as BYTE // Which we use as a bool End Type One member of the UDT says to mask 0x00000001 against flags, so: If (DemoField.Flag AND &H00000001) Then Now lets assume this returns true (non-zero). Now if this is true then I know there are 2 WORD values I need to retrieve. Counter as WORD Unknown as WORD CopyMemory Counter, UDPPacket(iLastPosition), (Len(DemoField) + Len(Counter)) CopyMemory Unknown, UDPPacket(iLastPosition+Len(Counter)), Len(Unknown)) Ok and here is my question (thanks for bearing with me), the value thats returned in Counter, theres two more fields. Key as DWORD Value as DWORD It says these are a 'vector of length' of Counter. How can I get two DWORD values from a WORD value? Now if a vector is like x, y, the only way I can see doing this would be HIWord/LOWord but that doesn't return a DWORD (?). Or if Counter = 0xFFAA, then cast the HI/LO to a DWORD? So, Key = 0x00FF and Value = 0x00AA? I'd appreciate any assistance. Nut
OMG that makes sense!

Thanks for the quick response :)

Advertisement
Its me again. :)

The values I get aren't what I should be getting using your vector approach.

I was googling and found something about C++ having a <vector> header file.

While I know very little of C++, was wondering if you think this include file would be the vector approach? The people that broke the protocol down assume everyone will be using C++.

The following is one of the message types to process:

/* 0xF658 - Character List */
//The list of characters on the current account.
DWORD unknown1
DWORD characterCount /*The number of characters in the list. Characters appear in the list ordered most-recently-used first, but are displayed alphabetically. */

//characters: vector of length characterCount
ObjectID character //The character ID for this entry.
String name //The name of this character.
DWORD deleteTimeout /*When 0, this character is not being deleted (not shown crossed out). Otherwise, it's a countdown timer in the number of seconds until the character is submitted for deletion. */

DWORD unknown2
DWORD slotCount //The total count of character slots.
String zonename //The zonename for this account.
DWORD ChatEnabled //Whether or not Chat is enabled.
DWORD unknown3


Any help would be appreciated. (BTW, I'm parsing this in VB)

Nut
To decode that packet, you'd use something like (pseudo-code):

read_dword -> ignore
read_dword -> count

characters = new array of character size count
for i from 1 to count
read_objectid -> characters.id
read_string -> characters.name
read_dword -> characters.deleteCount

read_dword -> ignore
read_dword -> slotCount
read_string -> zoneName
read_dword -> chatEnabled
read_dword ->


Now, I don't know how "read_objectid" or "read_string" would be implemented. Chances are, if the array doesn't look right to you, you're not implementing these functions correctly.

I would get one of these packets and dump it to disk (writing as a file), then opening it in a hex editor (HexEdit, or UltraEdit32 in hex mode, for example) and inspect the data to make sure it's what I think it is.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement