AbstractBeliefs

Untitled

Nov 28th, 2012
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.39 KB | None | 0 0
  1. sub pkt_escape {
  2.     my $pkt = shift;
  3.     my $esc = pack('C', 0x10);
  4.     my $buf;
  5.  
  6.     for (my $i = 0; $i < length $pkt; $i++) {
  7.         my $byte = unpack("x[$i]C", $pkt);
  8.  
  9.         if ($i > 4 && $i < length($pkt) - 4 && ($byte == 0x10 || $byte == 0x01 || $byte == 0x04 || $byte == 0x17)) {
  10.             $buf .= $esc;
  11.         }
  12.  
  13.         $buf .= pack('C', $byte);
  14.     }
  15.  
  16.     return $buf;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment