Ethereal-dev: AW: [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: "Helge Kruse" <HelgeKruse@xxxxxxxxxxx>
Date: Wed, 11 May 2005 05:40:04 +0200
Some ideas

Dont use strlen to get the buffer size, even if your for sure, that the
buffer has exact a zero terminated string. Use tvb_length instead.

Your target buffer should have the definition:
    char new_buffer[new_buffer_size];

You need a read and write index. If you found your sequence, add 3 to the
read pointer, 1 to the write pointer. The for head will add one additional
offset to the indices.

Helge


-----Ursprüngliche Nachricht-----
Von: ethereal-dev-bounces@xxxxxxxxxxxx
[mailto:ethereal-dev-bounces@xxxxxxxxxxxx] Im Auftrag von Oren Mazor
Gesendet: Dienstag, 10. Mai 2005 15:55
An: Ethereal development
Betreff: [Ethereal-dev] escape sequences in tvbuff

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;
}

_______________________________________________
Ethereal-dev mailing list
Ethereal-dev@xxxxxxxxxxxx
http://www.ethereal.com/mailman/listinfo/ethereal-dev