# Path: interface/messages.py
# def print_error(*args, **kwargs):
#     print(Color.RED + Color.BOLD + "[-]" + Color.ENDC, *args, **kwargs)
# 
# def print_success(*args, **kwargs):
#     print(Color.GREEN + Color.BOLD + "[+]" + Color.ENDC, *args, **kwargs)
# 
# 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 os
from interface.messages import print_error, print_success, print_warning, print_info
from struct import unpack, pack
        if result is not None:
            dirpath = core.io.writefile(result, "fw.decomp")
            print_success("Decompressed firmware written to fw.decomp")
            self.decompress_fs_only(data, dirpath)
            print_success("FS decompressed")

    #Code from draytools, with minor modifications for REXT and python3
    @staticmethod
    def decompress_firmware(data):
        """Decompress firmware"""
        flen = len(data)
        sigstart = data.find(b'\xA5\xA5\xA5\x5A\xA5\x5A')
        # Try an alternative signature
        if sigstart <= 0:
            sigstart = data.find(b'\x5A\x5A\xA5\x5A\xA5\x5A')
        # Compressed FW block found, now decompress
        if sigstart > 0:
            print_info('Signature found at [0x%08X]' % sigstart)
            lzosizestart = sigstart + 6
            lzostart = lzosizestart + 4
            lzosize = unpack('>L', bytes(data[lzosizestart:lzostart]))[0]
            return data[0x100:sigstart + 2] + core.compression.lzo.pydelzo.decompress(
                b'\xF0' + pack(">L", 0x1000000) + data[lzostart:lzostart + lzosize])
        else:
            print_error('Compressed FW signature not found!')
            return None

    def decompress_fs_only(self, data, path):
        """Decompress filesystem"""
        fsstart = unpack('>L', data[:4])[0]

# Path: interface/messages.py
# def print_error(*args, **kwargs):
#     print(Color.RED + Color.BOLD + "[-]" + Color.ENDC, *args, **kwargs)
# 
# def print_success(*args, **kwargs):
#     print(Color.GREEN + Color.BOLD + "[+]" + Color.ENDC, *args, **kwargs)
# 
# 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_fw_decompress.py
import core.Decryptor
import core.io
import core.compression.lzo
import os
from interface.messages import print_error, print_success, print_warning, print_info
from struct import unpack, pack

        if result is not None:
            dirpath = core.io.writefile(result, "fw.decomp")
            print_success("Decompressed firmware written to fw.decomp")
            self.decompress_fs_only(data, dirpath)
            print_success("FS decompressed")

    #Code from draytools, with minor modifications for REXT and python3
    @staticmethod
    def decompress_firmware(data):
        """Decompress firmware"""
        flen = len(data)
        sigstart = data.find(b'\xA5\xA5\xA5\x5A\xA5\x5A')
        # Try an alternative signature
        if sigstart <= 0:
            sigstart = data.find(b'\x5A\x5A\xA5\x5A\xA5\x5A')
        # Compressed FW block found, now decompress
        if sigstart > 0:
            print_info('Signature found at [0x%08X]' % sigstart)
            lzosizestart = sigstart + 6
            lzostart = lzosizestart + 4
            lzosize = unpack('>L', bytes(data[lzosizestart:lzostart]))[0]
            return data[0x100:sigstart + 2] + core.compression.lzo.pydelzo.decompress(
                b'\xF0' + pack(">L", 0x1000000) + data[lzostart:lzostart + lzosize])
        else:
            print_error('Compressed FW signature not found!')
            return None

    def decompress_fs_only(self, data, path):
        """Decompress filesystem"""
        fsstart = unpack('>L', data[:4])[0]

        print_info('FS block start at: %d [0x%08X]' % (fsstart, fsstart))