Ejemplo n.º 1
0
    def _generate_struct_from_headers(
            self, header_tables):  # type: (Container) -> Struct
        """
        Generate ``construct`` Struct for this file
        :param header_tables: contains elf_header, program_headers, section_headers
        :return: Struct of the whole file
        """
        elf_header = header_tables.elf_header
        program_headers = header_tables.program_headers
        section_headers = header_tables.section_headers
        assert program_headers or section_headers

        string_table_sh = None
        load_segment_subcons = []
        note_segment_subcons = []
        # Here we point back to make segments know their program headers
        for i, ph in enumerate(program_headers):
            args = [
                'ph' / Pointer(elf_header.e_phoff + i * ProgramHeader.sizeof(),
                               ProgramHeader),
                'data' / Pointer(ph.p_offset, Bytes(ph.p_filesz)),
            ]
            if ph.p_vaddr == 0 and ph.p_type == self.PT_NOTE:
                args.append('note_secs' / Pointer(ph.p_offset, NoteSections))
                note_segment_subcons.append(Struct(*args))
            elif ph.p_vaddr != 0:
                load_segment_subcons.append(Struct(*args))

        section_subcons = []
        for i, sh in enumerate(section_headers):
            if sh.sh_type == self.SHT_STRTAB and i == elf_header.e_shstrndx:
                string_table_sh = sh
            elif sh.sh_addr != 0 and sh.sh_type == self.SHT_PROGBITS:
                section_subcons.append(
                    Struct(
                        'sh' / Pointer(
                            elf_header.e_shoff + i * SectionHeader.sizeof(),
                            SectionHeader),
                        'data' / Pointer(sh.sh_offset, Bytes(sh.sh_size)),
                    ))

        args = [
            'elf_header' / ElfHeader,
            'load_segments' / Sequence(*load_segment_subcons),
            'note_segments' / Sequence(*note_segment_subcons),
            'sections' / Sequence(*section_subcons),
        ]
        if string_table_sh is not None:
            args.append('string_table' / Pointer(
                string_table_sh.sh_offset, Bytes(string_table_sh.sh_size)))

        return Struct(*args)
Ejemplo n.º 2
0
 def _RangeForm(self, element):
     return Embedded(
         Sequence(
             'MinimumValue' / element,
             'MaximumValue' / element,
             'StepSize' / element,
         ))
Ejemplo n.º 3
0
def PascalUtf16(size_type=Int16ul):
    """Parse a length-defined string in UTF-16."""

    return _Utf16(Sequence(
        size_type,
        Bytes(this[0] * 2),
    ))
Ejemplo n.º 4
0
def DelimitedField(stop):

    return _StripDelimiter(
        Sequence(
            RepeatUntil(
                lambda x, lst, ctx: lst[-len(stop):] == [int(c) for c in stop],
                Byte), Computed(this[0][:-len(stop)]),
            Seek(-len(stop), whence=1)))
Ejemplo n.º 5
0
def AlphaString(name):
    return StringAdapter(
        DoubleAdapter(
            Sequence(
                name,
                UBInt16("length"),
                MetaField("data", lambda ctx: ctx["length"] * 2),
            )),
        encoding="ucs2",
    )
Ejemplo n.º 6
0
class DemoConfigStruct(ConfStructure):
    # The structures of value in the following fields are equal.
    val1 = ConstructorField(code=0x01, constructor=Short)
    val2 = SingleField(code=0x02, format='>H')

    # The structures of value in the following fields are equal.
    ip1 = ConstructorField(code=0x03,
                           constructor=ServerAddressAdapter(Byte[6]))
    ip2 = ConstructorField(code=0x04, constructor=ServerAddressStruct())

    pos1 = ConstructorField(code=0x05, constructor=Sequence(Byte, Byte))
