"seq" / Int32ub,
    "xid" / Int32ub,
    "device" / Bytes(6),
    "iface_id" / Int32ub,
)
CQM_REQUEST.name = "cqm_request"

CQM_ENTRY = Struct("addr" / Bytes(6), "last_rssi_std" / Int8ub,
                   "last_rssi_avg" / Int8ub, "last_packets" / Int32ub,
                   "hist_packets" / Int32ub, "mov_rssi" / Int8ub)
CQM_ENTRY.name = "ucqm_entry"

CQM_RESPONSE = Struct("version" / Int8ub, "type" / Int8ub, "length" / Int32ub,
                      "seq" / Int32ub, "xid" / Int32ub, "device" / Bytes(6),
                      "iface_id" / Int32ub, "nb_entries" / Int16ub,
                      "entries" / Array(lambda ctx: ctx.nb_entries, CQM_ENTRY))
CQM_RESPONSE.name = "cqm_response"


class ChannelQualityMap(EWiFiWorker):
    """WiFi Channel Quality Map Worker

    Parameters:
        every: the polling period in ms (optional, default: 2000)
    """
    def __init__(self, context, service_id, every):

        super().__init__(context=context, service_id=service_id, every=every)

        self.ucqm = {}
        self.ncqm = {}
예제 #2
0
RATES_REQUEST = Struct("rates_request", UBInt8("version"),
                       UBInt8("type"),
                       UBInt16("length"),
                       UBInt32("seq"),
                       UBInt32("module_id"),
                       Bytes("sta", 6))

RATES_RESPONSE = Struct("rates_response", UBInt8("version"),
                        UBInt8("type"),
                        UBInt16("length"),
                        UBInt32("seq"),
                        UBInt32("module_id"),
                        Bytes("wtp", 6),
                        Bytes("sta", 6),
                        UBInt16("nb_entries"),
                        Array(lambda ctx: ctx.nb_entries, RATES_ENTRY))


class LVAPStats(Module):
    """ PacketsCounter object. """

    MODULE_NAME = "lvap_stats"
    REQUIRED = ['module_type', 'worker', 'tenant_id', 'lvap']

    # parameters
    _lvap = None

    # data structure
    rates = {}

    def __eq__(self, other):
예제 #3
0
ADD_SUMMARY = Struct("add_summary", UBInt8("version"), UBInt8("type"),
                     UBInt32("length"), UBInt32("seq"), UBInt32("module_id"),
                     Bytes("addr", 6), Bytes("hwaddr", 6), UBInt8("channel"),
                     UBInt8("band"), SBInt16("limit"), UBInt16("period"))

SUMMARY_ENTRY = Sequence(
    "frames", Bytes("ra", 6), Bytes("ta", 6), UBInt64("tsft"),
    BitStruct("flags", Padding(6), Bit("mcs"), Padding(9)), UBInt16("seq"),
    SBInt8("rssi"), UBInt8("rate"), UBInt8("type"), UBInt8("subtype"),
    UBInt32("length"))

SUMMARY_TRIGGER = Struct("summary", UBInt8("version"), UBInt8("type"),
                         UBInt32("length"), UBInt32("seq"),
                         UBInt32("module_id"), Bytes("wtp", 6),
                         UBInt16("nb_entries"),
                         Array(lambda ctx: ctx.nb_entries, SUMMARY_ENTRY))

DEL_SUMMARY = Struct("del_summary", UBInt8("version"), UBInt8("type"),
                     UBInt32("length"), UBInt32("seq"), UBInt32("module_id"))


class Summary(ModuleScheduled):
    """ Summary object. """

    MODULE_NAME = "summary"
    REQUIRED = ['module_type', 'worker', 'tenant_id', 'block']

    def __init__(self):

        super().__init__()
예제 #4
0
    "research_percent"/Byte
)

society = "society"/Struct(
    "score"/Int16ul,
    "total_wonders"/Byte,
    "total_castles"/Byte,
    "relics_captured"/Byte,
    Padding(1),
    "villager_high"/Int16ul,
)

achievements = "achievements"/Struct(
    "player_name"/String(16, padchar=b'\x00', trimdir='right', encoding='latin1'),
    "total_score"/Int16ul,
    Array(8, "total_scores"/Int16ul),
    "victory"/Flag,
    CivEnum("civilization"/Byte),
    ColorAdapter("color"/Byte),
    "team"/Byte,
    "ally_count"/Byte,
    Padding(1),
    "mvp"/Flag,
    Padding(3),
    "result"/Flag,
    Padding(3),
    military,
    Padding(32),
    economy,
    Padding(16),
    technology,
예제 #5
0
파일: map_info.py 프로젝트: sighalt/aoc-mgz
            Embedded(
                IfThenElse(
                    lambda ctx: ctx.terrain_type == 255,
                    Struct("terrain_type" / Byte, "elevation" / Byte,
                           Padding(1)), Struct("elevation" / Byte))))))

