-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathls-phar.php
executable file
·62 lines (46 loc) · 1.53 KB
/
ls-phar.php
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 php
<?php
if (!isset($argv)) {
echo "E: This must be run from CLI", "\n"; exit(1);
}
$archive = $argv[1] ?? null;
$file = $argv[2] ?? null;
if (isset($file)) {
if (str_starts_with($file, "./") || $file == ".") {
$file = substr($file, 1);
}
$file = trim($file, "/");
}
if (!isset($archive) || !is_file($archive)) {
echo sprintf("Usage: %s <archive> [<file/dir>]", basename($argv[0])), "\n";
echo "------\n";
echo "Specify a file to dump it's content", "\n\n";
exit(1);
} else if (isset($file) && is_file("phar://{$archive}/{$file}")) {
echo "Dump: {$file}\n";
echo "------\n";
echo file_get_contents("phar://{$archive}/{$file}");
} else if (isset($file) && !is_dir("phar://{$archive}/{$file}")) {
echo "E: The path {$file} cannot be found", "\n"; exit(1);
} else {
$phar = new Phar($archive);
$itt = new RecursiveIteratorIterator($phar);
if ($phar->hasMetadata() && !isset($file)) {
echo sprintf("Usage: %s <archive> [<file/dir>]", basename($argv[0])), "\n";
echo "------\n";
echo "Specify a file to dump it's content", "\n\n";
echo "Metadata\n";
echo "------\n";
print_r($phar->getMetadata());
echo "\n";
} else if (!empty($file)) {
$file .= "/";
}
echo "Files\n";
echo "------\n";
foreach ($itt as $path) {
if (!isset($file) || str_starts_with($path, "phar://{$archive}/{$file}")) {
echo substr($path, strlen("phar://{$archive}")+1) . "\n";
}
}
}