Ejemplo n.º 7
0
def BigInteger(length_field):
	def decode_big(obj, _ctx):
		(_length, isNegative, value) = obj
		ret = sum([d << i*8 for (d, i) in zip(value, range(0, len(value)))])
		if isNegative:
			return -ret
		return ret

	def encode_big(obj, _ctx):
		isNegative = 0
		if obj < 0:
			isNegative = 1
			obj = -obj
		value = []
		while obj > 0:
			value.append(obj & 0xFF)
			obj = obj >> 8
		return (len(value), isNegative, value)

	return ExprAdapter(Sequence("len" / length_field,
		"isNegative" / Int8ub,
		"value" / Array(lambda ctx: ctx.len, Int8ub)),
		encoder=encode_big,
		decoder=decode_big)
Ejemplo n.º 8
0
from empower.core.module import Module
from empower.core.module import ModuleLVAPPWorker

from empower.main import RUNTIME

PT_ADD_SUMMARY = 0x22
PT_SUMMARY = 0x23
PT_DEL_SUMMARY = 0x24

ADD_SUMMARY = Struct("add_summary", UBInt8("version"), UBInt8("type"),
                     UBInt16("length"), UBInt32("seq"), UBInt32("module_id"),
                     Bytes("addrs", 6), Bytes("hwaddr", 6), UBInt8("channel"),
                     UBInt8("band"), SBInt16("limit"), UBInt16("period"))

SUMMARY_ENTRY = Sequence("frames", Bytes("addr", 6), UBInt64("tsft"),
                         UBInt16("seq"), SBInt8("rssi"), UBInt8("rate"),
                         UBInt8("type"), UBInt8("subtype"), UBInt32("length"))

SUMMARY_TRIGGER = Struct("summary", UBInt8("version"), UBInt8("type"),
                         UBInt16("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"),
                     UBInt16("length"), UBInt32("seq"), UBInt32("module_id"))


class Summary(Module):
    """ Summary object. """
Ejemplo n.º 9
0
ConstructResourceDatabase = Struct(
    items=PrefixedArray(Byte, ConstructResourceInfo),
    events=PrefixedArray(Byte, ConstructResourceInfo),
    tricks=PrefixedArray(Byte, ConstructResourceInfo),
    damage=PrefixedArray(Byte, Struct(
        Embedded(ConstructResourceInfo),
        reductions=PrefixedArray(Byte, Struct(
            index=Byte,
            multiplier=Float32b,
        )),
    )),
    versions=PrefixedArray(Byte, ConstructResourceInfo),
    misc=PrefixedArray(Byte, ConstructResourceInfo),
    difficulty=PrefixedArray(Byte, ConstructResourceInfo),
    requirement_template=PrefixedArray(VarInt, Sequence(CString("utf8"), ConstructRequirement))
)

ConstructEchoesBeamConfiguration = Struct(
    item_index=Byte,
    _has_ammo_a=Rebuild(Flag, lambda this: this.ammo_a is not None),
    ammo_a=If(lambda this: this._has_ammo_a, Byte),
    _has_ammo_b=Rebuild(Flag, lambda this: this.ammo_b is not None),
    ammo_b=If(lambda this: this._has_ammo_b, Byte),
    uncharged_cost=Byte,
    charged_cost=Byte,
    combo_missile_cost=Byte,
    combo_ammo_cost=Byte,
)

