# 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



class Decryptor(core.Decryptor.RextDecryptor):
    """
Name:Draytek Vigor 2XXX/3XXX series FW decompression and FS extraction
File:vigor_fw_decompress.py
Author:Ján Trenčanský
License: GNU GPL v3
Created: 25.2.2014
Description: Decompress firmware file extract filesystem

Options:
    Name        Description

    file        Input firmware file path
    """

    def __init__(self):
        core.Decryptor.RextDecryptor.__init__(self)

    def do_run(self, e):
        f = open(self.input_file, 'rb')
        data = f.read()
        f.close()
        result = self.decompress_firmware(data)
        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)

# 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




class Decryptor(core.Decryptor.RextDecryptor):
    """
Name:Draytek Vigor 2XXX/3XXX series FW decompression and FS extraction
File:vigor_fw_decompress.py
Author:Ján Trenčanský
License: GNU GPL v3
Created: 25.2.2014
Description: Decompress firmware file extract filesystem

Options:
    Name        Description

    file        Input firmware file path
    """

    def __init__(self):
        core.Decryptor.RextDecryptor.__init__(self)

    def do_run(self, e):
        f = open(self.input_file, 'rb')
        data = f.read()
        f.close()
        result = self.decompress_firmware(data)
        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")