# Path: interface/messages.py
# def print_success(*args, **kwargs):
#     print(Color.GREEN + Color.BOLD + "[+]" + Color.ENDC, *args, **kwargs)
# 
# def print_green(msg):
#     print(Color.GREEN + msg + Color.ENDC)
# 
# def print_yellow(msg):
#     print(Color.YELLOW + msg + Color.ENDC)
# 
# def print_warning(*args, **kwargs):
#     print(Color.YELLOW + Color.BOLD + "[!]" + Color.ENDC, *args, **kwargs)
# 
# def print_info(*args, **kwargs):
#     print(Color.BLUE + Color.BOLD + "[*]" + Color.ENDC, *args, **kwargs)


import core.Decryptor
import core.io
import core.compression.lzo
import math
from interface.messages import print_success, print_green, print_yellow, print_warning, print_info
from collections import defaultdict
from struct import unpack, pack
            if freq > 0:
                ffreq = float(freq) / dlen
                # actual entropy calcualtion
                ent -= ffreq * math.log(ffreq, 2)
        return ent

    def get_modelid(self, data):
        """Extract a model ID from config file header"""
        modelid = data[0x0C:0x0E]
        return modelid

    def decompress_cfg(self, data):
        """Decompress a config file"""
        modelstr = "V" + format(unpack(">H", self.get_modelid(data))[0], "04X")
        print_info('Model is :\t' + modelstr)
        rawcfgsize = 0x00100000
        lzocfgsize = unpack(">L", data[0x24:0x28])[0]
        raw = data[:0x2D] + b'\x00' + data[0x2E:0x100] + \
              core.compression.lzo.pydelzo.decompress(b'\xF0' + pack(">L", rawcfgsize) + data[0x100:0x100 + lzocfgsize])
        return raw

    def decrypt_cfg(self, data):
        """Decrypt config, bruteforce if default key fails"""
        modelstr = "V" + format(unpack(">H", self.get_modelid(data))[0], "04X")
        print_info('Model is :\t' + modelstr)
        ckey = self.make_key(modelstr)
        rdata = self.decrypt(data[0x100:], ckey)
        # if the decrypted data does not look good, bruteforce
        if self.smart_guess(rdata) != self.CFG_LZO:
            rdata = self.brute_cfg(data[0x100:])

# Path: interface/messages.py
# def print_success(*args, **kwargs):
#     print(Color.GREEN + Color.BOLD + "[+]" + Color.ENDC, *args, **kwargs)
# 
# def print_green(msg):
#     print(Color.GREEN + msg + Color.ENDC)
# 
# def print_yellow(msg):
#     print(Color.YELLOW + msg + Color.ENDC)
# 
# def print_warning(*args, **kwargs):
#     print(Color.YELLOW + Color.BOLD + "[!]" + Color.ENDC, *args, **kwargs)
# 
# def print_info(*args, **kwargs):
#     print(Color.BLUE + Color.BOLD + "[*]" + Color.ENDC, *args, **kwargs)


# Path: modules/decryptors/draytek/vigor_config_old.py
import core.Decryptor
import core.io
import core.compression.lzo
import math
from interface.messages import print_success, print_green, print_yellow, print_warning, print_info
from collections import defaultdict
from struct import unpack, pack

            if freq > 0:
                ffreq = float(freq) / dlen
                # actual entropy calcualtion
                ent -= ffreq * math.log(ffreq, 2)
        return ent

    def get_modelid(self, data):
        """Extract a model ID from config file header"""
        modelid = data[0x0C:0x0E]
        return modelid

    def decompress_cfg(self, data):
        """Decompress a config file"""
        modelstr = "V" + format(unpack(">H", self.get_modelid(data))[0], "04X")
        print_info('Model is :\t' + modelstr)
        rawcfgsize = 0x00100000
        lzocfgsize = unpack(">L", data[0x24:0x28])[0]
        raw = data[:0x2D] + b'\x00' + data[0x2E:0x100] + \
              core.compression.lzo.pydelzo.decompress(b'\xF0' + pack(">L", rawcfgsize) + data[0x100:0x100 + lzocfgsize])
        return raw

    def decrypt_cfg(self, data):
        """Decrypt config, bruteforce if default key fails"""
        modelstr = "V" + format(unpack(">H", self.get_modelid(data))[0], "04X")
        print_info('Model is :\t' + modelstr)
        ckey = self.make_key(modelstr)
        rdata = self.decrypt(data[0x100:], ckey)
        # if the decrypted data does not look good, bruteforce
        if self.smart_guess(rdata) != self.CFG_LZO:
            rdata = self.brute_cfg(data[0x100:])

            print_success('Used key :\t[0x%02X]' % ckey)