Ethereal-dev: Re: [Ethereal-dev] Create a new tvbuf when decrypting?

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Gilbert Ramirez <gram@xxxxxxxxxx>
Date: Mon, 13 Nov 2000 15:35:26 -0500
On Mon, Nov 13, 2000 at 12:21:03PM -0800, Mark Atwood wrote:
> 
> The protocol I am dissecting can be encrypted. I can get the keys and
> decrypt the packets just fine. My problem is that I've passive tvbuf's
> down into my subroutins to decode the various payloads and
> subpayloads.
> 
> What I would *like* to do would be to decrypt the packet, create a new
> tvbuf with the plaintext, and then continue on with that tvbuf as if
> it had never been encrypted.
> 
> How do I create a new tvbuf, with "new" data in it, and what are 
> the issues with automaticially freeing it, etc?
> 
> 

If you decrypt the packet into an array of bytes, you can create
a new TVBUFF_REAL_DATA from it. You can then pass that new tvbuff to
subsequent dissectors and they'll have no problem with it.

The automatic free on the original tvbuff, of course, won't free
your new tvbuff, as you rightly guessed, since as far as the tvbuff
routines are concerned, they are not connected.

What you need is a way for any arbitrary tvbuff to have a "child"
TVBUFF_REAL_DATA. The child is freed when the parent is freed. Automatic
descruction of the object would then take place. This ability does not
yet exist in the tvbuff routines, but I could add it if it sounds
useful.

You'd also need to set a callback for the freeing of your new
TVBUFF_REAL_DATA. You would use tvb_set_free_cb() to register some
function that frees your array of bytes representing the decrypted
data... that way, when your new tvbuff is automatically freed, your
decrypted data is freed, too.

Let me know if that will work for you, and if so, I'll add the
ability to chain TVBUFF_REAL_DATA's under other tvbuffs. I'm pretty
sure that that's the only tvbuff type that needs special chaining,
since TVBUFF_SUBSET and TVBUFF_COMPOSITE are already based on
the idea of chaining tvbuffs together.

--gilbert