William Bowling is sharing code with you
Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.
Don't show this again1 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | #!/usr/bin/env perl
#
# Trivial script to anonymize Adium debug logs. It's a hack, and was
# put together with little time or effort. I'm sure that it could be
# made better, if someone cared enough to do so.
# 29 Dec 2007: Minor updates / fixes (e.g., add libpurple into search
# strings instead of libgaim).
# 29 Apr 2007: This script works for all the data in the log that I
# need to submit; I'm quite sure that it is *not* comprehensive. I
# only anonymized AIM, Jabber, and Sametime data that I found in my
# log; there is no support for the other protocols, and I'm guessing
# that this script won't anonymize *all* data from AIM/Jabber/Sametime
# -- just the stuff that I found in my log.
use strict;
# Get the filename
my $filename = $ARGV[0];
if (! $filename) {
print "Usage: $0 <filename>\n";
exit(1);
}
# Do the work
print "Anonymizing...\n";
my $temp = "ANONYMIZE_TEMP_REPLACE_SENTINEL_STRING";
my $contents = read_file($filename);
replace_aim_names($contents);
replace_sametime_names($contents);
replace_jabber_names($contents);
replace_group_names($contents);
replace_accounts($contents);
replace_uids($contents);
replace_dns($contents);
replace_email($contents);
write_file("$filename.anonymous", $contents);
# All done
exit(0);
###########################################################################
sub read_file {
my $filename = shift;
my $contents;
open (F, $filename) || die "Cannot open $filename";
$contents .= $_
while (<F>);
close(F);
\$contents;
}
###########################################################################
sub replace_accounts {
my $contents = shift;
my $account_index = 1;
while ($$contents =~ m/connecting to account (.+)$/im) {
my $account_name = $1;
my $replace_str = "ACCOUNT_#$account_index";
print "Found account: $account_name -> $replace_str\n";
# Put in a sentinel string so that we don't find it again
$$contents =~ s/connecting to account $account_name$/$temp $replace_str/igm;
# Replace with the anonymized string everywhere else, too
$$contents =~ s/$account_name/$replace_str/gm;
++$account_index;
}
# Put the original string back
$$contents =~ s/$temp/connecting to account/gm;
}
###########################################################################
sub replace_uids {
my $contents = shift;
my $uid_index = 1;
while ($$contents =~ m/created PurpleAccount 0x[0-9a-f]+ with uid (.+),/im) {
my $uid = $1;
if ($uid !~ /^ACCOUNT_#/) {
my $replace_str = "UID_#$uid_index";
print "Found UID: $uid -> $replace_str\n";
# Put in a sentinel string so that we don't find it again
$$contents =~ s/with uid $uid/$temp $replace_str/igm;
# Replace with the anonymized string everywhere else, too
$$contents =~ s/$uid/$replace_str/gm;
++$uid_index;
} else {
$$contents =~ s/with uid $uid/$temp $uid/igm;
}
}
# Put the original string back
$$contents =~ s/$temp/with UID/gm;
}
###########################################################################
sub replace_dns {
my $contents = shift;
my $dns_index = 1;
while ($$contents =~ m/dns query for '(.+)' queued$/im) {
my $ip_name = $1;
my $name_replace_str = "IP_NAME_#$dns_index";
my $addr_replace_str = "IP_ADDRESS_#$dns_index";
print "Found DNS name: $ip_name -> $name_replace_str\n";
# Is the name an IP address already?
my $ip_address;
if ($ip_name =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
$ip_address = $ip_name;
print "DNS name already resolved: $ip_address\n";
}
# Nope, not already resolved. Find the corresponding resolved
# IP address
else {
if ($$contents =~ m/ip resolved for $ip_name\n\d\d:\d\d:\d\d: \(libpurple: proxy\) attempting connection to (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/i ||
$$contents =~ m/ip resolved for $ip_name\n\d\d:\d\d:\d\d: \(lbigaim: proxy\) attempting connection to (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/i) {
$ip_address = $1;
print "Found corresponding IP address: $ip_name -> $ip_address -> $addr_replace_str\n";
}
}
# Put in a sentinel string so that we don't find it again
$$contents =~ s/dns query for '$ip_name' queued$/$temp '$name_replace_str' queued/igm;
# Replace with the anonymized strings everywhere else, too
$$contents =~ s/$ip_name/$name_replace_str/gm;
$$contents =~ s/$ip_address/$addr_replace_str/gm
if ($ip_address);
++$dns_index;
}
# Put the original string back
$$contents =~ s/$temp/DNS query for/gm;
}
###########################################################################
sub replace_email {
my $contents = shift;
my $email_index = 1;
while ($$contents =~ m/ E-mail: (.+)$/im) {
my $email = $1;
my $replace_str = "EMAIL_#$email_index";
print "Found Email: $email -> $replace_str\n";
# Put in a sentinel string so that we don't find it again
$$contents =~ s/ E-mail: $email$/ $temp $replace_str/gm;
++$email_index;
}
while ($$contents =~ m/ Email: (.+)$/im) {
my $email = $1;
my $replace_str = "EMAIL_#$email_index";
print "Found Email: $email -> $replace_str\n";
# Put in a sentinel string so that we don't find it again
$$contents =~ s/ Email: $email$/ $temp $replace_str/gm;
++$email_index;
}
# Put the original string back
$$contents =~ s/$temp/E-mail:/gm;
}
###########################################################################
sub replace_aim_names {
my $contents = shift;
my $aim_name_index = 1;
while ($$contents =~ m/ AIM\.(\w+)/im) {
my $aim_name = $1;
my $replace_str = "AIM_ID_#$aim_name_index";
print "Found AIM ID: $aim_name -> $replace_str\n";
# Put in a sentinel string so that we don't find it again
$$contents =~ s/ AIM\.$aim_name/ $temp.$replace_str/igm;
# Replace with the anonymized strings everywhere else, too
$$contents =~ s/(\W)$aim_name(\W)/\1$replace_str\2/igm;
++$aim_name_index;
}
# Put the original string back
$$contents =~ s/$temp/AIM/gm;
}
###########################################################################
sub replace_sametime_names {
my $contents = shift;
my $st_index = 1;
while ($$contents =~ m/ Sametime\.uid=(.+?)>/im) {
my $st_name = $1;
my $replace_str = "SAMETIME_ID_#$st_index";
print "Found Sametime ID: $st_name -> $replace_str\n";
# Put in a sentinel string so that we don't find it again
$$contents =~ s/ Sametime\.uid=$st_name/ $temp$replace_str/igm;
# Replace with the anonymized strings everywhere else, too
$$contents =~ s/(\W)uid=$st_name(\W)/\1$replace_str\2/igm;
++$st_index;
}
# Put the original string back
$$contents =~ s/ $temp/ Sametime.uid=/gm;
}
###########################################################################
sub replace_jabber_names {
my $contents = shift;
my $jabber_index = 1;
while ($$contents =~ m/ jabber\.(.+?)>/im) {
my $jabber_name = $1;
my $replace_str = "JABBER_ID_#$jabber_index";
print "Found Jabber ID: $jabber_name -> $replace_str\n";
# Put in a sentinel string so that we don't find it again
$$contents =~ s/ Jabber\.$jabber_name/ $temp$replace_str/igm;
# Replace with the anonymized strings everywhere else, too
$$contents =~ s/(\W)$jabber_name(\W)/\1$replace_str\2/igm;
++$jabber_index;
}
# Put the original string back
$$contents =~ s/ $temp/ Jabber./gm;
}
###########################################################################
sub replace_group_names {
my $contents = shift;
my $group_index = 1;
while ($$contents =~ m/ Group\.(.+?)>/im) {
my $group_name = $1;
my $replace_str = "GROUP_ID_#$group_index";
print "Found Group ID: $group_name -> $replace_str\n";
# Put in a sentinel string so that we don't find it again
$$contents =~ s/ Group\.$group_name/ $temp$replace_str/igm;
# Replace with the anonymized strings everywhere else, too
$$contents =~ s/(\W)$group_name(\W)/\1$replace_str\2/igm;
++$group_index;
}
# Put the original string back
$$contents =~ s/ $temp/ Group./gm;
}
###########################################################################
sub write_file {
my ($filename, $contents) = @_;
open (F, ">$filename") || die("Cannot open output file $filename");
print F $$contents;
close(F);
}
|