## read a string until a '\x00' is encountered (-> null termination of strings in C!) sub read_complete_string { my ($self) = @_; my $string = ""; ## return empty string if we're already at the end of the buffer if($self->index() >= $self->size()) { return $string; } my $end_of_string = index($self->buffer(), "\x00", $self->index()); if(!($end_of_string)) { ## just read the rest of the buffer if there is no termination $string = $self->read_buffer($self->size() - $self->index()); } else { $string = $self->read_buffer($end_of_string - $self->index()); ## ignore the nullbyte '\x00' $self->skip(1); } return $string; }