Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no exit code as counter #44

Merged
merged 4 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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