ConstructEchoesGameSpecific = Struct(
Ejemplo n.º 10
0
from construct import UBInt16
from construct import UBInt32
from construct import Array

from empower.datatypes.etheraddress import EtherAddress
from empower.lvapp.lvappserver import ModuleLVAPPWorker
from empower.core.module import Module
from empower.core.app import EmpowerApp
from empower.lvapp import PT_VERSION

from empower.main import RUNTIME

PT_STATS_REQUEST = 0x17
PT_STATS_RESPONSE = 0x18

STATS = Sequence("stats", UBInt16("bytes"), UBInt32("count"))

STATS_REQUEST = Struct("stats_request", UBInt8("version"), UBInt8("type"),
                       UBInt32("length"), UBInt32("seq"), UBInt32("module_id"),
                       Bytes("sta", 6))

STATS_RESPONSE = \
    Struct("stats_response", UBInt8("version"),
           UBInt8("type"),
           UBInt32("length"),
           UBInt32("seq"),
           UBInt32("module_id"),
           Bytes("wtp", 6),
           Bytes("sta", 6),
           UBInt16("nb_tx"),
           UBInt16("nb_rx"),
Ejemplo n.º 11
0
from construct import Array

from empower.lvapp import PT_VERSION
from empower.datatypes.etheraddress import EtherAddress
from empower.lvapp.lvappserver import LVAPPServer
from empower.datatypes.etheraddress import EtherAddress
from empower.lvapp.lvappserver import ModuleLVAPPWorker
from empower.core.module import Module
from empower.core.app import EmpowerApp

from empower.main import RUNTIME

PT_CQM_LINKS_REQUEST = 0x43
PT_CQM_LINKS_RESPONSE = 0x44

CQM_LINK = Sequence("stats", Bytes("ta", 6), UBInt32("p_pdf"),
                    UBInt32("p_available_bw"))

CQM_LINKS_REQUEST = Struct("stats_request", UBInt8("version"), UBInt8("type"),
                           UBInt32("length"), UBInt32("seq"),
                           UBInt32("module_id"))

CQM_LINKS_RESPONSE = \
    Struct("stats_response", UBInt8("version"),
           UBInt8("type"),
           UBInt32("length"),
           UBInt32("seq"),
           UBInt32("module_id"),
           Bytes("wtp", 6),
           UBInt16("nb_links"),
           Array(lambda ctx: ctx.nb_links, CQM_LINK))
Ejemplo n.º 12
0
              Bit("authenticated")), UBInt16("assoc_id"), Bytes("hwaddr", 6),
    UBInt8("channel"), UBInt8("band"), Bytes("sta", 6), Bytes("encap", 6),
    Bytes("net_bssid", 6), Bytes("lvap_bssid", 6), SSIDS)

DEL_LVAP = Struct("del_lvap", UBInt8("version"), UBInt8("type"),
                  UBInt16("length"), UBInt32("seq"), Bytes("sta", 6))

STATUS_LVAP = Struct(
    "status_lvap", UBInt8("version"), UBInt8("type"), UBInt16("length"),
    UBInt32("seq"),
    BitStruct("flags", Padding(13), Bit("set_mask"), Bit("associated"),
              Bit("authenticated")), UBInt16("assoc_id"), Bytes("wtp", 6),
    Bytes("sta", 6), Bytes("encap", 6), Bytes("hwaddr", 6), UBInt8("channel"),
    UBInt8("band"), Bytes("net_bssid", 6), Bytes("lvap_bssid", 6), SSIDS)

CAPS_R = Sequence("blocks", Bytes("hwaddr", 6), UBInt8("channel"),
                  UBInt8("band"), BitStruct("flags", Padding(16)))

CAPS_P = Sequence("ports", Bytes("hwaddr", 6), UBInt16("port_id"),
                  Bytes("iface", 10))

CAPS = Struct("caps", UBInt8("version"), UBInt8("type"), UBInt16("length"),
              UBInt32("seq"), Bytes("wtp", 6), UBInt8("nb_resources_elements"),
              UBInt8("nb_ports_elements"),
              Array(lambda ctx: ctx.nb_resources_elements, CAPS_R),
              Array(lambda ctx: ctx.nb_ports_elements, CAPS_P))

