Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
FRAME = cons.Struct('frames',
cons.ULInt32('cmd_table_offset'),
cons.ULInt32('outline_table_offset'),
cons.ULInt32('palette_offset'),
cons.ULInt32('properties'),
cons.SLInt32('width'),
cons.SLInt32('height'),
cons.SLInt32('hotspot_x'),
cons.SLInt32('hotspot_y'),
)
HEADER = cons.Struct('header',
cons.String('version', 4),
cons.ULInt32('num_frames'),
cons.String('comment', 24),
cons.Array(lambda ctx: ctx['num_frames'], FrameAdapter(FRAME)),
)
class ImageAdapter(object):
"""
A generic image writer. Could be used with PIL, cairo, ...
"""
def __init__(self, frame):
"""
Create a new image with the dimensions given by the frame object.
"""
raise NotImplementedError()
def draw_pixels(self, x, y, amount, color):
"""
Draw *amount* pixels, horizontally, starting at *x*, *y*.
*color* is a 3-tuple (R, G, B) or None for transparency.
construct.ULInt16('logical_width'),
construct.ULInt16('logical_height'),
construct.EmbeddedBitStruct(
construct.Flag('gct_flag'),
construct.macros.BitField('colour_res', 3),
construct.Flag('sort_flag'),
construct.macros.BitField('gct_size', 3),
),
construct.ULInt8('bg_col_index'),
construct.ULInt8('pixel_aspect'),
)
_gct = construct.Array(
lambda ctx: pow(2, ctx.logical_screen_descriptor.gct_size + 1),
construct.Array(3, construct.ULInt8('gct')),
)
gif = construct.Struct(
'GIF',
construct.Select(
'magic',
construct.Magic('GIF89a'),
construct.Magic('GIF87a'),
),
_logical_screen_descriptor,
construct.If(lambda ctx: ctx.logical_screen_descriptor.gct_flag, _gct),
construct.RepeatUntil(
lambda obj, ctx: obj.block_start == 0x3B,
construct.Struct(
'body',
"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 = {}
ipv6_mask_size : int
IPv6 netmask CIDR notation
rx_bytes : int
Number of Rx bytes
tx_bytes : int
Number of Tx bytes
interface_name : string
Interface Name
flags : int
Interface flags from SIOCGIFFLAGS
sender : int
Optional sender ID, defaults to SENDER_ID (see sbp/msg.py).
"""
_parser = construct.Struct(
'ipv4_address' / construct.Array(4, construct.Int8ul),
'ipv4_mask_size' / construct.Int8ul,
'ipv6_address' / construct.Array(16, construct.Int8ul),
'ipv6_mask_size' / construct.Int8ul,
'rx_bytes' / construct.Int32ul,
'tx_bytes' / construct.Int32ul,
'interface_name'/ construct.Bytes(16),
'flags' / construct.Int32ul,)
__slots__ = [
'ipv4_address',
'ipv4_mask_size',
'ipv6_address',
'ipv6_mask_size',
'rx_bytes',
'tx_bytes',
'interface_name',
'flags',
# TODO: update emtpy, hints, updating and user.
_FILE_HEADER = construct.Struct(
u'chrome_cache_data_file_header',
construct.ULInt32(u'signature'),
construct.ULInt16(u'minor_version'),
construct.ULInt16(u'major_version'),
construct.ULInt16(u'file_number'),
construct.ULInt16(u'next_file_number'),
construct.ULInt32(u'block_size'),
construct.ULInt32(u'number_of_entries'),
construct.ULInt32(u'maximum_number_of_entries'),
construct.Array(4, construct.ULInt32(u'emtpy')),
construct.Array(4, construct.ULInt32(u'hints')),
construct.ULInt32(u'updating'),
construct.Array(5, construct.ULInt32(u'user')),
construct.Array(2028, construct.ULInt32(u'allocation_bitmap')))
_CACHE_ENTRY = construct.Struct(
u'chrome_cache_entry',
construct.ULInt32(u'hash'),
construct.ULInt32(u'next_address'),
construct.ULInt32(u'rankings_node_address'),
construct.ULInt32(u'reuse_count'),
construct.ULInt32(u'refetch_count'),
construct.ULInt32(u'state'),
construct.ULInt64(u'creation_time'),
construct.ULInt32(u'key_size'),
construct.ULInt32(u'long_key_address'),
construct.Array(4, construct.ULInt32(u'data_stream_sizes')),
construct.Array(4, construct.ULInt32(u'data_stream_addresses')),
construct.ULInt32(u'flags'),
construct.Padding(16),
The flash status message writes to the 8-bit M25 flash status
register. The device replies with a MSG_FLASH_DONE message.
Parameters
----------
sbp : SBP
SBP parent object to inherit from.
status : array
Byte to write to the M25 flash status register
sender : int
Optional sender ID, defaults to SENDER_ID (see sbp/msg.py).
"""
_parser = construct.Struct(
'status' / construct.Array(1, construct.Int8ul),)
__slots__ = [
'status',
]
def __init__(self, sbp=None, **kwargs):
if sbp:
super( MsgM25FlashWriteStatus,
self).__init__(sbp.msg_type, sbp.sender, sbp.length,
sbp.payload, sbp.crc)
self.from_binary(sbp.payload)
else:
super( MsgM25FlashWriteStatus, self).__init__()
self.msg_type = SBP_MSG_M25_FLASH_WRITE_STATUS
self.sender = kwargs.pop('sender', SENDER_ID)
self.status = kwargs.pop('status')
# Bitmap 13 - found later in file
class UTF8(FixedObjectByteArray):
classID = 14
_construct = PascalString("value", length_field=UBInt32("length"),
encoding="utf8")
# Collections
class Collection(FixedObjectWithRepeater, ContainsRefs):
_construct = Struct("",
UBInt32("length"),
MetaRepeater(lambda ctx: ctx.length, Rename("items", field)),
)
def __init__(self, value=None):
if value == None:
value = []
FixedObject.__init__(self, value)
def __iter__(self):
return iter(self.value)
def __getattr__(self, name):
if name in ('append', 'count', 'extend', 'index', 'insert', 'pop',
'remove', 'reverse', 'sort'):
return getattr(self.value, name)
return super(Collection, self).__getattr__(name)
construct.Int32ul,
),
# offset_high always 0 if ver < 101
"offset_high"
/ construct.IfThenElse(
construct.this._.version >= 101,
construct.Transformed(
construct.Int32ul, LMObfuscator().transform_int, 4, LMObfuscator().transform_int_high, 4,
),
construct.Int32ul,
),
),
),
"compress_types" / construct.Array(construct.this.count, construct.Enum(construct.Byte, LMCompressType)),
"unk1s"
/ construct.Array(
construct.this.count,
# construct.Transformed(
# construct.Int32ul,
# LMObfuscator().transform_int,
# 4,
# LMObfuscator().transform_int,
# 4,
# ),
construct.Int32ul,
),
"checksums" / construct.Array(construct.this.count, construct.Int32ul,),
"encrypt_flags" / construct.Array(construct.this.count, construct.Byte,),
)
def ReadVtableFixups(ClrHeader):
VTableFixup = construct.Struct('VTableFixup',
MakeRva('RVA'),
construct.ULInt16('Count'),
construct.FlagsEnum(construct.ULInt16('Type'),
COR_VTABLE_32BIT = 0x01, # V-table slots are 32-bits in size.
COR_VTABLE_64BIT = 0x02, # V-table slots are 64-bits in size.
COR_VTABLE_FROM_UNMANAGED = 0x04, # If set, transition from unmanaged.
COR_VTABLE_FROM_UNMANAGED_RETAIN_APPDOMAIN = 0x08, # If set, transition from unmanaged with keeping the current appdomain.
COR_VTABLE_CALL_MOST_DERIVED = 0x10, # Call most derived method described by
)
)
numFixups = ClrHeader.VTableFixups.Size / VTableFixup.sizeof()
VTableFixups = construct.Array(numFixups, VTableFixup)
if numFixups == 0: return []
return VTableFixups.parse(idc.GetManyBytes(clrHeader.VTableFixups.VA, VTableFixups.sizeof()))
MetadataTableHeader = construct.Struct('MetadataTableHeader',
construct.ULInt32('Reserved'),
construct.ULInt8('MajorVersion'),
construct.ULInt8('MinorVersion'),
construct.FlagsEnum(construct.ULInt8('HeapSizeFlags'),
StringHeapLarge = 0x01, # 4 byte uint indexes used for string heap offsets
GUIDHeapLarge = 0x02, # 4 byte uint indexes used for GUID heap offsets
BlobHeapLarge = 0x04, # 4 byte uint indexes used for Blob heap offsets
EnCDeltas = 0x20, # Indicates only EnC Deltas are present
DeletedMarks = 0x80, # Indicates metadata might contain items marked deleted
),
construct.ULInt8('RowId'),
construct.ULInt64('ValidTables'),
construct.ULInt64('SortedTables'),
construct.Array(lambda ctx: bin(ctx.ValidTables).count('1'), construct.ULInt32('NumRows'))
)
class MDTable:
Module = 0x00
TypeRef = 0x01
TypeDef = 0x02
FieldPtr = 0x03
Field = 0x04
MethodPtr = 0x05
Method = 0x06
ParamPtr = 0x07
Param = 0x08
InterfaceImpl = 0x09
MemberRef = 0x0A
Constant = 0x0B
CustomAttribute = 0x0C