All pastes #771989 Raw Edit

Perl script to dump root filesys

public text v1 · immutable
#771989 ·published 2007-11-13 13:19 UTC
rendered paste body
sub process_dir ($) {
	my ($path) = shift;
	print "d\t$path\n";
	return if $path eq "/sys/";
	return if $path eq "/proc/";
	return if $path eq "/dev/"; 
	my @dirs = ();
	open(IN, "/cygdrive/c/Android/tools/adb shell ls $path |");
	while (<IN>) {
		chomp $_;
		if (m/^d[-rwxst]+\s+\w+\s+\w+\s+[0-9]+-[0-9]+-[0-9]+\s+[0-9]+:[0-9]+\s+([-_a-zA-Z0-9.+@]+)\s+/) {
			next if $1 eq $path;
			push(@dirs, "$path$1/");
		}
		elsif (m/^-[-rwxst]+\s+\w+\s+\w+\s+[0-9]+\s+[0-9]+-[0-9]+-[0-9]+\s+[0-9]+:[0-9]+\s+([-_a-zA-Z0-9.+@]+)\s+/) {
			print "f\t$path$1\n";
		}
		elsif (m/^p[-rwxst]+\s+\w+\s+\w+\s+[0-9]+-[0-9]+-[0-9]+\s+[0-9]+:[0-9]+\s+([-_a-zA-Z0-9.+@]+)\s+/) {
			print "p\t$path$1\n";
		}
		elsif (m/^s[-rwxst]+\s+\w+\s+\w+\s+[0-9]+-[0-9]+-[0-9]+\s+[0-9]+:[0-9]+\s+([-_a-zA-Z0-9.+@]+)\s+/) {
			print "s\t$path$1\n";
		}
		elsif (m/^l[-rwxst]+\s+\w+\s+\w+\s+[0-9]+-[0-9]+-[0-9]+\s+[0-9]+:[0-9]+\s+([-_a-zA-Z0-9.+@]+)\s+->\s+([-_a-zA-Z0-9.+@]+)\s+/) {
			print "l\t$path$1 -> $2\n";
		}
		elsif (m/^\s+$/) {
			next;
		}
		else {
			print "Entry $_ unmatched\n";
			exit 1;
		}	
	}
	close(IN);

	foreach (@dirs) {
		process_dir($_);
	}
}

process_dir("/");