parsing of variable lenght packets with sub elements

Wrote new code? Fixed a bug? Want to discuss technical stuff? Feel free to post it here.

Moderator: Moderators

Message
Author
Technology
Super Moderators
Super Moderators
Posts: 801
Joined: 06 May 2008, 12:47
Noob?: No

Re: parsing of variable lenght packets with sub elements

#21 Post by Technology »

kLabMouse wrote:Some packet's can have a structure:

Code: Select all

short param_1
short param_2
struct {
  something
} array[(packet_len-2-4-2)/struct_size]
short param_3
You see the "array" ??? Well, number of elements is calculated from packet len, and there is additional param_3 at the end of packet.
So it need to be parsed good.
This is not ansi C, is it?
Either way, no such packet exists right?
One ST0 to rule them all? One PE viewer to find them!
One ST_kRO to bring them all and in the darkness bind them...

Mount Doom awaits us, fellowship of OpenKore!

Technology
Super Moderators
Super Moderators
Posts: 801
Joined: 06 May 2008, 12:47
Noob?: No

Re: parsing of variable lenght packets with sub elements

#22 Post by Technology »

Pure perl C struct based RO packet pack/unpack are fact, cuz edited it on wiki! ;)

Be warned, this project is still in its baby shoes. We create the objects manually.
However, it qualifies as a proof of concept no?

So...
The next part of the story is that we create a C struct parser that will create these objects for us.
If needed along the way, we can learn this newborn new stuff so it can grow up to kick ass and take names.

ps: kid can be found in tape archive GNU zip compressed state on the sidebar below

disclaimer: I'm not responsible in any way if this so happens to put your keyboard on fire, causes pregnancy or any other unwanted events...

So, see you next time for another exciting episode of...
Attachments
RO_struct.tar.gz
(2.31 KiB) Downloaded 242 times
One ST0 to rule them all? One PE viewer to find them!
One ST_kRO to bring them all and in the darkness bind them...

Mount Doom awaits us, fellowship of OpenKore!

User avatar
kLabMouse
Administrator
Administrator
Posts: 1301
Joined: 24 Apr 2008, 12:02

Re: parsing of variable lenght packets with sub elements

#23 Post by kLabMouse »

Technology wrote:Pure perl C struct based RO packet pack/unpack are fact, cuz edited it on wiki! ;)

Be warned, this project is still in its baby shoes. We create the objects manually.
However, it qualifies as a proof of concept no?

So, see you next time for another exciting episode of...
Nice. Very Nice.
I need to upload some new stuff to the Packets topic. :D

Technology
Super Moderators
Super Moderators
Posts: 801
Joined: 06 May 2008, 12:47
Noob?: No

Re: parsing of variable lenght packets with sub elements

#24 Post by Technology »

The current implementation supports most of the recovered packets.

Exceptions being:
1) type array[x][x] (ex. struct PACKET_ZC_WARPLIST)
2) structs that have nested struct(s) that are not at the end (ex. struct EQUIPSLOTINFO)
3) structs that have multiple nested structs (nested on the same level) (ex. i haven't found an example of this but its possible)
- ... (add to the list)

We can solve these problem by implementing a:
1) struct::array (basically this is struct::nestedarray(count|slurp) without the SUPER::(un)pack_)
in such object we put a "nested" struct::* object that we treat as in struct::nestedarray(count|slurp)

2&3) struct::chain (un)pack class
in such object we can put a list of struct::* objects that we sequentially call method (un)pack_ on.

I'll need help on following:
- TODO: conversion of kLab's C structs to (compilable) ANSI-C.
- DONE: recording of the packet below, so we can put the (un)packer to the test.

Code: Select all

// packet 0x11c
struct PACKET_ZC_WARPLIST {
  /* this+0x0 */ short PacketType
  /* this+0x2 */ unsigned short SKID
  /* this+0x4 */ char mapName[4][16]
}
(or i can just pack my own packet i guess...)
- TODO: test if we really are able to unpack all RO packets

The actual implementation might even change along the way, we'll see.
I didn't have any time today and probably will not have any, but i'll try to work on it tomorrow.
Also, i had an old C struct to perl unpack string test lying around from a while ago but its still very basic and it needs to be worked on.

Suggestions, criticism and questions are always welcome btw.
So for now my thread goes to sleep, i'm hoping for other threads to awake now :P

UPDATE:
uploaded the first incarnation of the unpacker that implements the solution to the above problems and is thus capable of handling all(?) known RO packets,
in test.pl i marked the design flaws marked by (# FLAW:) and on the bottom of the file you will find the idea's for iteration 2 in the development cycle of the project.
RO_struct_1.tar.gz
(5.23 KiB) Downloaded 238 times
Also added the the (really) old experiment to do C struct to perl unpack string, idk if it has any use.
kore pack.tar.gz
(2.46 KiB) Downloaded 239 times
Experimental:
- changed the way we name and create the objects to make it easier to understand and more dynamical
The external is done: this will probably be the final way of creating the (un)pack objects, so now we can start working on the C struct to (un)pack object parser.
- temporarily(?) merged all array or struct related classes in their respective class until we find the best way to split them back up and let the main array & struct class delegate to other classes without causing overhead.
- $self->{(un)pack} was an experiment, it may change together with the splitting up of the classes (if we decide to)
The internal may still change.
RO_struct_1_1.tar.gz
(4.67 KiB) Downloaded 243 times
- Fixed multidimensional array unpacking
- Added chain struct with 2 array's test (Harvest)
- Fixed chain struct for (see comments: self unpack, no name)
RO_struct_1_2.tar.gz
(4.86 KiB) Downloaded 244 times
One ST0 to rule them all? One PE viewer to find them!
One ST_kRO to bring them all and in the darkness bind them...

Mount Doom awaits us, fellowship of OpenKore!

Post Reply