Adapters - Wrappers to use with construct lib¶
Adapters and other Construct utility classes
-
class
xbox.sg.utils.adapters.CryptoTunnel(subcon)¶ Bases:
construct.core.SubconstructAdapter/Tunnel for inline decryption of protected payloads.
Depending on the packet-type, acquiring the Initialization Vector and decrypting the protected payload happens differently: * ConnectResponse: The IV is delivered in the unprotected payload section of the packet and can be used directly * Messages: The IV is generated by encrypting the first 16 bytes of the packet header using the IV key.
Inline encryption using this Tunnel is not (yet) possible due to limitations in Construct. As explained above, the IV for Messages is generated by encrypting the first 16 bytes of the header. However, there’s currently no method of determining the length of the payload without building it first. Therefor, the IV wouldn’t be correct.
-
static
decrypt(stream, context)¶
-
static
-
class
xbox.sg.utils.adapters.JsonAdapter(subcon)¶ Bases:
construct.core.AdapterConstruct-Adapter for JSON field.
Parses and dumps JSON.
-
class
xbox.sg.utils.adapters.UUIDAdapter(encoding=None)¶ Bases:
construct.core.Adapter
-
class
xbox.sg.utils.adapters.CertificateAdapter¶ Bases:
construct.core.Adapter-
__init__()¶ Construct-Adapter for Certificate field.
Parses and dumps the DER certificate as used in the discovery response messages.
-
-
class
xbox.sg.utils.adapters.CertificateInfo(raw_cert)¶ Bases:
object-
__init__(raw_cert)¶ Helper class for parsing a x509 certificate.
Extracts common_name and public_key from the certificate.
- Parameters
raw_cert (bytes) – The DER certificate to parse.
-
dump(encoding=<Encoding.DER: 'DER'>)¶
-
-
class
xbox.sg.utils.adapters.XSwitch(keyfunc, cases, default=None)¶ Bases:
construct.core.Switch
-
class
xbox.sg.utils.adapters.XEnum(subcon, enum=None)¶ Bases:
construct.core.Adapter-
__init__(subcon, enum=None)¶ Construct-Adapter for Enum field.
Parses numeric fields into XEnumInt’s, which display the Enum name and value.
- Parameters
subcon (Construct) – The subcon to adapt.
enum (Enum) – The enum to parse into.
-
-
class
xbox.sg.utils.adapters.XInject(code)¶ Bases:
construct.core.Construct
-
class
xbox.sg.utils.adapters.TerminatedField(subcon, length=1, pattern=b'\x00')¶ Bases:
construct.core.Subconstruct-
__init__(subcon, length=1, pattern=b'\x00')¶ A custom
Subconstructthat adds a termination character at the end of the child struct.
-
-
xbox.sg.utils.adapters.SGString(encoding='utf8')¶ Defines a null terminated PascalString.
The Smartglass protocol seems to always add a termination character behind a length prefixed string. This utility function combines a PascalString with a TerminatedField.
- Parameters
encoding (str) – The string encoding to use for the PascalString.
- Returns
A null byte terminated PascalString.
- Return type
SGString
-
xbox.sg.utils.adapters.PrefixedBytes(lengthfield)¶ Defines a length prefixed bytearray.
- Parameters
lengthfield (
Subconstruct) – The length subcon.- Returns
A length prefixed bytesarray
- Return type
PrefixedBytes