| 1 | 1 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | package App::Pasar 0.02; | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Archive::Asar 0.02 (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Getopt::Long qw(GetOptionsFromArray :config gnu_getopt); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 0 | ▶ | sub version() { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 0 | say "pasar (" . __PACKAGE__ . ") " . __PACKAGE__->VERSION; | |||||||||||||||||||||||||||||||||||||||||
| 8 | 0 | exit; | |||||||||||||||||||||||||||||||||||||||||
| 9 | } | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 0 | ▶ | sub usage($err) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
usage: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | ▶ | print { $err ? \*STDERR : \*STDOUT } <<~"_EOT_"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | Usage: $0 OPTION... FILE [DIRECTORY] | ||||||||||||||||||||||||||||||||||||||||||
| 14 | Extract data from Electron ASAR archive files. | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | -l, --list list contents of archive FILE | ||||||||||||||||||||||||||||||||||||||||||
| 17 | -x, --extract recursively extract contents of FILE to DIRECTORY | ||||||||||||||||||||||||||||||||||||||||||
| 18 | -u DIR, --unpacked=DIR read archive files marked "unpacked" from DIR | ||||||||||||||||||||||||||||||||||||||||||
| 19 | instead; if DIR is the empty string, "unpacked" | ||||||||||||||||||||||||||||||||||||||||||
| 20 | files are skipped instead | ||||||||||||||||||||||||||||||||||||||||||
| 21 | -h, --help display this help and exit | ||||||||||||||||||||||||||||||||||||||||||
| 22 | --version output version information and exit | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | Either -l/--list or -x/--extract must be given. | ||||||||||||||||||||||||||||||||||||||||||
| 25 | _EOT_ | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | exit($err ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | sub list($asar) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list: called CC=8 SCAR=21.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 10 | ▶ | my sub esc($x, $harder) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
esc: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 10 | ▶ | $x =~ s{([/\\])}{\\$1}g if $harder; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | $x =~ s{([\x00-\x1f])}{ sprintf '\\x%02x', ord $1 }eg; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 10 | $x | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 8 | ▶ | my sub get_node($path, $node) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_node: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 8 | for my $p (@$path) { | |||||||||||||||||||||||||||||||||||||||||
| 38 | 10 | ▶ | $node = $node->{files}{$p} // return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$node->{"files"}{$p} // (return undef)
MC/DC0%0/1
$node->{"files"}{$p} // (return undef)
$node->{"files"}{$p}
Truth table50%1/2
A
A= $node->{"files"}{$p}
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | $node | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 8 | } | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | my $index = $asar->index_raw; | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | my $listing = ''; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | my @stack = []; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | while (@stack) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 8 | my $path = pop @stack; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 8 | my $node = get_node $path, $index; | |||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 8 | my $name = join '/', map esc($_, 1), @$path; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 8 | ▶ | if (exists $node->{link}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $listing .= "LINK $name -> " . esc($node->{link}, 0) . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 54 | } elsif (exists $node->{files}) { | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 3 | push @stack, map [@$path, $_], sort { $b cmp $a } keys $node->{files}->%*; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 3 | ▶ | my $unpacked = $node->{unpacked} ? ' (unpacked)' : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | ▶ | $listing .= "DIR $name$unpacked\n" if @$path; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 5 | ▶ | my $size = exists $node->{size} ? ' ' . (0 + $node->{size}) : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 5 | ▶ | my $unpacked = $node->{unpacked} ? ' (unpacked)' : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 5 | $listing .= "FILE $name$size$unpacked\n"; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | $listing | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | } | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | ▶ | sub main(@args) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
main: called CC=17 SCAR=38.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | GetOptionsFromArray( | ||||||||||||||||||||||||||||||||||||||||||
| 70 | \@args, | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 'create|c' => \my $opt_create, | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 'list|l' => \my $opt_list, | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 'extract|x' => \my $opt_extract, | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 'unpacked|u=s' => \my $opt_unpacked, | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | 'help|h' => sub (@) { usage 0 }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | 'version' => sub (@) { version }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 2 | ▶ | ) or usage 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | ▶ | $opt_create || $opt_list || $opt_extract | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$opt_create or $opt_list or $opt_extract
$opt_create or $opt_list
MC/DC0%0/3
$opt_create or $opt_list or $opt_extract
$opt_create
$opt_list
$opt_extract
Truth table50%2/4
A or B or C
A= $opt_createB= $opt_listC= $opt_extract
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | or die "$0: either --create, --list, or --extract must be given\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 2 | ▶ | @args or die "$0: no archive name\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | my $asarfile = shift @args; | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | my $asar; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | ▶ | if ($opt_create) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $asar = Archive::Asar->new_empty($asarfile); | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | for my $arg (@args) { | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my @path = grep $_ ne '.', split m{[/\\]+}, $arg, -1; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if (grep $_ eq '..', @path) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | die "$0: can't embed paths containing '..': $arg\n"; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $asar->ingest(\@path, $arg); | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $asar->write_to_file($asarfile); | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | ▶ | if ($opt_list) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | ▶ | $asar //= Archive::Asar->new_from_file($asarfile); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$asar //= "Archive::Asar"->new_from_file($asarfile)
MC/DC0%0/2
$asar //= "Archive::Asar"->new_from_file($asarfile)
$asar
"Archive::Asar"->new_from_file($asarfile)
Truth table33%1/3
A //= B
A= $asarB= "Archive::Asar"->new_from_file($asarfile)
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | print list($asar); | |||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 2 | ▶ | if ($opt_extract) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | ▶ | $asar //= Archive::Asar->new_from_file($asarfile); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$asar //= "Archive::Asar"->new_from_file($asarfile)
MC/DC0%0/2
$asar //= "Archive::Asar"->new_from_file($asarfile)
$asar
"Archive::Asar"->new_from_file($asarfile)
Truth table33%1/3
A //= B
A= $asarB= "Archive::Asar"->new_from_file($asarfile)
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | ▶ | my $outdir = @args ? shift @args : '.'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | my %opts; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | ▶ | if (defined $opt_unpacked) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | $opts{unpacked_dir} = length $opt_unpacked ? $opt_unpacked : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | } elsif (-d "$asarfile.unpacked") { | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $opts{unpacked_dir} = "$asarfile.unpacked"; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | $asar->extract_to($outdir, \%opts); | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | 1 | |||||||||||||||||||||||||||||||||||||||||
| 117 | __END__ | ||||||||||||||||||||||||||||||||||||||||||