PageRenderTime 37ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/Utilities/anonymize-adium-debug-log.pl

https://bitbucket.org/jclyons/adium-av/
Perl | 255 lines | 163 code | 39 blank | 53 comment | 23 complexity | befca724efcea15c2d46980806e1250c MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, BSD-3-Clause
  1. #!/usr/bin/env perl
  2. #
  3. # Trivial script to anonymize Adium debug logs. It's a hack, and was
  4. # put together with little time or effort. I'm sure that it could be
  5. # made better, if someone cared enough to do so.
  6. # 29 Dec 2007: Minor updates / fixes (e.g., add libpurple into search
  7. # strings instead of libgaim).
  8. # 29 Apr 2007: This script works for all the data in the log that I
  9. # need to submit; I'm quite sure that it is *not* comprehensive. I
  10. # only anonymized AIM, Jabber, and Sametime data that I found in my
  11. # log; there is no support for the other protocols, and I'm guessing
  12. # that this script won't anonymize *all* data from AIM/Jabber/Sametime
  13. # -- just the stuff that I found in my log.
  14. use strict;
  15. # Get the filename
  16. my $filename = $ARGV[0];
  17. if (! $filename) {
  18. print "Usage: $0 <filename>\n";
  19. exit(1);
  20. }
  21. # Do the work
  22. print "Anonymizing...\n";
  23. my $temp = "ANONYMIZE_TEMP_REPLACE_SENTINEL_STRING";
  24. my $contents = read_file($filename);
  25. replace_aim_names($contents);
  26. replace_sametime_names($contents);
  27. replace_jabber_names($contents);
  28. replace_group_names($contents);
  29. replace_accounts($contents);
  30. replace_uids($contents);
  31. replace_dns($contents);
  32. replace_email($contents);
  33. write_file("$filename.anonymous", $contents);
  34. # All done
  35. exit(0);
  36. ###########################################################################
  37. sub read_file {
  38. my $filename = shift;
  39. my $contents;
  40. open (F, $filename) || die "Cannot open $filename";
  41. $contents .= $_
  42. while (<F>);
  43. close(F);
  44. \$contents;
  45. }
  46. ###########################################################################
  47. sub replace_accounts {
  48. my $contents = shift;
  49. my $account_index = 1;
  50. while ($$contents =~ m/connecting to account (.+)$/im) {
  51. my $account_name = $1;
  52. my $replace_str = "ACCOUNT_#$account_index";
  53. print "Found account: $account_name -> $replace_str\n";
  54. # Put in a sentinel string so that we don't find it again
  55. $$contents =~ s/connecting to account $account_name$/$temp $replace_str/igm;
  56. # Replace with the anonymized string everywhere else, too
  57. $$contents =~ s/$account_name/$replace_str/gm;
  58. ++$account_index;
  59. }
  60. # Put the original string back
  61. $$contents =~ s/$temp/connecting to account/gm;
  62. }
  63. ###########################################################################
  64. sub replace_uids {
  65. my $contents = shift;
  66. my $uid_index = 1;
  67. while ($$contents =~ m/created PurpleAccount 0x[0-9a-f]+ with uid (.+),/im) {
  68. my $uid = $1;
  69. if ($uid !~ /^ACCOUNT_#/) {
  70. my $replace_str = "UID_#$uid_index";
  71. print "Found UID: $uid -> $replace_str\n";
  72. # Put in a sentinel string so that we don't find it again
  73. $$contents =~ s/with uid $uid/$temp $replace_str/igm;
  74. # Replace with the anonymized string everywhere else, too
  75. $$contents =~ s/$uid/$replace_str/gm;
  76. ++$uid_index;
  77. } else {
  78. $$contents =~ s/with uid $uid/$temp $uid/igm;
  79. }
  80. }
  81. # Put the original string back
  82. $$contents =~ s/$temp/with UID/gm;
  83. }
  84. ###########################################################################
  85. sub replace_dns {
  86. my $contents = shift;
  87. my $dns_index = 1;
  88. while ($$contents =~ m/dns query for '(.+)' queued$/im) {
  89. my $ip_name = $1;
  90. my $name_replace_str = "IP_NAME_#$dns_index";
  91. my $addr_replace_str = "IP_ADDRESS_#$dns_index";
  92. print "Found DNS name: $ip_name -> $name_replace_str\n";
  93. # Is the name an IP address already?
  94. my $ip_address;
  95. if ($ip_name =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
  96. $ip_address = $ip_name;
  97. print "DNS name already resolved: $ip_address\n";
  98. }
  99. # Nope, not already resolved. Find the corresponding resolved
  100. # IP address
  101. else {
  102. 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 ||
  103. $$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) {
  104. $ip_address = $1;
  105. print "Found corresponding IP address: $ip_name -> $ip_address -> $addr_replace_str\n";
  106. }
  107. }
  108. # Put in a sentinel string so that we don't find it again
  109. $$contents =~ s/dns query for '$ip_name' queued$/$temp '$name_replace_str' queued/igm;
  110. # Replace with the anonymized strings everywhere else, too
  111. $$contents =~ s/$ip_name/$name_replace_str/gm;
  112. $$contents =~ s/$ip_address/$addr_replace_str/gm
  113. if ($ip_address);
  114. ++$dns_index;
  115. }
  116. # Put the original string back
  117. $$contents =~ s/$temp/DNS query for/gm;
  118. }
  119. ###########################################################################
  120. sub replace_email {
  121. my $contents = shift;
  122. my $email_index = 1;
  123. while ($$contents =~ m/ E-mail: (.+)$/im) {
  124. my $email = $1;
  125. my $replace_str = "EMAIL_#$email_index";
  126. print "Found Email: $email -> $replace_str\n";
  127. # Put in a sentinel string so that we don't find it again
  128. $$contents =~ s/ E-mail: $email$/ $temp $replace_str/gm;
  129. ++$email_index;
  130. }
  131. while ($$contents =~ m/ Email: (.+)$/im) {
  132. my $email = $1;
  133. my $replace_str = "EMAIL_#$email_index";
  134. print "Found Email: $email -> $replace_str\n";
  135. # Put in a sentinel string so that we don't find it again
  136. $$contents =~ s/ Email: $email$/ $temp $replace_str/gm;
  137. ++$email_index;
  138. }
  139. # Put the original string back
  140. $$contents =~ s/$temp/E-mail:/gm;
  141. }
  142. ###########################################################################
  143. sub replace_aim_names {
  144. my $contents = shift;
  145. my $aim_name_index = 1;
  146. while ($$contents =~ m/ AIM\.(\w+)/im) {
  147. my $aim_name = $1;
  148. my $replace_str = "AIM_ID_#$aim_name_index";
  149. print "Found AIM ID: $aim_name -> $replace_str\n";
  150. # Put in a sentinel string so that we don't find it again
  151. $$contents =~ s/ AIM\.$aim_name/ $temp.$replace_str/igm;
  152. # Replace with the anonymized strings everywhere else, too
  153. $$contents =~ s/(\W)$aim_name(\W)/\1$replace_str\2/igm;
  154. ++$aim_name_index;
  155. }
  156. # Put the original string back
  157. $$contents =~ s/$temp/AIM/gm;
  158. }
  159. ###########################################################################
  160. sub replace_sametime_names {
  161. my $contents = shift;
  162. my $st_index = 1;
  163. while ($$contents =~ m/ Sametime\.uid=(.+?)>/im) {
  164. my $st_name = $1;
  165. my $replace_str = "SAMETIME_ID_#$st_index";
  166. print "Found Sametime ID: $st_name -> $replace_str\n";
  167. # Put in a sentinel string so that we don't find it again
  168. $$contents =~ s/ Sametime\.uid=$st_name/ $temp$replace_str/igm;
  169. # Replace with the anonymized strings everywhere else, too
  170. $$contents =~ s/(\W)uid=$st_name(\W)/\1$replace_str\2/igm;
  171. ++$st_index;
  172. }
  173. # Put the original string back
  174. $$contents =~ s/ $temp/ Sametime.uid=/gm;
  175. }
  176. ###########################################################################
  177. sub replace_jabber_names {
  178. my $contents = shift;
  179. my $jabber_index = 1;
  180. while ($$contents =~ m/ jabber\.(.+?)>/im) {
  181. my $jabber_name = $1;
  182. my $replace_str = "JABBER_ID_#$jabber_index";
  183. print "Found Jabber ID: $jabber_name -> $replace_str\n";
  184. # Put in a sentinel string so that we don't find it again
  185. $$contents =~ s/ Jabber\.$jabber_name/ $temp$replace_str/igm;
  186. # Replace with the anonymized strings everywhere else, too
  187. $$contents =~ s/(\W)$jabber_name(\W)/\1$replace_str\2/igm;
  188. ++$jabber_index;
  189. }
  190. # Put the original string back
  191. $$contents =~ s/ $temp/ Jabber./gm;
  192. }
  193. ###########################################################################
  194. sub replace_group_names {
  195. my $contents = shift;
  196. my $group_index = 1;
  197. while ($$contents =~ m/ Group\.(.+?)>/im) {
  198. my $group_name = $1;
  199. my $replace_str = "GROUP_ID_#$group_index";
  200. print "Found Group ID: $group_name -> $replace_str\n";
  201. # Put in a sentinel string so that we don't find it again
  202. $$contents =~ s/ Group\.$group_name/ $temp$replace_str/igm;
  203. # Replace with the anonymized strings everywhere else, too
  204. $$contents =~ s/(\W)$group_name(\W)/\1$replace_str\2/igm;
  205. ++$group_index;
  206. }
  207. # Put the original string back
  208. $$contents =~ s/ $temp/ Group./gm;
  209. }
  210. ###########################################################################
  211. sub write_file {
  212. my ($filename, $contents) = @_;
  213. open (F, ">$filename") || die("Cannot open output file $filename");
  214. print F $$contents;
  215. close(F);
  216. }