Skip to content

Commit

Permalink
no exit code as counter (#44)
Browse files Browse the repository at this point in the history
Co-authored-by: umnik <[email protected]>
  • Loading branch information
DMyachin and umnik authored May 1, 2023
1 parent 096eb7b commit ec04052
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pip install -r requirements.txt

```bash
$ ./exodus_analyze.py --help
usage: exodus_analyze.py [-h] [-t] [-j] [-o OUTPUT_FILE] [-i IGNORE] apk
usage: exodus_analyze.py [-h] [-t] [-j] [-o OUTPUT_FILE] [-i IGNORE] [-e CODE] apk

positional arguments:
apk the apk file to analyse
Expand All @@ -75,6 +75,8 @@ optional arguments:
store JSON report in file (requires -j option)
-i IGNORE, --ignore IGNORE
comma-separated ids of trackers to ignore
-e CODE, --exit-code CODE
use the CODE instead of trackers counter as exit code if trackers was detected
```
#### Text output
Expand Down
16 changes: 13 additions & 3 deletions exodus_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def get_ignore_list(ignore_arg):
return ignored, ''


def analyze_apk(apk, json_mode, output_file, ignore_list):
def analyze_apk(apk, json_mode, output_file, forced_code, ignore_list):
analysis = AnalysisHelper(apk)
analysis.load_trackers_signatures()
if json_mode:
Expand All @@ -73,7 +73,10 @@ def analyze_apk(apk, json_mode, output_file, ignore_list):
analysis.print_embedded_trackers()

trackers_not_ignored = [t for t in analysis.detect_trackers() if t.id not in ignore_list]
sys.exit(len(trackers_not_ignored))
counter = len(trackers_not_ignored)
if all([counter, forced_code is not None]):
sys.exit(forced_code)
sys.exit(counter)


def main():
Expand Down Expand Up @@ -105,6 +108,13 @@ def main():
default=None,
help='comma-separated ids of trackers to ignore'
)
parser.add_argument(
'-e', '--exit-code',
metavar='CODE',
dest='override_code',
type=int,
help='use the CODE instead of trackers counter as exit code if trackers was detected'
)

args = parser.parse_args()
args_error = validate_arguments(args)
Expand All @@ -117,7 +127,7 @@ def main():
if ignore_error:
raise_error(parser, ignore_error)

analyze_apk(args.apk, args.json_mode, args.output_file, ignore_list)
analyze_apk(args.apk, args.json_mode, args.output_file, args.override_code, ignore_list)


if __name__ == '__main__':
Expand Down

0 comments on commit ec04052

Please sign in to comment.