# Map size and terrain.
map_info = "map_info" / Struct(
    "size_x" / Int32ul,
    "size_y" / Int32ul,
    "tile_num" / Computed(lambda ctx: ctx.size_x * ctx.size_y),
    "zone_num" / Int32ul,
    Array(
        lambda ctx: ctx.zone_num,
        Struct(
            IfThenElse(lambda ctx: ctx._._.version == Version.DE,
                       Padding(lambda ctx: 2048 + (ctx._.tile_num * 2)),
                       Padding(lambda ctx: 1275 + ctx._.tile_num)),
            "num_floats" / Int32ul, Padding(lambda ctx: ctx.num_floats * 4),
            Padding(4))),
    "all_visible" / Flag,
    "fog_of_war" / Flag,
    "check" /
    Peek(Struct(Padding(lambda ctx: ctx._.tile_num * 7),
                "val" / Int32ul)),  # DE 12.97 fix
    Array(lambda ctx: ctx.tile_num, tile),
    "num_data" / Int32ul,
    Padding(4),
    Array(lambda ctx: ctx.num_data, Padding(4)),
    Array(
        lambda ctx: ctx.num_data, "couple" /
        Struct("num_obstructions" / Int32ul,
예제 #6
0
    "tx_packets" / Int32ub,
    "tx_bytes" / Int32ub,
)
SLICE_STATS_ENTRY.name = "slice_stats_entry"

WIFI_SLICE_STATS_RESPONSE = Struct(
    "version" / Int8ub,
    "type" / Int8ub,
    "length" / Int32ub,
    "seq" / Int32ub,
    "xid" / Int32ub,
    "device" / Bytes(6),
    "ssid" / Bytes(WIFI_NWID_MAXSIZE + 1),
    "slice_id" / Int8ub,
    "nb_entries" / Int16ub,
    "stats" / Array(lambda ctx: ctx.nb_entries, SLICE_STATS_ENTRY),
)
WIFI_SLICE_STATS_RESPONSE.name = "wifi_slice_stats_response"


class SliceStats(EWiFiApp):
    """WiFi Slice Statistics Primitive.

    This primitive collects the slice statistics.

    Parameters:
        slice_id: the slice to track (optinal, default 0)
        every: the loop period in ms (optional, default 2000ms)

    Example:
        POST /api/v1/projects/52313ecb-9d00-4b7d-b873-b55d3d9ada26/apps
        self.stream_payload = None

    def predict(self):
        return self.ml_model.predict_proba(np.array([
            self.stream_payload,
        ]))


# Test mode flag
__test__ = False

# Socket buffer size
socket_buffer_size = 128 * 1024

# Packet structure
packet = Array(10, Float32n)

# Boards configuration
boards = [
    Board(ip='192.168.43.152',
          port=8888,
          board_ip='192.168.43.25',
          data_set='data/board_0.data'),  # 21 Left p
    Board(ip='192.168.43.152',
          port=8887,
          board_ip='192.168.43.243',
          data_set='data/board_1.data'),  # 29 Right p
    Board(ip='192.168.43.152',
          port=8886,
          board_ip='192.168.43.82',
          data_set='data/board_2.data'),  # 28 Ch
예제 #8
0
from mgz.enums import VictoryEnum, ResourceLevelEnum, AgeEnum, PlayerTypeEnum, DifficultyEnum
from mgz.util import find_save_version

# pylint: disable=invalid-name, bad-continuation

de_string = Struct(Const(b"\x60\x0A"), "length" / Int16ul,
                   "value" / Bytes(lambda ctx: ctx.length))

separator = Const(b"\xa3_\x02\x00")

de = "de" / Struct(
    "version" / Float32l,
    "interval_version" / Int32ul,
    "game_options_version" / Int32ul,
    "dlc_count" / Int32ul,
    "dlc_ids" / Array(lambda ctx: ctx.dlc_count, Int32ul),
    "dataset_ref" / Int32ul,
    "difficulty" / DifficultyEnum(Int32ul),
    "selected_map_id" / Int32ul,
    "resolved_map_id" / Int32ul,
    "reveal_map" / Int32ul,
    Peek("victory_type_id" / Int32ul),
    VictoryEnum("victory_type" / Int32ul),
    Peek("starting_resources_id" / Int32ul),
    ResourceLevelEnum("starting_resources" / Int32ul),
    Peek("starting_age_id" / Int32ul),
    AgeEnum("starting_age" / Int32ul),
    Peek("ending_age_id" / Int32ul),
    AgeEnum("ending_age" / Int32ul),
    "game_type" / Int32ul,
    separator,
예제 #9
0
    2: Struct(
        "zone_status" / ZoneFlags(64)
    ),
    3: Struct(
        "zone_status" / ZoneFlags(32, start_index_from=65),
        "partition_status" / PartitionStatus(Bytes(32)),
    ),
    4: Struct(
        "partition_status" / PartitionStatus(Bytes(16)),
        "_panel_status" / BitStruct(
            "installer_lock_active" / Flag,
            "_free" / Padding(7)
        ),
        "event_pointer" / Int16ub,
        "event_pointer_bus" / Int16ub,
        "_recycle_system" / Array(8, Int8ub),
        "arm_disarm_report_delay_timer" / Int8ub,
        "_free" / Padding(34)
    ),
    5: Struct(
        "_free" / Padding(1),
        "bus-module_trouble" / StatusAdapter(Bytes(63))
    )
}

LiveEvent = Struct("fields" / RawCopy(
    Struct(
        "po" / BitStruct(
            "command" / Const(0xE, Nibble),
            "status" / Struct(
                "reserved" / Flag,
예제 #10
0
WSS_REQUEST.name = "wss_request"

WSS_ENTRY = Struct(
    "slice_id" / Int8ub,
    "ssid" / Bytes(WIFI_NWID_MAXSIZE + 1),
    "deficit_used" / Int32ub,
    "max_queue_length" / Int32ub,
    "tx_packets" / Int32ub,
    "tx_bytes" / Int32ub,
)
WSS_ENTRY.name = "wss_entry"

WSS_RESPONSE = Struct("version" / Int8ub, "type" / Int8ub, "length" / Int32ub,
                      "seq" / Int32ub, "xid" / Int32ub, "device" / Bytes(6),
                      "iface_id" / Int32ub, "nb_entries" / Int16ub,
                      "entries" / Array(lambda ctx: ctx.nb_entries, WSS_ENTRY))
WSS_RESPONSE.name = "wss_response"


class SliceStats(EWorker):
    """WiFi Slice Statistics Worker.

    Parameters:
        service_id: the service id as an UUID (mandatory)
        every: the polling period in ms (optional, default: 2000)
    """
    def __init__(self, service_id, project_id, every):

        super().__init__(service_id=service_id,
                         project_id=project_id,
                         every=every)
예제 #11
0
 "bpm_100" / Int32ul,
 "genre_id" / Int32ul,
 "album_id" / Int32ul,  # album artist is set in album entry
 "artist_id" / Int32ul,
 "id" / Int32ul,  # the rekordbox track id
 "disc_number" / Int16ul,
 "play_count" / Int16ul,
 "year" / Int16ul,
 "sample_depth" / Int16ul,  # not sure
 "duration" / Int16ul,
 "u4" / Int16ul,  # always 41?
 "color_id" / Int8ul,
 "rating" / Int8ul,
 "u5" / Default(Int16ul, 1),  # always 1?
 "u6" / Int16ul,  # alternating 2 or 3
 "str_idx" / Array(21, Int16ul),
 "str_u1" / IndexedPioString(0),  # empty
 "texter" / IndexedPioString(1),
 "str_u2" / IndexedPioString(2),  # thought tracknumber -> wrong!
 "str_u3" / IndexedPioString(
     3
 ),  # strange strings, often zero length, sometimes low binary values 0x01/0x02 as content
 "str_u4" / IndexedPioString(
     4
 ),  # strange strings, often zero length, sometimes low binary values 0x01/0x02 as content
 "message" / IndexedPioString(5),
 "kuvo_public" / IndexedPioString(6),  # "ON" or empty
 "autoload_hotcues" / IndexedPioString(7),  # "ON" or empty
 "str_u5" / IndexedPioString(8),  # 8
 "str_u6" / IndexedPioString(9),  # empty
 "date_added" / IndexedPioString(10),
예제 #12
0
    "size" / Int16ub,
    "count" / Int32ub,
)
COUNTERS_ENTRY.name = "counters_entry"

BIN_COUNTERS_RESPONSE = Struct(
    "version" / Int8ub,
    "type" / Int8ub,
    "length" / Int32ub,
    "seq" / Int32ub,
    "xid" / Int32ub,
    "device" / Bytes(6),
    "sta" / Bytes(6),
    "nb_tx" / Int16ub,
    "nb_rx" / Int16ub,
    "stats" / Array(lambda ctx: ctx.nb_tx + ctx.nb_rx, COUNTERS_ENTRY),
)
BIN_COUNTERS_RESPONSE.name = "bin_counters_response"


class LVAPBinCounter(EWApp):
    """LVAP Bin Counter Primitive.

    This primitive collects the packet counters from the specified LVAP.

    Parameters:
        sta: the LVAP to track as an EtherAddress (mandatory)
        bins: the bins for the measurements (optional, default: [8192])
        every: the loop period in ms (optional, default 2000ms)

    Example:
예제 #13
0
                        RED=1,
                        YELLOW=2,
                        BLACK=3,
                        WHITE=4,
                        GREEN=5,
                        ORANGE=6,
                        PURPLE=7,
                        BROWN=8,
                        GRAY=9),
    "score" / Byte,
    "penalty_shot" / Byte,  # penalty shot counter
    "single_shots" / Short,  # bits represent penalty shot success
    "coach_sequence" / Byte,
    "coach_message" / Bytes(253),
    Renamed("coach", RobotInfo),
    "players" / Array(11, RobotInfo))

