Firmware modulation (fmod)

Interface

hiktools.fmod.read_raw_header(resource: str) bytes

Reads the first 108 bytes from the resource stream.

hiktools.fmod.decode_xor16(buf: bytes, key: bytes, length: int) bytes

Decodes (XOR) the given buf with a key.

hiktools.fmod.split_header(buf: bytes) DigiCapHeader

Extracts information from the decoded firmware header.

hiktools.fmod.split_files(buf: TextIOWrapper, length: int = 0) Generator[tuple, None, None]

Iterates over all files located in the given filesystem index.

hiktools.fmod.fopen_dav(file_name: str, mode: str = 'rb') TextIOWrapper

Opens a file with te ‘dav’ extension.

Parameters:
  • file_name (str) – The absolute or relative path to the file

  • mode (str) – The mode this file shoul be opened with (either ‘r’ or ‘rb’)

Raises:
Returns:

A file reader instance.

Return type:

TextIOWrapper

hiktools.fmod.export(dfile: DigiCap, location: str) bool

Extracts all files stored in the given digicap file.

Classes

class hiktools.fmod.DigiCap(resource: TextIOWrapper = None)

The base class for operating with digicap.dav files.

KEY_XOR = b'\xba\xcd\xbc\xfe\xd6\xca\xdd\xd3\xba\xb9\xa3\xab\xbf\xcb\xb5\xbe'

The key used to encrypt/decrypt the firmware files.

fclose()

Closes the current file reader.

Will be called automatically when this class is used in a with statement.

fopen(resource: str) bool

Opens the given resource.

Will be called automatically when this class is used in a with statement.

fparse()

Parses the firmware file.

fread(length: int, offset: int = -1) bytes

Reads the given amount of bytes from the underlying stream.

property head: DigiCapHeader

The header object storing important configuration data.

property name: str

The file name (absolute or relative)

reset() bool

Sets the reader’s position to the start of the stream.

Usage:

from hiktools import fmod

 # Open the resource at the specified path (loading is done automatically)
 # or manually decrypt the firmware file.
 with fmod.DigiCap('filename.dav') as dcap:
    # Iterate over all files stored in the DigiCap object
    for file_info in dcap:
       print('> File name="%s", size=%d, pos=%d, checksum=%d' % file_info)

    # get file amount and current language
    print("Files: %d, Language: %d" % (dcap.head.files, dcap.head.language))

    # save all files stored in <filename.dav>
    fmod.export(dcap, "outdir/")
class hiktools.fmod.DigiCapHeader(magic: c_uint = 0, header_checksum: c_uint = 0, header_length: c_uint = 0, files: c_uint = 0, language: c_uint = 0, device_class: c_uint = 0, oem_code: c_uint = 0, signature: c_uint = 0, features: c_uint = 0)

A class covering important configuration information.

Parameters:
  • magic (c_uint32) – magic header bytes indicating the used firmware

  • header_checksum (c_uint32) – unused.

  • header_length (c_uint32) – The header length is used to indicate the end of the filesystem index.

  • files (c_uint32) – The amount of files stored in this firmware image.

  • language (c_uint32) – The used language

  • device_class (c_uint32) – unidentified

  • oem_code (c_uint32) – maybe system verfication key

  • signature (c_uint32) – unidentified

  • features (c_uint32) – unidentified

Exceptions

class hiktools.fmod.InvalidFileFormatException

Base class for DAV file exceptions.

class hiktools.fmod.FileAccessException

Base class for permission related issues.