File: androdd.py

package info (click to toggle)
androguard 3.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 62,444 kB
  • sloc: python: 24,366; xml: 3,187; java: 1,837; makefile: 228; sh: 12
file content (63 lines) | stat: -rwxr-xr-x 2,208 bytes parent folder | download | duplicates (2)
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
63
#!/usr/bin/env python

from __future__ import print_function

import os
import sys
from argparse import ArgumentParser

from androguard import session
from androguard.core import androconf
from androguard.cli import export_apps_to_format


def get_parser():
    parser = ArgumentParser(description="Decompile an APK and create Control Flow Graphs")

    parser.add_argument("--version", "-v", action="store_true", default=False,
            help="Print androguard version and exit")
    parser.add_argument("--input", "-i",
            help="resources.arsc or APK to parse (legacy option)")
    parser.add_argument("file", nargs="?",
            help="resources.arsc or APK to parse")
    parser.add_argument("--output", "-o", required=True,
            help="output directory. If the output folder already exsist, it will"
            "be overwritten!")
    parser.add_argument("--format", "-f",
            help="Additionally write control flow graphs for each method,"
            "specify the format for example png, jpg, raw (write dot file), ...")
    parser.add_argument("--jar", "-j", action="store_true", default=False,
            help="Use DEX2JAR to create a JAR file")
    parser.add_argument("--limit", "-l",
            help="Limit to certain methods only by regex (default: '.*')")
    parser.add_argument("--decompiler", "-d",
            help="Use a different decompiler (default: DAD)")
    return parser


if __name__ == "__main__":
    parser = get_parser()
    args = parser.parse_args()

    if args.file and args.input:
        print("Can not give --input and positional argument! Please use only one of them!", file=sys.stderr)
        sys.exit(1)

    if args.version:
        print("Androaxml version %s" % androconf.ANDROGUARD_VERSION)
        sys.exit(0)

    if not args.input and not args.file:
        print("Give one file to decode!", file=sys.stderr)
        sys.exit(1)

    if args.input:
        fname = args.input
    else:
        fname = args.file

    s = session.Session()
    with open(fname, "rb") as fd:
        s.add(fname, fd.read())
    export_apps_to_format(fname, s, args.output, args.limit,
                          args.jar, args.decompiler, args.format)