GameState = "gamedata" / Struct(
    "header" / Const(Bytes(4), b'RGme'),
    "version" / Const(Short, 12),
    "packet_number" / Byte,
    "players_per_team" / Byte,
    "game_type" / Byte,
    "game_state" / Enum(
        Byte,
        STATE_INITIAL=0,
        # auf startposition gehen
        STATE_READY=1,
        # bereithalten
        STATE_SET=2,
        # spielen
예제 #14
0
파일: replay.py 프로젝트: catorda/aoc-mgz
# Basic information about the recorded game
replay = "replay"/Struct(
    "old_time"/Int32ul,
    "world_time"/Int32ul,
    "old_world_time"/Int32ul,
    "game_speed_id"/Int32ul, # world_time_delta
    "world_time_delta_seconds"/Int32ul,
    "timer"/Float32l,
    "game_speed_float"/Float32l,
    "temp_pause"/Byte,
    "next_object_id"/Int32ul,
    "next_reusable_object_id"/Int32sl,
    "random_seed"/Int32ul,
    "random_seed_2"/Int32ul,
    "rec_player"/Int16ul, # id of the rec owner
    "num_players"/Byte, # including gaia
    "instant_build"/Flag,
    "cheats_enabled"/Flag,
    "game_mode"/Int16ul, # MP or SP?
    "campaign"/Int32ul,
    "campaign_player"/Int32ul,
    "campaign_scenario"/Int32ul,
    "king_campaign"/Int32ul,
    "king_campaign_player"/Byte,
    "king_campaign_scenario"/Byte,
    "player_turn"/Int32ul,
    "player_time_delta"/Array(9, "turn"/Int32ul),
    If(lambda ctx: ctx._.version == 'VER 9.4', Padding(8))
)
예제 #15
0
"""All low level structures used for parsing eddystone packets."""
from construct import Struct, Byte, Switch, Const, OneOf, Int8sl, Array, \
                      Int16ul, Int16ub, Int32ub, GreedyString, GreedyRange

from ..const import EDDYSTONE_UUID, EDDYSTONE_URL_SCHEMES, EDDYSTONE_TLM_UNENCRYPTED, \
                    EDDYSTONE_TLM_ENCRYPTED, EDDYSTONE_UID_FRAME, EDDYSTONE_URL_FRAME, \
                    EDDYSTONE_TLM_FRAME, EDDYSTONE_EID_FRAME, FLAGS_DATA_TYPE, \
                    SERVICE_DATA_TYPE, SERVICE_UUIDS_DATA_TYPE

# pylint: disable=invalid-name

EddystoneUIDFrame = Struct(
    "tx_power" / Int8sl,
    "namespace" / Array(10, Byte),
    "instance" / Array(6, Byte),
    "rfu" / Const(b"\x00\x00")
)

EddystoneURLFrame = Struct(
    "tx_power" / Int8sl,
    "url_scheme" / OneOf(Byte, list(EDDYSTONE_URL_SCHEMES)),
    "url" / GreedyString(encoding="ascii")
)

UnencryptedTLMFrame = Struct(
    "voltage" / Int16ub,
    "temperature" / Int16ul,
    "advertising_count" / Int32ub,
    "seconds_since_boot" / Int32ub,
)
예제 #16
0
파일: de.py 프로젝트: catorda/aoc-mgz
"""Definitive Edition structure."""

from construct import (Struct, Int32ul, Float32l, Array, Padding, Flag, Byte,
                       Int16ul, Bytes, Int32sl, Peek, If)

from mgz.enums import VictoryEnum, ResourceLevelEnum, AgeEnum

# pylint: disable=invalid-name, bad-continuation

de = "de" / Struct(
    "options" / Int32sl, "unk0" / Int32ul, "unk1" / Int32ul, "dlc_count" /
    Int32ul, "dlc_ids" / Array(lambda ctx: ctx.dlc_count, Int32ul), Padding(4),
    "difficulty" / Int32ul, "map_size" / Int32ul, "map_id" / Int32ul,
    "reveal_map" / Int32ul, Peek("victory_type_id" / Int32ul),
    VictoryEnum("victory_type" / Int32ul),
    Peek("starting_resources_id" / Int32ul),
    ResourceLevelEnum("starting_resources" / Int32ul),
    Peek("starting_age_id" / Int32ul), AgeEnum("starting_age" / Int32ul),
    Peek("ending_age_id" / Int32ul), AgeEnum("ending_age" / Int32ul),
    "game_type" / Int32ul, Padding(8), "speed" / Float32l,
    "treaty_length" / Int32ul, "population_limit" / Int32ul,
    "num_players" / Int32ul, "unknown2" / Int32ul, "unknown3" / Int32ul,
    Padding(4), "trade_enabled" / Flag, "team_bonus_disabled" / Flag,
    "random_positions" / Flag, "all_techs" / Flag, "num_starting_units" / Byte,
    "lock_teams" / Flag, "lock_speed" / Flag, "multiplayer" / Flag,
    "cheats" / Flag, "record_game" / Flag, "animals_enabled" / Flag,
    "predators_enabled" / Flag, Padding(6), "players" / Array(
        8,
        Struct("dat_crc" / Bytes(4), "mp_version" / Byte, "color_id" / Int32sl,
               "civ_id" / Int32sl, Padding(23), "profile_id_length" / Int16ul,
               "profile_id" / Bytes(lambda ctx: ctx.profile_id_length),
예제 #17
0
    "player_number"/Int32sl,
    "hd_rm_elo"/If(lambda ctx: find_save_version(ctx) < 25.22, Int32ul),
    "hd_dm_elo"/If(lambda ctx: find_save_version(ctx) < 25.22, Int32ul),
    "prefer_random"/Flag,
    "custom_ai"/Flag,
    If(lambda ctx: find_save_version(ctx) >= 25.06, "handicap"/Bytes(8)),
)

de = "de"/Struct(
    "build"/If(lambda ctx: find_save_version(ctx) >= 25.22, Int32ul),
    "timestamp"/If(lambda ctx: find_save_version(ctx) >= 26.16, Int32ul),
    "version"/Float32l,
    "interval_version"/Int32ul,
    "game_options_version"/Int32ul,
    "dlc_count"/Int32ul,
    "dlc_ids"/Array(lambda ctx: ctx.dlc_count, Int32ul),
    "dataset_ref"/Int32ul,
    Peek("difficulty_id"/Int32ul),
    DifficultyEnum("difficulty"/Int32ul),
    "selected_map_id"/Int32ul,
    "resolved_map_id"/Int32ul,
    "reveal_map"/Int32ul,
    Peek("victory_type_id"/Int32ul),
    VictoryEnum("victory_type"/Int32ul),
    Peek("starting_resources_id"/Int32ul),
    ResourceLevelEnum("starting_resources"/Int32ul),
    "starting_age_id"/Int32ul,
    "starting_age"/AgeEnum(Computed(lambda ctx: ctx.starting_age_id - 2)),
    "ending_age_id"/Int32ul,
    "ending_age"/AgeEnum(Computed(lambda ctx: ctx.ending_age_id - 2)),
    "game_type"/Int32ul,
예제 #18
0
            FilesystemQueryVolumeInformationOperationType,
            FilesystemOperation.SetVolumeInformation.name:
            FilesystemSetVolumeInformationOperationType,
            FilesystemOperation.QueryInformationFile.name:
            FilesystemQueryInformationOperationType,
            FilesystemOperation.SetInformationFile.name:
            FilesystemSetInformationOperationType,
            FilesystemOperation.DirectoryControl.name:
            FilesystemDirectoryControlOperationType,
            FilesystemOperation.PlugAndPlay.name:
            FilesystemPnpOperationType,
            FilesystemOperation.LockUnlockFile.name:
            FilesystemLockUnlockOperationType,
        }, Int8ul) * fix_filesystem_event_operation_name,
    "reserved1" / Int8ul * "!!Unknown field!!",
    "reserved2" / Array(5, PVoid) * "!!Unknown field!!",
    "reserved3" / Bytes(0x16) * "!!Unknown field!!",
    "path_info" / DetailStringInfo,
    "reserved3" / Int16ul,
    "path" / DetailString(lambda this: this.path_info),
    "operation_detail" / Switch(
        lambda ctx: ctx._.operation, {
            FilesysemDirectoryControlOperation.QueryDirectory.name:
            QueryDirectoryDetails
        }, Pass),
    "path" / Computed(
        lambda ctx: ctx.path
    ),  # The path might be changed because of the specific file operation
)

FilesystemDetails = ExprAdapter(
예제 #19
0
from empower.main import RUNTIME

EP_ACT_RRC_MEASUREMENT = 0x05

RRC_REQUEST = Struct("rrc_request", UBInt8("type"), UBInt8("version"),
                     UBInt32("enbid"), UBInt16("cellid"), UBInt32("modid"),
                     UBInt16("length"), UBInt32("seq"), UBInt8("action"),
                     UBInt8("dir"), UBInt8("op"), UBInt8("meas_id"),
                     UBInt16("rnti"), UBInt16("earfcn"), UBInt16("interval"),
                     UBInt16("max_cells"), UBInt16("max_meas"))

RRC_ENTRY = Struct("rrc_entries", UBInt8("meas_id"), UBInt16("pci"),
                   SBInt16("rsrp"), SBInt16("rsrq"))

RRC_RESPONSE = Struct("rrc_response", UBInt32("nof_meas"),
                      Array(lambda ctx: ctx.nof_meas, RRC_ENTRY))


class RRCMeasurements(ModuleTrigger):
    """ LVAPStats object. """

    MODULE_NAME = "rrc_measurements"
    REQUIRED = ['module_type', 'worker', 'tenant_id', 'imsi', 'measurements']

    def __init__(self):

        super().__init__()

        # parameters
        self._imsi = None
        self._measurements = {}
예제 #20
0
class BSAArchive(BaseArchive):
    """Archive type for BSA files.

    BSA stands for "Bethesda ? Archive".
    These archives are compressed meshes, textures and other static resources that can
    be loaded as a single file instead of a directory of files (loose files).

    There are currently 4 versions of BSA:
        - ???: Morrowind
        - 103: Oblivion
        - 104: Fallout 3, Fallout: New Vegas, and Skyrim
        - 105: Skyrim: Special Edition

    Note:
        BSA archives to not read the file data on initialization.
        Header's, records and names are read in and files are built during
        :func:`~BSAArchive.iter_files`.

    **Credit:**
        - `BAE <https://github.com/jonwd7/bae>`_
    """

    SIZE_MASK = 0x3fffffff
    COMPRESSED_MASK = 0xc0000000

    header_struct = Struct(
        "magic" / Bytes(4),
        "version" / Int32ul,
        "directory_offset" / Int32ul,
        "archive_flags" / FlagsEnum(
            Int32ul,
            directories_named=0x001,
            files_named=0x002,
            files_compressed=0x004,
            _unknown_0=0x008,
            _unknown_1=0x010,
            _unknown_2=0x020,
            xbox360_archive=0x040,
            files_prefixed=0x100,
            _unknown_4=0x200,
            _unknown_5=0x400,
        ),
        "directory_count" / Int32ul,
        "file_count" / Int32ul,
        "directory_names_length" / Int32ul,
        "file_names_length" / Int32ul,
        "file_flags" / FlagsEnum(
            Int32ul,
            nif=0x001,
            dds=0x002,
            xml=0x004,
            wav=0x008,
            mp3=0x010,
            txt=0x020,
            html=0x020,
            bat=0x020,
            scc=0x020,
            spt=0x040,
            tex=0x080,
            fnt=0x080,
            ctl=0x100,
        ),
    )
    """The structure of BSA headers.

    Returns:
        :class:`~construct.core.Struct`: The structure of BSA headers
    """

    directory_record_struct = Struct(
        "hash" / Int64ul,
        "file_count" / Int32ul,
        "_unknown_0" / If(lambda this: this._.header.version >= 105, Int32ul),
        "name_offset" / IfThenElse(lambda this: this._.header.version >= 105,
                                   Int64ul, Int32ul),
    )
    """The structure of directory records.

    Returns:
        :class:`~construct.core.Struct`: The structure of directory records
    """

    file_record_struct = Struct("hash" / Int64ul, "size" / Int32ul,
                                "offset" / Int32ul)
    """The structure of file records.

    Returns:
        :class:`~construct.core.Struct`: The structure of file records
    """

    directory_block_struct = Struct(
        "name" / If(
            lambda this: this._.header.archive_flags.directories_named,
            PascalString(VarInt, "utf8"),
        ),
        "file_records" / Array(
            lambda this: this._.directory_records[this._._index].file_count,
            file_record_struct,
        ),
    )
    """The structure of directory blocks.

    Returns:
        :class:`~construct.core.Struct`: The structure of directory blocks
    """

    archive_struct = Struct(
        "header" / header_struct,
        "directory_records" / Array(lambda this: this.header.directory_count,
                                    directory_record_struct),
        "directory_blocks" / Array(lambda this: this.header.directory_count,
                                   directory_block_struct),
        "file_names" / If(
            lambda this: this.header.archive_flags.files_named,
            Array(lambda this: this.header.file_count, CString("utf8")),
        ),
    )
    """The **partial** structure of BSA archives.

    Return:
        :class:`~construct.core.Struct`: The **partial** structure of BSA archives
    """
    @property
    def uncompressed_file_struct(self) -> Struct:
        """The uncompressed file structure for uncompressed files.

        Returns:
            :class:`~construct.core.Struct`: The uncompressed file structure for
            uncompressed files.
        """
        return Struct("data" / GreedyBytes)

    @property
    def compressed_file_struct(self) -> Struct:
        """The compressed file structure for compressed files.

        Returns:
            :class:`~construct.core.Struct`: The compressed file structure for
            compressed files.
        """
        return Struct(
            "original_size" / Int32ul,
            "data" / IfThenElse(
                self.container.header.version >= 105,
                LZ4CompressedAdapter(GreedyBytes),
                Compressed(GreedyBytes, "zlib"),
            ),
        )

    @classmethod
    def can_handle(cls, filepath: str) -> bool:
        """Determines if a given file can be handled by the current archive.

        Args:
            filepath (str): The filepath to check if can be handled
        """

        header = cls.header_struct.parse_file(filepath)
        return header.magic == b"BSA\x00" and header.version in (103, 104, 105)

    def iter_files(self) -> Generator[ArchiveFile, None, None]:
        """Iterates over the parsed data and yields instances of :class:`.ArchiveFile`.

        Yields:
            :class:`.ArchiveFile`: An file contained within the archive
        """

        file_index = 0
        file_struct = self.uncompressed_file_struct
        if self.container.header.archive_flags.files_compressed:
            file_struct = self.compressed_file_struct

        for directory_block in self.container.directory_blocks:
            # get directory path from directory block
            directory_path = PureWindowsPath(directory_block.name[:-1])
            for file_record in directory_block.file_records:
                # choose the compressed file structure if compressed mask is set
                if file_record.size > 0 and (
                        self.container.header.archive_flags.files_compressed !=
                        bool(file_record.size & self.COMPRESSED_MASK)):
                    file_struct = self.compressed_file_struct

                file_container = file_struct.parse(
                    self.content[file_record.offset:(
                        file_record.offset +
                        (file_record.size & self.SIZE_MASK))])

                yield ArchiveFile(
                    filepath=directory_path.joinpath(
                        self.container.file_names[file_index]),
                    data=file_container.data,
                )

                file_index += 1
예제 #21
0
__license__ = "GPL3"
__email__ = "code at mheistermann.de"

import construct as c
from construct import Struct, Magic, ULInt32, Padding, Aligned
from construct import Pointer, Array, MetaArray, String
from construct import Field, StaticField, OnDemand, Bytes
from construct import Adapter, Value

burnhdr1 = Struct(
    "burnhdr1",
    Magic(b"SUNP BURN HDR 1"),
    Padding(1, strict=True),
    Array(
        9,
        Bytes(
            "unk", 16
        )  # mostly only first 4 bytes used, exception 12 bytes at [burnhdr+0x74], e.g. behind unk[6]
    ))


def _xor(s, key=0x7A):
    return bytes((x ^ key) for x in s)


class XorObfuscation(Adapter):
    def _encode(self, obj, ctx):
        return _xor(obj)

    def _decode(self, obj, ctx):
        return _xor(obj)
예제 #22
0
 def __init__(self, filepath):
     self.filepath = Path(filepath)
     if not self.filepath.exists():
         raise FileNotFoundError(self.filepath)
     self.header_structure = Struct(
         'magic' / PaddedString(12, 'ascii'),
         'version' / Int32un,
         'unknown' / Array(10, Int16un)
     )
     self.main_directory_structure = Struct(
         'magic' / PaddedString(12, 'ascii'),
         'version' / Int32un,
         'unknown' / Array(10, Int16un),
         'num_entries' / Int32un,
         'current' / Int32un,
         'prev' / Int32un,
         'unknown3' / Int32un,
     )
     self.sub_directory_structure = Struct(
         'pos' / Int32un,
         'start' / Int32un,
         'size' / Int32un,
         'unknown' / Int32un,
         'patient_id' / Int32un,
         'study_id' / Int32un,
         'series_id' / Int32un,
         'slice_id' / Int32sn,
         'unknown2' / Int16un,
         'unknown3' / Int16un,
         'type' / Int32un,
         'unknown4' / Int32un,
     )
     self.chunk_structure = Struct(
         'magic' / PaddedString(12, 'ascii'),
         'unknown' / Int32un,
         'unknown2' / Int32un,
         'pos' / Int32un,
         'size' / Int32un,
         'unknown3' / Int32un,
         'patient_id' / Int32un,
         'study_id' / Int32un,
         'series_id' / Int32un,
         'slice_id' / Int32sn,
         'ind' / Int16un,
         'unknown4' / Int16un,
         'type' / Int32un,
         'unknown5' / Int32un,
     )
     self.patient_info_structure = Struct(
         'name' / PaddedString(31, 'ascii'),
         'surname' / PaddedString(66, 'ascii'),
         'birthdate' / Int32un,
         'sex' / Int8un
     )
     self.lat_structure = Struct(
         # 'unknown' / Int8un,
         'unknown' / PaddedString(14, 'ascii'),
         # 'unknown' / Array(16, Int16un),
         'laterality' / Int8un,
         'unknown2' / Int8un
     )
     self.image_structure = Struct(
         'size' / Int32un,
         'type' / Int32un,
         'unknown' / Int32un,
         'width' / Int32un,
         'height' / Int32un,
     )
예제 #23
0
"""Initial."""

# pylint: disable=invalid-name,no-name-in-module

from construct import (Array, Byte, Embedded, Flag, Float32l, If, Int16ul, Int32sl,
                       Int32ul, Padding, Struct, Tell, this, Bytes)

from mgz.enums import MyDiplomacyEnum, TheirDiplomacyEnum
from mgz.header.objects import existing_object
from mgz.header.playerstats import player_stats
from mgz.util import Find, GotoObjectsEnd, RepeatUpTo

# Player attributes.
attributes = "attributes"/Struct(
    Array(lambda ctx: ctx._._._.replay.num_players, TheirDiplomacyEnum("their_diplomacy"/Byte)),
    Array(9, MyDiplomacyEnum("my_diplomacy"/Int32sl)),
    "allied_los"/Int32ul,
    "allied_victory"/Flag,
    "player_name_length"/Int16ul,
    "player_name"/Bytes(this.player_name_length - 1),
    Padding(1), # 0x00
    Padding(1), # 0x16
    "num_header_data"/Int32ul,
    Padding(1), # 0x21
    player_stats,
    Padding(1),
    "camera_x"/Float32l,
    "camera_y"/Float32l,
    "end_of_camera"/Tell,
    "num_saved_views"/Int32sl,
    # present in resumed games
예제 #24
0
        "zone_open" / StatusAdapter(Bytes(12)),
        "zone_tamper" / StatusAdapter(Bytes(12)),
        "zone_low_battery" / StatusAdapter(Bytes(12))),
    2:
    Struct("zone_status" / ZoneFlags(64)),
    3:
    Struct(
        "zone_status" / ZoneFlags(32, start_index_from=65),
        "partition_status" / PartitionStatus(Bytes(32)),
    ),
    4:
    Struct(
        "partition_status" / PartitionStatus(Bytes(16)), "_panel_status" /
        BitStruct("installer_lock_active" / Flag, "_free" / Padding(7)),
        "event_pointer" / Int16ub, "event_pointer_bus" / Int16ub,
        "_recycle_system" / Array(8, Int8ub),
        "arm_disarm_report_delay_timer" / Int8ub, "_free" / Padding(34)),
    5:
    Struct("_free" / Padding(1),
           "bus-module_trouble" / StatusAdapter(Bytes(63)))
}

LiveEvent = Struct(
    "fields" / RawCopy(
        Struct(
            "po" / BitStruct(
                "command" / Const(0xE, Nibble), "status" /
                Struct("reserved" / Flag, "alarm_reporting_pending" / Flag,
                       "Winload_connected" / Flag, "NeWare_connected" / Flag)),
            "event_source" / Const(0xFF, Int8ub),
            "event_nr" / Int16ub,
예제 #25
0
        return self.send("get_indicatorLamp")


class ProntoPulseAdapter(Adapter):
    def _decode(self, obj, context, path):
        return int(obj * context._.modulation_period)

    def _encode(self, obj, context, path):
        raise RuntimeError("Not implemented")


ChuangmiIrSignal = Struct(
    Const(0xA567, Int16ul),
    "edge_count" / Rebuild(Int16ul,
                           len_(this.edge_pairs) * 2 - 1),
    "times_index" / Array(16, Int32ul),
    "edge_pairs" / Array(
        (this.edge_count + 1) // 2,
        BitStruct("gap" / BitsInteger(4), "pulse" / BitsInteger(4)),
    ),
)

ProntoBurstPair = Struct("pulse" / ProntoPulseAdapter(Int16ub),
                         "gap" / ProntoPulseAdapter(Int16ub))

Pronto = Struct(
    Const(0, Int16ub),
    "_ticks" / Int16ub,
    "modulation_period" / Computed(this._ticks * 0.241246),
    "frequency" / Computed(1000000 / this.modulation_period),
    "intro_len" / Int16ub,
예제 #26
0
        return play_method(command, *command_args)


class ProntoPulseAdapter(Adapter):
    def _decode(self, obj, context):
        return int(obj * context._.modulation_period)

    def _encode(self, obj, context):
        raise RuntimeError('Not implemented')


ChuangmiIrSignal = Struct(
    Const(0xa567,
          Int16ul), 'edge_count' / Rebuild(Int16ul,
                                           len_(this.edge_pairs) * 2 - 1),
    'times_index' / Array(16, Int32ul), 'edge_pairs' / Array(
        (this.edge_count + 1) // 2,
        BitStruct(
            'gap' / BitsInteger(4),
            'pulse' / BitsInteger(4),
        )))

ProntoBurstPair = Struct(
    'pulse' / ProntoPulseAdapter(Int16ub),
    'gap' / ProntoPulseAdapter(Int16ub),
)

Pronto = Struct(
    Const(0, Int16ub),
    '_ticks' / Int16ub,
    'modulation_period' / Computed(this._ticks * 0.241246),
예제 #27
0
    def __init__(self, elf_structs, data):

        self.ehdr = elf_structs.Elf_ehdr.parse(data)
        self.phdr_table = Array(self.ehdr.e_phnum, elf_structs.Elf_phdr).parse(
            data[self.ehdr.e_phoff:])
예제 #28
0
# based in part of:
# https://github.com/brunchboy/dysentery
# https://bitbucket.org/awwright/libpdjl

from construct import Adapter, Array, Byte, Const, CString, Default, Embedded, Enum, ExprAdapter, FlagsEnum, FocusedSeq, GreedyBytes, GreedyRange, Int8ub, Int16ub, Int32ub, Int64ub, Int16ul, Int32ul, Padded, Padding, Pass, PascalString, Prefixed, Rebuild, String, Struct, Subconstruct, Switch, this, len_

MacAddr = Array(6, Byte)
IpAddr = Array(4, Byte)


class IpAddrAdapter(Adapter):
    def _encode(self, obj, context):
        return list(map(int, obj.split(".")))

    def _decode(self, obj, context):
        return ".".join("{}".format(x) for x in obj)


IpAddr = IpAddrAdapter(Byte[4])


class MacAddrAdapter(Adapter):
    def _encode(self, obj, context):
        return list(int(x, 16) for x in obj.split(":"))

    def _decode(self, obj, context):
        return ":".join("{:02x}".format(x) for x in obj)


MacAddr = MacAddrAdapter(Byte[6])
예제 #29
0
from construct import Struct, Const, Int32ul, Array, Padding, Tell
from .pagetype import PageTypeEnum

FileHeaderEntry = Struct(
    "page_type" / PageTypeEnum,
    "empty_candidate" / Int32ul,
    "first_page" /
    Int32ul,  # always points to a strange page, which then links to a real data page
    "last_page" / Int32ul)

FileHeader = Struct(
    Padding(4),  # always 0
    "page_size" / Const(4096, Int32ul),
    "page_entries" / Int32ul,  # FileHeaderEntry follow, usually 20
    "next_unused_page" /
    Int32ul,  # even unreferenced -> not used as any "empty_candidate", points "out of file"
    "unknown1" / Int32ul,  # (5,4,4,1,1,1...)
    "sequence" /
    Int32ul,  # sequence number, always incremented by 1 (sometimes 2/3)
    Padding(4),  # always 0
    "entries" / Array(lambda ctx: ctx.page_entries, FileHeaderEntry),
    "length" / Tell,  # usually 348 when page_entries=20
    Padding(lambda ctx: ctx.page_size - ctx.length))
예제 #30
0
"""All low level structures used for parsing eddystone packets."""
from construct import Struct, Byte, Const, Int8sl, Array, Int16ub

from ..const import IBEACON_COMPANY_ID, IBEACON_PROXIMITY_TPYE

# pylint: disable=invalid-name

IBeaconAdvertisingPacket = Struct(
    "flags" / Const(b"\x02\x01\x06"),
    "length" / Const(b"\x1A"),
    "type" / Const(b"\xFF"),
    "company_id" / Const(IBEACON_COMPANY_ID),
    "beacon_type" / Const(IBEACON_PROXIMITY_TPYE),
    "uuid" / Array(16, Byte),
    "major" / Int16ub,
    "minor" / Int16ub,
    "tx_power" / Int8sl,
)