Exemple #1
0
def obfuscate_sample(sample_file_name, obfuscator_list, sample_tf_dir):
    '''This function obfucate a sample with the obfuscators in the list using a temporary directory as support'''
    init(sample_tf_dir)
    if enable_logging:
        u.logger('Obfuscate Request: %s - %s - %s' %
                 (sample_file_name, obfuscator_list, sample_tf_dir))
    else:
        u.logger('Obfuscate Request')
    if not debug:
        clean_temp(sample_tf_dir)
    backsmali(sample_tf_dir, sample_file_name)
    start_time = datetime.utcnow()
    if enable_logging:
        u.logger('Obfuscate Start: ' + str(start_time))
    try:
        for obfuscator_item in obfuscator_list:
            obfuscator_method = obfuscator_mapping[obfuscator_item]
            obfuscator_method(sample_file_name, sample_tf_dir)
    except KeyError as ex:
        raise e.RunningObfuscatorException('Invalid obfuscator id ' + str(ex))
    end_time = datetime.utcnow()
    if enable_logging:
        u.logger('Obfuscate Stop: ' + str(end_time))
    u.logger('Obfuscate Time: ' + str(end_time - start_time))
    if cleanup:
        sample_ob_file_name = sample_file_name + 'Ob'
    else:
        sample_ob_file_name = sample_file_name
    smali(sample_tf_dir, sample_ob_file_name)
    sign_apk(sample_ob_file_name)
    if not debug:
        clean_temp(sample_tf_dir)
        if cleanup:
            clean_apk(sample_file_name)
    u.logger('### SUCCESS ### {' + str(end_time - start_time) + '}')
Exemple #2
0
def run_obfuscator_lib(sample_file_name, sample_tf_dir):
    try:
        if enable_logging:
            u.logger('Obfuscator Lib')
        apply_py_obfuscator(sample_file_name, sample_tf_dir, obfuscator_lib)
    except e.RunningObfuscatorException as ex:
        raise e.RunningObfuscatorException(str(ex) + '\nUnable to apply Lib')
Exemple #3
0
def run_obfuscator_zip(sample_file_name, sample_tf_dir):
    try:
        if enable_logging:
            u.logger('Obfuscator Align')
        apply_zip(sample_file_name)
    except e.RunningObfuscatorException as ex:
        raise e.RunningObfuscatorException(str(ex) + '\nUnable to apply Align')
Exemple #4
0
def run_obfuscator_resigned(sample_file_name, sample_tf_dir):
    try:
        if enable_logging:
            u.logger('Obfuscator Resign')
        apply_resign(sample_file_name)
    except e.OpenToolException as ex:
        raise e.RunningObfuscatorException(
            str(ex) + '\nUnable to apply Resign')
Exemple #5
0
def popen(com_str):
    p = sub.Popen(com_str, shell=True, stdout=sub.PIPE, stderr=sub.PIPE)
    out, err = p.communicate()
    if enable_logging:
        u.logger(out)
        u.logger(err)
    if 'Exception' in out or 'Exception' in err:
        if 'method index is too large' in out or 'method index is too large' in err:
            raise e.AndroidLimitException('Unable run :' + com_str)
        elif 'java.lang.ArrayIndexOutOfBoundsException' in out or 'java.lang.ArrayIndexOutOfBoundsException' in err:
            raise e.AndroidRandomException('Unable run :' + com_str)
        else:
            raise e.RunningObfuscatorException('Unable run :' + com_str)
Exemple #6
0
def apply_py_obfuscator(sample_file_name, sample_tf_dir, obfuscatorPy):
    '''Apply an obfuscator'''
    try:
        if enable_logging:
            u.logger('Python Obfuscator!')
        #backsmali(sample_tf_dir, sample_file_name)
        obfuscatorPy.obfuscate()
        if debug:
            smali(sample_tf_dir, sample_file_name)
        #sign_apk(sample_file_name)
        #clean_temp(sample_tf_dir)
    except (e.OpenToolException, e.LoadFileException) as ex:
        raise e.RunningObfuscatorException(
            str(ex) + '\nUnable run python obfuscator')
Exemple #7
0
def apply_zip(sample_file_name):  # Zipaling an apk file
    try:
        zip_align(sample_file_name)
    except e.OpenToolException as ex:
        raise e.RunningObfuscatorException(str(ex))
Exemple #8
0
def apply_resign(sample_file_name):  # Resign an apk file
    try:
        design_apk(sample_file_name)
        sign_apk(sample_file_name)
    except e.OpenToolException as ex:
        raise e.RunningObfuscatorException(str(ex))