Skip to content

Instantly share code, notes, and snippets.

@virifi
Created July 19, 2012 09:08
Show Gist options
  • Select an option

  • Save virifi/3142325 to your computer and use it in GitHub Desktop.

Select an option

Save virifi/3142325 to your computer and use it in GitHub Desktop.
Android上の指定したディレクトリ配下のファイルのリスト(permission, id, md5sumを含む)を再帰的に取得する
#!/usr/bin/env perl
use strict;
use warnings;
die "Usage: $0 <root_path>" unless @ARGV == 1;
my $root_path = $ARGV[0];
print_file_list($root_path);
sub print_file_list {
my $target_dir = shift;
die "$target_dir is not a directory" unless `adb shell 'test -d \"$target_dir\"; echo \$?'` == 0;
print "files in \"$target_dir\"", "\n";
my @ls_result = `adb shell busybox ls -al \"$target_dir\"`;
my @dir_list = ();
foreach my $line (@ls_result) {
chomp($line);
$line =~ s/\r$//g;
$line =~ /^(.)(\S+\s+){8}(.+)$/;
die "cannot get file type" unless defined $1;
my $filetype = $1;
die "cannot get filename" unless defined $3;
my $filename = $3;
next if ($filename eq "." or $filename eq "..");
if ($filetype eq "d") {
push @dir_list, $filename;
print $line, "\n";
} elsif ($filetype eq "-") {
my $md5sum = `adb shell md5sum \"$target_dir/$filename\"`;
$md5sum =~ s/\s.*//g;
die "cannot get md5sum of \"$target_dir/$filename\"" unless $md5sum =~ /^\w{32}$/;
print $line, " $md5sum", "\n";
} else {
print $line, "\n";
}
}
print"\n";
foreach my $dirname (@dir_list) {
print_file_list("$target_dir/$dirname");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment