-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_leaks
executable file
·71 lines (52 loc) · 1.83 KB
/
find_leaks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/perl -w
#
# Given an swf file this will give some diagnostics
# on where our write_through program is going wrong.
#
#
use strict;
# warning this is a security risk, probably
my $file = shift || die "Must pass a file name";
# make a temp name
my $tmp = $$.time;
# perform a write through an generate the first loads of tags
my @first = `./write_through $file $tmp`;
# do the second one. We should probably error check this.
my @second = `./write_through $tmp $tmp`;
die "There was an error running the external program './write_through'" unless (@first && @second);
# get rid of the tmp file
unlink $tmp;
# the current difference
my $diff = 0;
for (my $i=0; $i<scalar @first; $i++)
{
# clean up
chomp ($first[$i]);
chomp ($second[$i]);
# don't want anything that isn't debug output
next unless $first[$i] =~ /^\[/;
# grab the info
my @a = ($first[$i] =~ /^\[(\d+)\] \((\d+)\) (.+) (\**)$/);
my @b = ($second[$i] =~ /^\[(\d+)\] \((\d+)\) (.+) (\**)$/);
# work out where the tags were in the file and what the difference
# is between them.
my $tdiff = $a[1] - $b[1];
# normalise
$tdiff *= -1 if ($tdiff < 0);
# if it's different to the last difference
# (if you get what I mean) then the tag before
# must have been longer (I think, it could be
# this one)
if ($tdiff > $diff) {
my @c = ($first[$i-1] =~ /^\[(\d+)\] \((\d+)\) (.+) (\**)$/);
my @d = ($second[$i-1] =~ /^\[(\d+)\] \((\d+)\) (.+) (\**)$/);
print "$c[2] changed by ".($tdiff-$diff)." bytes in frame $c[0]";
print " (longtag)" if (defined $c [3] && $c[3] eq '*');
print ".\n";
print "Original tag started at ".$c[1]." and the next tag starts at ".$a[1]." size=".($a[1]-$c[1])."\n";
print "The new tag started at ".$d[1]." and the next tag starts at ".$b[1]." size=".($b[1]-$d[1])."\n";
print "\n";
$diff = $tdiff;
}
}
exit 0;