Ethereal-dev: [Ethereal-dev] escape sequences in tvbuff

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

From: "Oren Mazor" <oren.mazor@xxxxxxxxx>
Date: Tue, 10 May 2005 09:55:20 -0400
hi all,

I'm attempting to go through a tvbuff and replace a certain pattern with another (FF55 to FF). Unfortunately, it seems that something is wrong with my attempts to create the new tvbuff (since I cant change the original..)

Could somebody take a look at the last few lines of the following code (I provided the entire function for context) and let me know where I'm going wrong creating the new tvbuff?

thanks,
Oren Mazor

-------------------

static tvbuff_t *
cleanUpEscapeSequence(tvbuff_t *tvb, packet_info *pinfo)
{
	//the original bytes
	char* orig_buffer = tvb_memdup(tvb, 0, tvb_length(tvb));
	//the size of above buffer
	int buffer_size = strlen(orig_buffer);
	//the size of our new buffer (initially the same as original buffer)
	int new_buffer_size = buffer_size;
	//buffer to hold the resulting bytes
	char* new_buffer[buffer_size];
	int i;
	for(i=0;i<buffer_size-4;i++)
	{
		//test the next four bytes for the required pattern
		if(orig_buffer[i] == 'F' && orig_buffer[i+1] == 'F'
				&&orig_buffer[i+2] == '5' && orig_buffer[i+3]=='5')
		{
			*new_buffer[i] = 'F';
			*new_buffer[i+1] = 'F';
			i+=4;//skip the rest, as we dont need the next two bytes ('55')
			new_buffer_size-=2;//need to know the size of the resulting buffer
		}
		else
			*new_buffer[i] = orig_buffer[i];
	}
	
	if(new_buffer_size != buffer_size)
	{//we've had a change, if the two buffer size dont match
		//create the new tvb
tvbuff_t *next_tvb = tvb_new_real_data(*new_buffer, new_buffer_size, new_buffer_size);
		tvb_set_child_real_data_tvbuff(tvb, next_tvb);
	 	add_new_data_source(pinfo, next_tvb, "Check");
		return next_tvb;
	}
	else
		return tvb;
}