SET_PORT = Struct("set_port", UBInt8("version"), UBInt8("type"),
                  UBInt16("length"), UBInt32("seq"),
                  BitStruct("flags", Padding(15), Bit("no_ack")),
                  Bytes("hwaddr", 6), UBInt8("channel"), UBInt8("band"),
                  Bytes("sta", 6), UBInt16("rts_cts"), UBInt8("tx_mcast"),
Ejemplo n.º 13
0
from construct import Bit

from empower.core.resourcepool import BT_L20
from empower.core.app import EmpowerApp
from empower.datatypes.etheraddress import EtherAddress
from empower.lvapp.lvappserver import ModuleLVAPPWorker
from empower.core.module import ModulePeriodic
from empower.lvapp import PT_VERSION

from empower.main import RUNTIME

PT_RATES_REQUEST = 0x30
PT_RATES_RESPONSE = 0x31

RATES_ENTRY = Sequence("rates", UBInt8("rate"),
                       BitStruct("flags", Padding(6), Bit("mcs"), Padding(9)),
                       UBInt32("prob"), UBInt32("cur_prob"))

RATES_REQUEST = Struct("rates_request", UBInt8("version"), UBInt8("type"),
                       UBInt32("length"), UBInt32("seq"), UBInt32("module_id"),
                       Bytes("sta", 6))

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


class LVAPStats(ModulePeriodic):
    """ LVAPStats object. """
Ejemplo n.º 14
0
Footer = Struct(
    Const(b'\xf7'),                 # SysEx End
)

Header_Mk2 = Struct(
    'mk2' / Computed(True),

    Const(b'\xf0'),                 # SysEx Begin
    Const(b'\x47\x00'),             # Mfg ID = Akai
    Const(b'\x26'),                 # Dev ID = MPK Mk2
    Const(b'\x64'),                 # CMD = Dump (67) / Load (64) Preset
    Const(b'\x00\x6d'),             # Len = 109bytes (7bit stuffed)

    Embedded(General),              # Note: different order to Mk1
    Embedded(Arpeggio_enable),
    Embedded(Arpeggio_mode),
    Embedded(Arpeggio_div),
    Embedded(Arpeggio_clk),
    Embedded(Arpeggio),
    Embedded(Joy),
)

MPK_MINI_MK2 = Sequence(
    Header_Mk2,
    Array(_PBANKS, Array(_PADS, Pad,)),
    Array(_DBANKS, Array(_DIALS, Dial,)),
    Transpose,
    Footer,
)
Ejemplo n.º 15
0
    pattern = re.compile("<START>.*?<END>")
    total_lines = get_total_lines(str(base_file_location / 'formatted.txt'))
    db_train = {}
    db_test = {}

    with open(str(base_file_location / 'formatted.txt'), 'r',
              encoding='utf-8') as file:
        index = 0  # cheap tricks to store correct and changed sentence one after the other
        start_from_pos = 0  # while ensuring there is a 80-20 train-test split.

        for i, line in tqdm(enumerate(file)):
            sample = None
            if i % 2 == 0:
                sample = Grammar(line)
            else:
                sample = Sequence(line)

            if min_length_qualify(sample.correct):
                sample.make_change()

                correct, changed = sample.correct, sample.changed
                correct_label, changed_label = labelify(
                    correct, changed, i, sample.change_type)

                a = Type1Label(correct, correct_label, convert_to_max=True)
                # a.pretty_print()
                b = Type1Label(changed, changed_label, convert_to_max=True)
                # b.pretty_print()

                if index < int(0.4 * total_lines):
                    db_test[index] = a.store_dict()
Ejemplo n.º 16
0
TileIdEntry = Struct(
    "type" / PascalString(Int8ul, "latin-1"),
    "names" / PrefixedArray(
        Int8ul,
        Struct(
            "name" / PascalString(Int8ul, "latin-1"),
            "id" / Int8ul,
        )),
)

achievement_types = {
    'achievement': Computed(lambda this: "no-data"),
    'build-entity-achievement': Int32ul,
    'combat-robot-count': Int32ul,
    'construct-with-robots-achievement': Sequence(Int32ul, Int32ul),
    'deconstruct-with-robots-achievement': Int32ul,
    'deliver-by-robots-achievement': Float64l,
    'dont-build-entity-achievement': Int32ul,
    #'dont-craft-manually-achievement': Unknown
    'dont-use-entity-in-energy-production-achievement': Float64l,
    'finish-the-game-achievement': Int32ul,
    'group-attack-achievement': Int32ul,
    'kill-achievement': Float64l,
    'player-damaged-achievement': Sequence(Float32l, Int8ul),
    'produce-achievement': Float64l,
    'produce-per-hour-achievement': Float64l,
    'research-achievement': Computed(lambda this: "no-data"),
    'train-path-achievement': Float64l,
}
Ejemplo n.º 17
0
from construct import Array

from empower.core.lvap import LVAP
from empower.datatypes.etheraddress import EtherAddress
from empower.core.module import ModuleLVAPPWorker
from empower.core.module import Module
from empower.lvapp import PT_VERSION

from empower.main import RUNTIME


PT_RATES_REQUEST = 0x29
PT_RATES_RESPONSE = 0x30

RATES_ENTRY = Sequence("rates",
                       UBInt8("rate"),
                       UBInt8("prob"))


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"),
Ejemplo n.º 18
0
# but len(entry_enabled)==16 while len(revidx)<=16

FirstReverseIndexArray = Struct(
  "entries" / Array(this._._.entry_count%16, ReverseIndexedEntry),
  "entry_enabled" / ByteSwapped(Bitwise(Array(16, Flag))), # may start with unexistant entries, see above!
  "entry_enabled_override" / ByteSwapped(Bitwise(Array(16, Flag))) # may start with unexistant entries, see above!
)

FullReverseIndexArray = Struct(
  "entries" / Array(16, ReverseIndexedEntry),
  "entry_enabled" / ByteSwapped(Bitwise(Array(16, Flag))),
  "entry_enabled_override" / ByteSwapped(Bitwise(Array(16, Flag)))
)

PageEndHeader = Sequence(
  FirstReverseIndexArray,
  Embedded(Array(this._.entry_count//16, FullReverseIndexArray))
)

PageHeader = Struct( # 40 bytes
  Padding(4), # always 0
  "index" / Int32ul, # in units of 4096 bytes
  "page_type" / PageTypeEnum,
  "next_index" / Int32ul, # in units of 4096 bytes, finally points to empty page, even outside of file
  "u1" / Int32ul, # sequence number (0->1: 8->13, 1->2: 22, 2->3: 27)
  Padding(4),
  "real_entry_count" / Int8ul,
  "u3" / Int8ul, # a bitmask (1st track: 32)
  "u4" / Int16ul, # 25600 for strange blocks
  "free_size" / Int16ul, # excluding data at page end
  "payload_size" / Int16ul,
  "u7" / Int16ul, # (0->1: 2)
Ejemplo n.º 19
0
from empower.core.resourcepool import BT_L20
from empower.core.app import EmpowerApp
from empower.datatypes.etheraddress import EtherAddress
from empower.lvapp.lvappserver import ModuleLVAPPWorker
from empower.core.module import ModulePeriodic
from empower.lvapp import PT_VERSION

from empower.main import RUNTIME

PT_NIF_REQUEST = 0x90
PT_NIF_RESPONSE = 0x91

NIF_STATS_ENTRY = Sequence(
    "rates", UBInt8("rate"),
    BitStruct("flags", Padding(6), Bit("mcs"), Padding(9)), UBInt32("prob"),
    UBInt32("cur_prob"), UBInt64("hist_successes"), UBInt64("hist_attempts"),
    UBInt32("last_successes"), UBInt32("last_attempts"),
    UBInt64("last_acked_bytes"), UBInt64("hist_acked_bytes"))

NIF_STATS_REQUEST = Struct("nif_request", UBInt8("version"), UBInt8("type"),
                           UBInt32("length"), UBInt32("seq"),
                           UBInt32("module_id"), Bytes("sta", 6))

NIF_STATS_RESPONSE = Struct("nif_response", UBInt8("version"), UBInt8("type"),
                            UBInt32("length"), UBInt32("seq"),
                            UBInt32("module_id"), Bytes("wtp", 6),
                            UBInt16("nb_entries"),
                            Array(lambda ctx: ctx.nb_entries, NIF_STATS_ENTRY))


class NIFStats(ModulePeriodic):
Ejemplo n.º 20
0
from empower.lvapp import PT_VERSION
from empower.datatypes.etheraddress import EtherAddress
from empower.lvapp.lvappserver import LVAPPServer
from empower.datatypes.etheraddress import EtherAddress
from empower.lvapp.lvappserver import ModuleLVAPPWorker
from empower.core.module import Module
from empower.core.app import EmpowerApp

from empower.main import RUNTIME

PT_CQM_LINKS_REQUEST = 0x43
PT_CQM_LINKS_RESPONSE = 0x44

CQM_LINK = Sequence("stats", Bytes("ta",
                                   6), UBInt32("p_channel_busy_fraction"),
                    UBInt32("p_throughput"), UBInt32("p_available_bw"),
                    UBInt32("p_pdf"), UBInt32("p_attainable_throughput"))

CQM_LINKS_REQUEST = Struct("stats_request", UBInt8("version"), UBInt8("type"),
                           UBInt32("length"), UBInt32("seq"),
                           UBInt32("module_id"))

CQM_LINKS_RESPONSE = \
    Struct("stats_response", UBInt8("version"),
           UBInt8("type"),
           UBInt32("length"),
           UBInt32("seq"),
           UBInt32("module_id"),
           Bytes("wtp", 6),
           UBInt16("nb_links"),
           Array(lambda ctx: ctx.nb_links, CQM_LINK))
Ejemplo n.º 21
0
)

anchor = Struct(
    Const(b"\xff" * 4),
    "akttab" / blockref,
    "clorX" / blockref,
    Const(b"\xff" * 4 * 3),
    "taskRoot" / blockref,
    Const(b"\xff" * 4),
) * "System anchor block"

assert pagesize // blockref.sizeof() == 128
blockTable = Array(pagesize // blockref.sizeof(), blockref)

# XXX: skip const
segmentTable = Sequence(Const(2 * blockref.sizeof() * b'\xff'),
                        Array(14, blockref))

drinfo = Struct(
    "count" / blockref * "Number of blocks/pages allocated",
    "blocks" / Array(3, blockref) *
    "Direct block references for page 1, 2 and 3",
    "blockTables" / Array(2, blockref) * "Block references to block tables",
    "segmentTables" / Array(2, blockref) *
    "Block references to segment tables, which refer to block tables",
) * "Dataspace descriptor"

# see src/devel/misc/unknown/src/XSTATUS.ELA
# EUMEL’s pcb function returns the 16 bit word at position (0x1e+2*<id>)%0x40
# i.e. module is pcb(23) → at offset 0x0c
pcb = Struct(
    "wstate" / Int32ul,
Ejemplo n.º 22
0
DEL_LVAP = Struct("del_lvap", UBInt8("version"), UBInt8("type"),
                  UBInt32("length"), UBInt32("seq"), UBInt32("module_id"),
                  Bytes("sta", 6), Bytes("target_hwaddr", 6),
                  UBInt8("target_channel"), UBInt8("tagert_band"),
                  UBInt8("csa_switch_mode"), UBInt8("csa_switch_count"))

STATUS_LVAP = Struct(
    "status_lvap", UBInt8("version"), UBInt8("type"), UBInt32("length"),
    UBInt32("seq"),
    BitStruct("flags", Padding(13), Bit("set_mask"), Bit("associated"),
              Bit("authenticated")), UBInt16("assoc_id"), Bytes("wtp", 6),
    Bytes("sta", 6), Bytes("encap", 6), Bytes("hwaddr", 6), UBInt8("channel"),
    UBInt8("band"), UBInt8("supported_band"), Bytes("net_bssid", 6),
    Bytes("lvap_bssid", 6), SSIDS)

CAPS_R = Sequence("blocks", Bytes("hwaddr", 6), UBInt8("channel"),
                  UBInt8("band"))

CAPS_P = Sequence("ports", Bytes("hwaddr", 6), UBInt16("port_id"),
                  Bytes("iface", 10))

CAPS_RESPONSE = Struct("caps", UBInt8("version"), UBInt8("type"),
                       UBInt32("length"), UBInt32("seq"), Bytes("wtp", 6),
                       UBInt8("nb_resources_elements"),
                       UBInt8("nb_ports_elements"),
                       Array(lambda ctx: ctx.nb_resources_elements, CAPS_R),
                       Array(lambda ctx: ctx.nb_ports_elements, CAPS_P))

CAPS_REQUEST = Struct("caps_request", UBInt8("version"), UBInt8("type"),
                      UBInt32("length"), UBInt32("seq"))

LVAP_STATUS_REQUEST = Struct("lvap_status_request", UBInt8("version"),
Ejemplo n.º 23
0
    events=PrefixedArray(VarInt, ConstructResourceInfo),
    tricks=PrefixedArray(VarInt, ConstructTrickResourceInfo),
    damage=PrefixedArray(
        VarInt,
        Struct(
            Embedded(ConstructResourceInfo),
            reductions=PrefixedArray(
                VarInt, Struct(
                    index=VarInt,
                    multiplier=Float32b,
                )),
        )),
    versions=PrefixedArray(VarInt, ConstructResourceInfo),
    misc=PrefixedArray(VarInt, ConstructResourceInfo),
    requirement_template=PrefixedArray(
        VarInt, Sequence(CString("utf8"), ConstructRequirement)))

ConstructEchoesBeamConfiguration = Struct(
    item_index=VarInt,
    ammo_a=OptionalValue(Byte),
    ammo_b=OptionalValue(Byte),
    uncharged_cost=Byte,
    charged_cost=Byte,
    combo_missile_cost=Byte,
    combo_ammo_cost=Byte,
)

ConstructEchoesGameSpecific = Struct(
    energy_per_tank=Float32b,
    safe_zone_heal_per_second=Float32b,
    beam_configurations=PrefixedArray(VarInt,
Ejemplo n.º 24
0
from empower.core.resourcepool import CQM
from empower.core.resourcepool import ResourceBlock
from empower.core.resourcepool import ResourcePool
from empower.core.module import Module
from empower.lvapp import PT_VERSION

from empower.main import RUNTIME

PT_POLLER_REQ_MSG_TYPE = 0x27
PT_POLLER_RESP_MSG_TYPE = 0x28


POLLER_ENTRY_TYPE = Sequence("img_entries",
                             Bytes("addr", 6),
                             UBInt32("last_rssi_std"),
                             SBInt32("last_rssi_avg"),
                             UBInt32("last_packets"),
                             UBInt32("hist_packets"),
                             SBInt32("ewma_rssi"),
                             SBInt32("sma_rssi"))

POLLER_REQUEST = Struct("poller_request", UBInt8("version"),
                        UBInt8("type"),
                        UBInt16("length"),
                        UBInt32("seq"),
                        UBInt32("module_id"),
                        Bytes("addrs", 6),
                        Bytes("hwaddr", 6),
                        UBInt8("channel"),
                        UBInt8("band"))

POLLER_RESPONSE = Struct("poller_response", UBInt8("version"),
Ejemplo n.º 25
0
	return mapping[obj.__class__]

# Recurrent term
term_ = LazyBound(lambda: term)

atom_cache_ref = ExprAdapter(Int8ub,
		encoder=lambda obj, ctx: obj.index,
		decoder=lambda obj, ctx: AtomCacheReference(obj))
small_integer = Int8ub
integer = Int32sb
float_ = ExprAdapter(PaddedString(31, encoding="ascii"),
		encoder=lambda obj, ctx: u"{:.20e}    ".format(obj),
		decoder=lambda obj, ctx: float(obj))
atom = PascalString(lengthfield=Int16ub, encoding="latin1")
reference = ExprAdapter(Sequence("node" / term_,
		"id" / Int32ub,
		"creation" / Int8ub),
		encoder=lambda obj, ctx: (obj.node, obj.id, obj.creation),
		decoder=lambda obj, ctx: Reference(*obj))
port = ExprAdapter(Sequence("node" / term_,
		"id" / Int32ub,
		"creation" / Int8ub),
		encoder=lambda obj, ctx: (obj.node, obj.id, obj.creation),
		decoder=lambda obj, ctx: Port(*obj))
pid = ExprAdapter(Sequence("node" / term_,
		"id" / Int32ub,
		"serial" / Int32ub,
		"creation" / Int8ub),
		encoder=lambda obj, ctx: (obj.node, obj.id, obj.serial, obj.creation),
		decoder=lambda obj, ctx: Pid(*obj))
small_tuple = TupleAdapter(PrefixedArray(Int8ub, term_))
Ejemplo n.º 26
0
    },
}

# Constants
BYTE_N = 16
SAMPLING_BASE_TIME = timedelta(0, 0, 1000000)

# Structure for data exchange with sockets
MyDataFormat = Struct(
    "Signature" / Const(b"BMS"),
    "time" / Int32ub,
    "data" / Array(BYTE_N, Int16ub),
)
# Structure for data exchange with sockets PL1012 Picolog
PL1012BYTE_N = 12
PL1012DataFormat = Struct("data" / Array(PL1012BYTE_N, Int16ul))
TC08FLOAT_N = 9
TC08DataFormat = Struct("data" / Array(TC08FLOAT_N, Float32l))
PEAK_MSGS = 6
CANREAD_TIMEOUT = 0.600000
PEAKDataFormat = Array(PEAK_MSGS,
                       Sequence(PaddedString(11, 'utf-8'), Array(8, Int8ub)))

# Screen position of data
SCREEN_POS = [(5, 2), (7, 2), (9, 2), (11, 2), (13, 2), (15, 2), (17, 2),
              (19, 2), (21, 2), (23, 2), (5, 27), (7, 27), (9, 27), (11, 27),
              (13, 27), (15, 27), (17, 27), (19, 27), (21, 27), (23, 27),
              (5, 52), (7, 52), (9, 52), (11, 52),
              (13, 52), (15, 52), (17, 52), (19, 52), (21, 52), (23, 52),
              (5, 77), (7, 77), (9, 77), (11, 77), (13, 77), (15, 77),
              (17, 77), (19, 77), (21, 77), (23, 77), (25, 2)]
Ejemplo n.º 27
0
                     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))
Ejemplo n.º 28
0
from empower.lvapp import PT_VERSION
from empower.datatypes.etheraddress import EtherAddress
from empower.lvapp.lvappserver import LVAPPServer
from empower.datatypes.etheraddress import EtherAddress
from empower.lvapp.lvappserver import ModuleLVAPPWorker
from empower.core.module import Module
from empower.core.app import EmpowerApp

from empower.main import RUNTIME


PT_WTP_STATS_REQUEST = 0x41
PT_WTP_STATS_RESPONSE = 0x42

WTP_STATS = Sequence("stats",
                     Bytes("lvap", 6),
                     UBInt16("bytes"),
                     UBInt32("count"))

WTP_STATS_REQUEST = Struct("stats_request", UBInt8("version"),
                           UBInt8("type"),
                           UBInt32("length"),
                           UBInt32("seq"),
                           UBInt32("module_id"))

WTP_STATS_RESPONSE = \
    Struct("stats_response", UBInt8("version"),
           UBInt8("type"),
           UBInt32("length"),
           UBInt32("seq"),
           UBInt32("module_id"),
           Bytes("wtp", 6),
Ejemplo n.º 29
0
from construct import Array

from empower.lvapp.lvappserver import ModuleLVAPPWorker
from empower.core.app import EmpowerApp
from empower.datatypes.etheraddress import EtherAddress
from empower.core.module import ModulePeriodic
from empower.core.resourcepool import CQM
from empower.core.resourcepool import ResourceBlock
from empower.lvapp import PT_VERSION

from empower.main import RUNTIME

PT_WIFI_STATS_REQUEST = 0x37
PT_WIFI_STATS_RESPONSE = 0x38

ENTRY_TYPE = Sequence("entries", UBInt8("type"), UBInt32("timestamp"),
                      UBInt32("sample"))

WIFI_STATS_REQUEST = Struct("wifi_stats_request", UBInt8("version"),
                            UBInt8("type"), UBInt32("length"), UBInt32("seq"),
                            UBInt32("module_id"), Bytes("hwaddr", 6),
                            UBInt8("channel"), UBInt8("band"))

WIFI_STATS_RESPONSE = Struct("wifi_stats_response", UBInt8("version"),
                             UBInt8("type"), UBInt32("length"), UBInt32("seq"),
                             UBInt32("module_id"), Bytes("wtp", 6),
                             UBInt16("nb_entries"),
                             Array(lambda ctx: ctx.nb_entries, ENTRY_TYPE))


class WiFiStats(ModulePeriodic):
    """ A maps poller. """