-
Notifications
You must be signed in to change notification settings - Fork 9
/
capture-strings.pl
executable file
·64 lines (53 loc) · 1.54 KB
/
capture-strings.pl
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
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long;
# Dump string literals from source and AndroidMainifest.xml
#
# Parameters:
#
# 1) outfile: File to output
#
# 2) dirs: Directories to search for string literals
my @dirs_default = qw/src AndroidManifest.xml/;
my @dirs = ();
my $outfile = "./sparta-out/sparta_strings.txt";
GetOptions('dirs:s' => \@dirs, 'outfile:s' => \$outfile);
if ($#dirs < 0) {
@dirs = @dirs_default;
}
# Grep for double quotes in given directories (or files).
my $dirs_str = join(' ', @dirs);
my @lines = `egrep -R '\"[^"]+\"' $dirs_str`;
my %out = ();
# Break out multiple literals on the same line
for my $line (@lines) {
while ($line =~ /"([^"]+)"/g) {
my $match = $1;
# Strip ends of whitespace
$match =~ s/^\s+//;
$match =~ s/\s+$//;
# Make unique and don't include lines with whitespace only
$out{$match} = $match if $match =~ '[^ ]+';
}
}
@lines = `egrep -R '[^/]>[^<]+<' $dirs_str`;
# Break out multiple literals on the same line
for my $line (@lines) {
while ($line =~ /[^\/]>([^<]+)</g) {
my $match = $1;
# Strip ends of whitespace
$match =~ s/^\s+//;
$match =~ s/\s+$//;
# Make unique and don't include lines with whitespace only
$out{$match} = $match if $match =~ '[^ ]+';
}
}
my @lines_uniq = keys %out;
@lines_uniq = sort (@lines_uniq);
# print join("\n", @lines_uniq);
open (my $FH , ">", $outfile) or die "cannot open $outfile: $!";
for my $line (@lines_uniq) {
print $FH "$line\n";
}
close($FH)