#!/usr/bin/perl # plistparse - parse plist file, searching for strings and printing results # Copyright 2009 Lou Arminio (lou arminio gmail com) # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . use Getopt::Long; use Pod::Usage; use PlistParse; # Option variables my $plist_in; my $regex; my $rexfile; my $help = 0; my @regex; my $tags = 0; # Globals my $indent = 0; my $XML; Getopt::Long::Configure ('no_ignore_case'); GetOptions ("read|r=s" => \$plist_in, "regex|x=s" => \@regex, "rexfile|X=s" => \$rexfile, "tags|t" => \$tags, "help|h" => \$help) or shorthelp(2); if ($help) { pod2usage(-verbose => 2); } # Check inputs if (! $plist_in) { shorthelp(1); } if (! -r $plist_in) { print "File does not exist: $plist_in\n"; exit 1; } if (-r $rexfile) { open (REX, "<$rexfile") or die "Can't open regular expression file $rexfile: $!\n"; while () { chomp; push (@regex, $_); } close (REX); } if (! @regex) { @regex = ("."); $tags = 1; } open ($XML, "<$plist_in") or die "can't open $plist_in: $!\n"; my ($plistparse) = new PlistParse; $plistparse->YYData->{XML} = $XML; $plistparse->YYData->{REX} = \@regex; $plistparse->YYData->{TAGS} = $tags; $plistparse->Run; sub shorthelp { my ($exit) = @_; print "Usage: $0 --read|-r \n"; print " Prints plist file in readable form\n"; print " $0 --read|-r --regexp|-x \n"; print " [--tags|-t]\n"; print " Multiple -x options allowed\n"; print " $0 --read|-r --rexfile|-X \n"; print " [--tags|-t]\n"; print " -X can be used with -x\n"; print " $0 --help|-h\n"; exit($exit); } 0; __END__ =pod =head1 NAME B - make PLIST XML files easier to read =head1 SYNOPSIS B -r|--read PLISTFILE B -r|--read PLISTFILE [-x|--regexp REGULAR_EXPRESSION]... [-X|--rexfile REGULAR_EXPRESSION_FILE] [-t|--tags] B -h|--help =head1 OPTIONS =over 8 =item B<-r|--read PLISTFILE> Specify the name of the PLIST file. The file must be in XML. =item B<-x|--regexp REGULAR_EXPRESSION> Introduces a PERL regular expression. All PLIST and PCDATA values that match the expression will be printed. If a key is matched, it's associated data element is also displayed. Multiple B options may be specified in which case lines matching any of provided patterns will be printed. This option may be used together with the B option described below. =item B<-X|--rexfile REGULAR_EXPRESSION_FILE> Introduces a file which can contain multiple regular expressions. This option can be used together with the B option so regular expressions can come both from the command line and a file. =item B<-t|--tags> Normally, when B or B options are specified, the printing of indentation and tags not part of matched values are not printed. The B option displays the normal indentation and full simplified tags contained in the PLIST file, while only showing values that matched regular expressions. =item B<-h|--help> The -h and --help options print this help menu. The calling B with no options will print a quick usage summary. =back =head1 DESCRIPTION B reads an Apple PLIST XML format file and strips and simplifies the XML tags, making the file easier to read. The original PLIST file will all tags prior to the tag stripped. All other tags associated with PLIST files will be stripped and replace by simple labels and indentation. The resulting output should be much simpler for humans to read. Several options to plistparse allow the file to be searched for patterns. The script will accept PERL style regular expressions both directly from the command line and read in from a file containing PERL regular expressions. plistparse relies on the B module, which is a state machine that understands the PLIST XML grammer. PlistParse.pm was built using the B module, available through CPAN. Modules built with Parse::Yapp are copyright Francois Desarmenien. The copyright notice from the PERL documentation on Parse::Yapp is as follows. B The Parse::Yapp module and its related modules and shell scripts are copyright (c) 1998-2001 Francois Desarmenien, France. All rights reserved. You may use and distribute them under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file. =cut