script/electric-sheep-find-running-processes.pl untested

filter: Statementstmt 0.0% 0 / 49 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 71 CC 1 SCAR 6.9
CC
1
Cov
0%
usage
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/env perl
2  
3 use strict;
4 use warnings;
5  
6 our $VERSION = '0.09';
7  
8 use lib ('blib/lib');
9  
10 use Getopt::Long qw(:config no_ignore_case);
11 use Data::Roundtrip qw/perl2dump perl2json no-unicode-escape-permanently/;
12  
13 use Android::ElectricSheep::Automator;
14  
15 my $VERBOSITY = 0; # we need verbosity of 10 (max), so this is not used
16 my $DEVICE;
17 my $CONFIGFILE;
18 my $OUTFILE;
19  
20 if( ! Getopt::Long::GetOptions(
21 'device|d=s' => \$DEVICE,
22 'verbosity|v=i' => \$VERBOSITY,
23 'output|o=s'=> \$OUTFILE,
24 'configfile|c=s' => \$CONFIGFILE,
25 'help|h' => sub { print STDOUT usage(); exit(0); }
26 ) ){ die usage() }
27  
28 if( ! defined $CONFIGFILE ){ print STDERR usage(); print STDERR "\n$0 : error, a configuration file must be specified with '--configfile'.\n"; exit(1); }
29 if( ! -f $CONFIGFILE ){ die "$0 : failed to find config file '$CONFIGFILE'." }
30  
31 my $params = {
32 'configfile' => $CONFIGFILE,
33 'verbosity' => $VERBOSITY,
34 };
35 # we assume there is a device connected which the user
36 # must specify by serial, of if just one, we connect to
37 # it without the serial
38 if( defined $DEVICE ){ $params->{'device-serial'} = $DEVICE }
39 else { $params->{'device-is-connected'} = 1 }
40  
41 my $client = Android::ElectricSheep::Automator->new($params);
42 if( ! defined($client) ){ die "$0 : failed to instantiate the automator." }
43  
44 my $ret = $client->list_running_processes({
45 'filename' => $OUTFILE
46 });
47 if( ! defined($ret) ){ die "$0 : failed to find running processes." }
48  
49 print STDOUT $ret->{'raw'};
50  
51 print STDOUT "$0 : done, success!".(defined($OUTFILE)?" Output JSON written to file '$OUTFILE'.\n":"\n");
52  
53 sub usage {
54 return "Usage $0 --configfile CONFIGFILE [--output procs.json] [--device DEVICE] [--verbosity v]\n"
55 . "\nThis script will print the currently running processes in the device to STDOUT (as a normal 'ps' output), optionally saving a JSON version of the parsed 'ps' output to file.\n"
56 . "\nExample:\n"
57 . "$0 --configfile config/myapp.conf --output procs.json\n"
58 . "\nProgram by Andreas Hadjiprocopis (c) 2025 / bliako at cpan.org / andreashad2 at gmail.com\n\n"
59 ;
60 }
61  
62 1;