# Path: malwareconfig/crypto.py
# def decrypt_rsa(key, data):
# def decrypt_xor(key, data):
# def decrypt_arc4(key, data):
# def decrypt_des_ecb(key, data, iv=None):
# def decrypt_des_cbc(key, data, iv=None):
# def decrypt_des3(key, data):
# def decrypt_aes(key, data):
# def decrypt_aes_cbc_iv(key, iv, data):
# def decrypt_blowfish(key, data):
# def decrypt_RC6(key, encrypted, P, Q, rounds):
#     def rol(a, i):
#     def ror(a, i):
#     def to_int(bytestring):
#     def decrypt_block(block, S):
# def derive_pbkdf2(key, salt, iv_length, key_length, iterations=8):
#     T = 2 * rounds + 4
#     L = to_int(key)
#     S = []
#     S = [0 for i in range(T)]
#     S[0] = P
#     A = 0
#     B = 0
#         A = S[i] = rol((S[i] + A + B), 3)
#         B = L[j] = rol((L[j] + A + B), (A + B))
# 
# Path: malwareconfig/common.py
# class Decoder(object):
#     decoder_name = ""
#     decoder_version = 1
#     decoder_author = ""
#     decoder_description = ""
#     file_info = object
# 
#     def set_file(self, file_info):
#         self.file_info = file_info
# 
#     def get_config(self):
#         pass
# 
# Path: malwareconfig/fileparser.py
# class FileParser:
#     def __init__(self, file_path=None, rawdata=None):
#     def yarascan(self):
#     def file_hash(self, hash_type="sha256"):
#     def pe_resource_id(self, res_id):
#         def modules_callback(data):
#     def pe_resource_names(self):
#     def pe_resource_by_name(self, resource_name):
#     def dotnet_resource_names(self):
#         def modules_callback(data):
#     def dotnet_resource_by_name(self, resource_name):
#         def modules_callback(data):
#     def dotnet_guids(self):
#         def modules_callback(data):
#     def dotnet_user_strings(self):
#         def modules_callback(data):
#     def ascii_strings(self, min_len=4):
#     def unicode_strings(self, min_len=4):
#     def file_from_zip(self, filename):
#     def zip_namelist(self):
#     def parse_apk(self):
#     def elf_list_sections(self):
#         def modules_callback(data):
#     def elf_section_by_name(self, resource_name):
#         def modules_callback(data):


from binascii import unhexlify
from base64 import b64decode
from malwareconfig import crypto
from malwareconfig.common import Decoder
from malwareconfig import fileparser
        file_info = self.file_info
        file_list = file_info.zip_namelist()

        internal_jar = None
        key_file = None
        config_data = None

        config_dict = {}

        for name in file_list:
            if name == 'key.dat':
                key_file = file_info.file_from_zip(name)
            if name == 'enc.dat':
                internal_jar = file_info.file_from_zip(name)
            if name == 'config.dat':
                config_data = file_info.file_from_zip(name)

        # If there is a wrapper around the jrat
        if internal_jar:
            drop_conf = key_file
            new_key = drop_conf[:16]
            drop_conf_fields = key_file[16:].split(b',')
            config_dict['dropper'] = []
            for field in drop_conf_fields:
                try:
                    decoded_field = b64decode(field).decode('utf-8')
                    config_dict['dropper'].append(unhexlify(decoded_field))
                except:
                    pass


# Path: malwareconfig/crypto.py
# def decrypt_rsa(key, data):
# def decrypt_xor(key, data):
# def decrypt_arc4(key, data):
# def decrypt_des_ecb(key, data, iv=None):
# def decrypt_des_cbc(key, data, iv=None):
# def decrypt_des3(key, data):
# def decrypt_aes(key, data):
# def decrypt_aes_cbc_iv(key, iv, data):
# def decrypt_blowfish(key, data):
# def decrypt_RC6(key, encrypted, P, Q, rounds):
#     def rol(a, i):
#     def ror(a, i):
#     def to_int(bytestring):
#     def decrypt_block(block, S):
# def derive_pbkdf2(key, salt, iv_length, key_length, iterations=8):
#     T = 2 * rounds + 4
#     L = to_int(key)
#     S = []
#     S = [0 for i in range(T)]
#     S[0] = P
#     A = 0
#     B = 0
#         A = S[i] = rol((S[i] + A + B), 3)
#         B = L[j] = rol((L[j] + A + B), (A + B))
# 
# Path: malwareconfig/common.py
# class Decoder(object):
#     decoder_name = ""
#     decoder_version = 1
#     decoder_author = ""
#     decoder_description = ""
#     file_info = object
# 
#     def set_file(self, file_info):
#         self.file_info = file_info
# 
#     def get_config(self):
#         pass
# 
# Path: malwareconfig/fileparser.py
# class FileParser:
#     def __init__(self, file_path=None, rawdata=None):
#     def yarascan(self):
#     def file_hash(self, hash_type="sha256"):
#     def pe_resource_id(self, res_id):
#         def modules_callback(data):
#     def pe_resource_names(self):
#     def pe_resource_by_name(self, resource_name):
#     def dotnet_resource_names(self):
#         def modules_callback(data):
#     def dotnet_resource_by_name(self, resource_name):
#         def modules_callback(data):
#     def dotnet_guids(self):
#         def modules_callback(data):
#     def dotnet_user_strings(self):
#         def modules_callback(data):
#     def ascii_strings(self, min_len=4):
#     def unicode_strings(self, min_len=4):
#     def file_from_zip(self, filename):
#     def zip_namelist(self):
#     def parse_apk(self):
#     def elf_list_sections(self):
#         def modules_callback(data):
#     def elf_section_by_name(self, resource_name):
#         def modules_callback(data):


# Path: malwareconfig/decoders/jrat.py
from binascii import unhexlify
from base64 import b64decode
from malwareconfig import crypto
from malwareconfig.common import Decoder
from malwareconfig import fileparser

        file_info = self.file_info
        file_list = file_info.zip_namelist()

        internal_jar = None
        key_file = None
        config_data = None

        config_dict = {}

        for name in file_list:
            if name == 'key.dat':
                key_file = file_info.file_from_zip(name)
            if name == 'enc.dat':
                internal_jar = file_info.file_from_zip(name)
            if name == 'config.dat':
                config_data = file_info.file_from_zip(name)

        # If there is a wrapper around the jrat
        if internal_jar:
            drop_conf = key_file
            new_key = drop_conf[:16]
            drop_conf_fields = key_file[16:].split(b',')
            config_dict['dropper'] = []
            for field in drop_conf_fields:
                try:
                    decoded_field = b64decode(field).decode('utf-8')
                    config_dict['dropper'].append(unhexlify(decoded_field))
                except:
                    pass


            new_jar_data = crypto.decrypt_aes(new_key, internal_jar)