예제 #1
0
파일: dsi.py 프로젝트: theGreenJedi/BciPy
    'event_code' / Enum(
        Int32ub,  # bytes 12-15
        VERSION=1,
        DATA_START=2,
        DATA_STOP=3,
        SENSOR_MAP=9,
        DATA_RATE=10),
    'sending_node' / Int32ub,  # bytes 16-19

    # Message data is optional
    # Previous implementation used If(this._.payload_length > 8, ...), but this
    # method does not seem to work in v2.8.

    # message_length: bytes 20-23, message: bytes 24+
    'message' / Optional(
        PascalString(lengthfield='message_length' / Int32ub,
                     encoding='ascii')))

EEG_data = Struct(
    'timestamp' / Float32b,  # bytes 12-15
    'data_counter' / Int8ub,  # byte 16; Unused, just 0 currently
    'ADC_status' / Bytes(6),  # bytes 17-22
    # bytes 23-26, 27-30, etc.
    'sensor_data' / Array((this._.payload_length - 11) // 4, Float32b))

null = Struct('none' / Array(111, Int8ub))

packet = Struct(
    Embedded(header), 'payload' / Embedded(
        Switch(this.type, {
            'NULL': null,
예제 #2
0
def remember_last(obj, ctx):
    """Stores the last-seen command byte in the parsing context.

    Bit of a hack to make running status support work.
    """
    setattr(ctx._root, '_last_command_byte', obj)


AppleMIDIExchangePacket = Struct(
    '_name' / Computed('AppleMIDIExchangePacket'),
    'preamble' / Const(b'\xff\xff'),
    'command' / Bytes(2),
    'protocol_version' / Int32ub,
    'initiator_token' / Int32ub,
    'ssrc' / Int32ub,
    'name' / Optional(CString('ascii')),
)

AppleMIDITimestampPacket = Struct(
    '_name' / Computed('AppleMIDITimestampPacket'),
    'preamble' / Const(b'\xff\xff'),
    'command' / Bytes(2),
    'ssrc' / Int32ub,
    'count' / Int8ub,
    'padding' / Padding(3),
    'timestamp_1' / Int64ub,
    'timestamp_2' / Int64ub,
    'timestamp_3' / Int64ub,
)

MIDIPacketHeader = Struct(
예제 #3
0
PrefixedString = PascalString(Asn1Length, "utf8")

AppName = PrefixedString
Version = PrefixedString
Icon = Prefixed(Asn1Length, GreedyBytes)

CURVE_SEPCK256K1 = 1
CURVE_PRIME256R1 = 2
CURVE_ED25519 = 4

Curve = FlagsEnum(
    Byte, secp256k1=CURVE_SEPCK256K1, prime256r1=CURVE_PRIME256R1, ed25519=CURVE_ED25519
)

DerivationPath = Prefixed(
    Asn1Length, Struct(curve=Curve, paths=Optional(GreedyRange(Bip32Path)))
)

Dependency = Prefixed(
    Asn1Length, Struct(name=PrefixedString, version=Optional(PrefixedString))
)

Dependencies = Prefixed(Asn1Length, GreedyRange(Dependency))


class BolosTag(enum.IntEnum):
    BOLOS_TAG_APPNAME = 1
    BOLOS_TAG_APPVERSION = 2
    BOLOS_TAG_ICON = 3
    BOLOS_TAG_DERIVEPATH = 4
    BOLOS_TAG_DEPENDENCY = 6
# fmt: off
RegistryRecord = Struct(
    "source" / UnicastUnassignedAddress,
    "count" / Int16ul,
    "min_hops" / ConfigHeartbeatHops,
    "max_hops" / ConfigHeartbeatHops
)

NetworkDiagnosticSetupServerPublicationSet = Struct(
    "destination" / UnicastUnassignedGroupAddress,
    "count" / Int16ul,
    "period" / TransitionTime,
    "ttl" / TTL,
    "net_key_index" / Int12ul,
    "features" / Optional(ConfigHeartbeatPublicationFeatures)
)

NetworkDiagnosticSetupServerPublicationStatus = NetworkDiagnosticSetupServerPublicationSet

NetworkDiagnosticServerSubscriptionSet = Struct(
    "destination" / UnicastUnassignedGroupAddress,
    "period" / Int16ul
)

NetworkDiagnosticServerSubscriptionStatus = Struct(
    "destination" / UnicastUnassignedGroupAddress,
    "period" / Int16ul,
    "max_record_count" / Const(MAX_RECORD_COUNT, Int8ul),
    "record" / GreedyRange(RegistryRecord)
)
예제 #5
0
        return obj.encode('hex')


WARP_WORLD = Struct(
    'to_world', Byte('world_id'),
    Switch('world_type',
           lambda ctx: ctx['world_id'], {
               1: LazyBound('next', lambda: WARP_WORLD_CELESTIAL),
               2: LazyBound('next', lambda: WARP_WORLD_PLAYER),
               3: LazyBound('next', lambda: WARP_WORLD_MISSION)
           },
           default=Pass))

WARP_WORLD_CELESTIAL = Struct(
    'celestial_world', SBInt32('x'), SBInt32('y'), SBInt32('z'),
    SBInt32('planet'), SBInt32('satellite'), Optional(Byte('has_position')),
    If(lambda ctx: ctx['has_position'],
       Struct('position', SBInt32('x'), SBInt32('y'))))

WARP_WORLD_PLAYER = Struct(
    'player_world', HexAdapter(Field('uuid', 16)),
    Optional(Byte('has_position')),
    If(lambda ctx: ctx['has_position'],
       Struct('position', SBInt32('x'), SBInt32('y'))))

WARP_WORLD_MISSION = Struct(
    'mission_world', star_string('mission_world_name'), Byte('check'),
    If(lambda ctx: ctx['check'] == 1, HexAdapter(Field('instance', 16))))


def packet(name='base_packet'):
예제 #6
0
        Int16ub,
        "alpn_protocols" / GreedyRange("name" / PascalString(Int8ub), ),
    ))

UnknownExtension = Struct("bytes" / PascalString("length" / Int16ub))

Extension = "Extension" / Struct(
    "type" / Int16ub,
    Embedded(
        Switch(lambda ctx: ctx.type, {
            0x00: SNIExtension,
            0x10: ALPNExtension,
        },
               default=UnknownExtension)))

extensions = "extensions" / Optional(
    Struct(Int16ub, "extensions" / GreedyRange(Extension)))

ClientHello = "ClientHello" / Struct(
    ProtocolVersion,
    Random,
    SessionID,
    CipherSuites,
    CompressionMethods,
    extensions,
)

ServerHello = "ServerHello" / Struct(
    ProtocolVersion,
    Random,
    SessionID,
    "cipher_suite" / Bytes(2),
예제 #7
0
    Single[(this.chunk_length -
            (this.title_length * 2) - 2 - 4 - 2) / Single.sizeof()],
    "swatch_type_index" / Short,  # Two bytes
)

end_palette = Struct(
    "chunk_type" / Const(b"\xc0\x02"),
    "chunk_length" / Int,
)

palette = Struct(
    "chunk_type" / Const(b"\xc0\x01"),
    "chunk_length" / Int,
    "title_length" / Short,
    "title" / String(this.title_length * 2, encoding="utf-16be"),
    "colors" / color[1:],
    "_end" / end_palette,
)

header = Struct(
    "datatype" / Const(b"ASEF"),
    "major_version" / Short,
    "minor_version" / Short,
    "bugfix_version" / Short,
    "chunk_count" / Short,
)

ase_file = Struct(
    "header" / header, "data" /
    Union(0, "palette" / Optional(palette), "colors" / Optional(color[1:])))
예제 #8
0
파일: packets.py 프로젝트: mik3y/pymidi
class Struct(BaseStruct):
    """Adds `create()`, a friendlier `build()` method."""

    def create(self, **kwargs):
        return self.build(kwargs)


AppleMIDIExchangePacket = Struct(
    '_name' / Computed('AppleMIDIExchangePacket'),
    'preamble' / Const(b'\xff\xff'),
    'command' / Bytes(2),
    'protocol_version' / Int32ub,
    'initiator_token' / Int32ub,
    'ssrc' / Int32ub,
    'name' / Optional(CString('utf8')),
)

AppleMIDITimestampPacket = Struct(
    '_name' / Computed('AppleMIDITimestampPacket'),
    'preamble' / Const(b'\xff\xff'),
    'command' / Bytes(2),
    'ssrc' / Int32ub,
    'count' / Int8ub,
    'padding' / Padding(3),
    'timestamp_1' / Int64ub,
    'timestamp_2' / Int64ub,
    'timestamp_3' / Int64ub,
)

MIDIPacketHeaderFlags = Bitwise(
예제 #9
0
class DeviceSerialAdapter(Adapter):
    """ Adapter to decode the device serial number. """
    def _decode(self, obj, context, path):
        return bytearray(n - 0x30 for n in obj).decode()


Status = "Status" / Struct(
    "cmd" / Const(PROP_INFO_RETURN, Int8ub),
    Const(0x01, Int8ub),
    "mode" / ModeFlags,
    "valve" / Int8ub,
    Const(0x04, Int8ub),
    "target_temp" / TempAdapter(Int8ub),
    "away" / IfThenElse(lambda ctx: ctx.mode.AWAY, AwayDataAdapter(Bytes(4)),
                        Optional(Bytes(4))),
    "presets" / Optional(
        Struct(
            "window_open_temp" / TempAdapter(Int8ub),
            "window_open_time" / WindowOpenTimeAdapter(Int8ub),
            "comfort_temp" / TempAdapter(Int8ub),
            "eco_temp" / TempAdapter(Int8ub),
            "offset" / TempOffsetAdapter(Int8ub),
        )),
)

Schedule = "Schedule" / Struct(
    "cmd" / Enum(Int8ub, **NAME_TO_CMD),
    "day" / Enum(Int8ub, **NAME_TO_DAY),
    "base_temp" / TempAdapter(Int8ub),
    "next_change_at" / TimeAdapter(Int8ub),
예제 #10
0
    # The length above is actually the _flash_end symbol from startup_user.s
    # it includes the offset into 0x90000000 (external flash)
    # we mask out the highest nibble to correct this into the actual bin length
    # plus subtract 20 bytes for header, symbol and length dwords
    'bin' / Bytes((this.length & 0x0FFFFFFF) - 20)
)

struct_blit_relo = Struct(
    'header' / Const(b'RELO'),
    'relocs' / PrefixedArray(Int32ul, Struct(
        'reloc' / Int32ul
    ))
)

blit_game = Struct(
    'relo' / Optional(struct_blit_relo),
    'bin' / RawCopy(struct_blit_bin),
    'meta' / Optional(struct_blit_meta)
)

blit_game_with_meta = Struct(
    'relo' / Optional(struct_blit_relo),
    'bin' / RawCopy(struct_blit_bin),
    'meta' / struct_blit_meta
)

blit_game_with_meta_and_relo = Struct(
    'relo' / struct_blit_relo,
    'bin' / RawCopy(struct_blit_bin),
    'meta' / struct_blit_meta
)
예제 #11
0
VersionInfo = Struct(
    target_id=Hex(Int32ub),
    se_version=PascalString(Int8ub, "utf-8"),
    _flags_len=Const(b"\x04"),
    flags=FlagsEnum(
        Int32ul,
        recovery_mode=1,
        signed_mcu=2,
        is_onboarded=4,
        trust_issuer=8,
        trust_custom_ca=16,
        hsm_initialized=32,
        pin_validated=128,
    ),
    mcu_version=PascalString(Int8ub, "utf-8"),
    mcu_hash=Optional(Bytes(32)),
)


class AppInfo(object):
    def __init__(
        self,
        name: str,
        flags: int,
        code_data_hash: bytes,
        full_hash: bytes,
        data: bytes = None,
    ):
        self.name = name
        self.flags = flags
        self.code_data_hash = code_data_hash
예제 #12
0
    'header' / Const(b'BLIT'),
    'render' / Int32ul,
    'update' / Int32ul,
    'init' / Int32ul,
    'length' / Int32ul,
    # The length above is actually the _flash_end symbol from startup_user.s
    # it includes the offset into 0x90000000 (external flash)
    # we mask out the highest nibble to correct this into the actual bin length
    # plus subtract 20 bytes for header, symbol and length dwords
    'bin' / Bytes((this.length & 0x0FFFFFFF) - 20))

struct_blit_relo = Struct(
    'header' / Const(b'RELO'),
    'relocs' / PrefixedArray(Int32ul, Struct('reloc' / Int32ul)))

blit_game = Struct('relo' / Optional(struct_blit_relo),
                   'bin' / RawCopy(struct_blit_bin),
                   'meta' / Optional(struct_blit_meta))

blit_game_with_meta = Struct('relo' / Optional(struct_blit_relo),
                             'bin' / RawCopy(struct_blit_bin),
                             'meta' / struct_blit_meta)

blit_game_with_meta_and_relo = Struct('relo' / struct_blit_relo,
                                      'bin' / RawCopy(struct_blit_bin),
                                      'meta' / struct_blit_meta)


def compute_icns_data_length(ctx):
    """Compute the required data length for palette based images.
    We need this computation here so we can use `math.ceil` and
예제 #13
0
UnknownExtension = Struct(
    "", PascalString("bytes", length_field=UBInt16("extensions_length")))

Extension = Struct(
    "Extension", UBInt16("type"),
    Embed(
        Switch("",
               lambda ctx: ctx.type, {
                   0x00: SNIExtension,
                   0x10: ALPNExtension
               },
               default=UnknownExtension)))

extensions = TunnelAdapter(
    Optional(
        PascalString("extensions", length_field=UBInt16("extensions_length"))),
    OptionalGreedyRange(Extension))

ClientHello = Struct(
    "ClientHello",
    ProtocolVersion,
    Random,
    SessionID,
    CipherSuites,
    CompressionMethods,
    extensions,
)

ServerHello = Struct(
    "ServerHello",
    ProtocolVersion,
예제 #14
0
timestamp_t = Struct('seconds' / Int32ul, Bytes(4), 'microseconds' / Int32ul)

syslog_t = Struct(
    Bytes(9),
    'pid' / Int32ul,
    Bytes(42),
    'timestamp' / TimestampAdapter(timestamp_t),
    Bytes(1),
    'level' /
    Enum(Byte, Notice=0, Info=0x01, Debug=0x02, Error=0x10, Fault=0x11),
    Bytes(1),
    Bytes(60),
    'filename' / CString('utf8'),
    'image_name' / CString('utf8'),
    'message' / CString('utf8'),
    'label' / Optional(
        Struct('bundle_id' / CString('utf8'), 'identifier' / CString('utf8'))),
)


class OsTraceService(object):
    SERVICE_NAME = 'com.apple.os_trace_relay'

    def __init__(self, lockdown: LockdownClient):
        self.logger = logging.getLogger(__name__)
        self.lockdown = lockdown
        self.c = self.lockdown.start_service(self.SERVICE_NAME)

    def get_pid_list(self):
        self.c.send_plist({'Request': 'PidList'})

        # ignore first received unknown byte