def _parse_secondary(self, s: BytesIO, flags: int): Uint16LE.unpack(s) # orderLength (unused) extraFlags = Uint16LE.unpack(s) orderType = Uint8.unpack(s) assert orderType >= 0 and orderType < len(_sec) _sec[orderType](self, s, orderType, extraFlags)
def parse(s: BytesIO, flags: int) -> CacheBitmap: self = CacheBitmapV3(3) self.cacheId = flags & 0x00000003 self.flags = (flags & 0x0000FF80) >> 7 bitsPerPixelId = (flags & 0x00000078) >> 3 # The spec says this should never be 0, but it is... self.bpp = CBR23_BPP[bitsPerPixelId] self.cacheIndex = Uint16LE.unpack(s) self.key1 = Uint32LE.unpack(s) self.key2 = Uint32LE.unpack(s) self.bpp = Uint8.unpack(s) compressed = Uint8.unpack(s) s.read(1) # Reserved (1 bytes) self.codecId = Uint8.unpack(s) self.width = Uint16LE.unpack(s) self.height = Uint16LE.unpack(s) dataLen = Uint32LE.unpack(s) if compressed: # TS_COMPRESSED_BITMAP_HEADER_EX present. s.read(24) # Non-essential. self.data = s.read(dataLen) return self
def update(self, s: BytesIO): if self.ctx.field(1): self.cacheId = Uint16LE.unpack(s) if self.ctx.field(2): self.left = read_coord(s, self.ctx.deltaCoords, self.left) if self.ctx.field(3): self.top = read_coord(s, self.ctx.deltaCoords, self.top) if self.ctx.field(4): self.width = read_coord(s, self.ctx.deltaCoords, self.width) if self.ctx.field(5): self.height = read_coord(s, self.ctx.deltaCoords, self.height) if self.ctx.field(6): self.rop = Uint8.unpack(s) if self.ctx.field(7): self.nXSrc = read_coord(s, self.ctx.deltaCoords, self.nXSrc) if self.ctx.field(8): self.nYSrc = read_coord(s, self.ctx.deltaCoords, self.nYSrc) if self.ctx.field(9): self.bg = read_rgb(s) if self.ctx.field(10): self.fg = read_rgb(s) self.brush.update(s, self.ctx.fieldFlags >> 10) if self.ctx.field(16): self.cacheIndex = Uint16LE.unpack(s) self.colorIndex = self.cacheId >> 8 self.cacheId = self.cacheId & 0xFF return self
def update(self, s: BytesIO) -> 'MemBlt': ctx = self.ctx if ctx.field(1): self.cacheId = Uint16LE.unpack(s) if ctx.field(2): self.left = read_coord(s, ctx.deltaCoords, self.left) if ctx.field(3): self.top = read_coord(s, ctx.deltaCoords, self.top) if ctx.field(4): self.width = read_coord(s, ctx.deltaCoords, self.width) if ctx.field(5): self.height = read_coord(s, ctx.deltaCoords, self.height) if ctx.field(6): self.rop = Uint8.unpack(s) if ctx.field(7): self.xSrc = read_coord(s, ctx.deltaCoords, self.xSrc) if ctx.field(8): self.ySrc = read_coord(s, ctx.deltaCoords, self.ySrc) if ctx.field(9): self.cacheIndex = Uint16LE.unpack(s) self.colorIndex = self.cacheId >> 8 self.cacheId = self.cacheId & 0xFF return self
def parse(s: BytesIO) -> 'Glyph': self = Glyph() self.cacheIndex = Uint16LE.unpack(s) self.x = Uint16LE.unpack(s) self.y = Uint16LE.unpack(s) self.w = Uint16LE.unpack(s) self.h = Uint16LE.unpack(s) self.data = read_glyph_bitmap(self.w, self.h, s) return self
def update(self, s: BytesIO): if self.ctx.field(1): self.x = read_coord(s, self.ctx.deltaCoords, self.x) if self.ctx.field(2): self.y = read_coord(s, self.ctx.deltaCoords, self.y) if self.ctx.field(3): self.w = read_coord(s, self.ctx.deltaCoords, self.w) if self.ctx.field(4): self.h = read_coord(s, self.ctx.deltaCoords, self.h) if self.ctx.field(5): self.rop = Uint8.unpack(s) if self.ctx.field(6): self.bg = read_rgb(s) if self.ctx.field(7): self.fg = read_rgb(s) self.brush.update(s, self.ctx.fieldFlags >> 7) if self.ctx.field(13): self.numRectangles = Uint8.unpack(s) if self.ctx.field(14): self.cbData = Uint16LE.unpack(s) self.rectangles = read_delta_rectangles(s, self.numRectangles) return self
def update(self, s: BytesIO): if self.ctx.field(1): self.nLeftRect = read_coord(s, self.ctx.deltaCoords, self.nLeftRect) if self.ctx.field(2): self.nTopRect = read_coord(s, self.ctx.deltaCoords, self.nTopRect) if self.ctx.field(3): self.nWidth = read_coord(s, self.ctx.deltaCoords, self.nWidth) if self.ctx.field(4): self.nHeight = read_coord(s, self.ctx.deltaCoords, self.nHeight) if self.ctx.field(5): self.bRop = Uint8.unpack(s) if self.ctx.field(6): self.nXSrc = read_coord(s, self.ctx.deltaCoords, self.nXSrc) if self.ctx.field(7): self.nYSrc = read_coord(s, self.ctx.deltaCoords, self.nYSrc) if self.ctx.field(8): self.numRectangles = Uint8.unpack(s) if self.ctx.field(9): self.cbData = Uint16LE.unpack(s) self.rectangles = read_delta_rectangles(s, self.numRectangles) return self
def update(self, s: BytesIO): if self.ctx.field(1): self.nLeftRect = read_coord(s, self.ctx.deltaCoords, self.nLeftRect) if self.ctx.field(2): self.nTopRect = read_coord(s, self.ctx.deltaCoords, self.nTopRect) if self.ctx.field(3): self.nWidth = read_coord(s, self.ctx.deltaCoords, self.nWidth) if self.ctx.field(4): self.nHeight = read_coord(s, self.ctx.deltaCoords, self.nHeight) if self.ctx.field(5): r = Uint8.unpack(s) self.color = (self.color & 0x00FFFF00) | r if self.ctx.field(6): g = Uint8.unpack(s) self.color = (self.color & 0x00FF00FF) | (g << 8) if self.ctx.field(7): b = Uint8.unpack(s) self.color = (self.color & 0x0000FFFF) | (b << 16) if self.ctx.field(8): self.numRectangles = Uint8.unpack(s) if self.ctx.field(9): self.cbData = Uint16LE.unpack(s) self.rectangles = read_delta_rectangles(s, self.numRectangles) return self
def update(self, s: BytesIO): if self.ctx.field(1): self.cacheId = Uint8.unpack(s) if self.ctx.field(2): self.flAccel = Uint8.unpack(s) if self.ctx.field(3): self.ulCharInc = Uint8.unpack(s) if self.ctx.field(4): self.fOpRedundant = Uint8.unpack(s) if self.ctx.field(5): self.bg = read_rgb(s) if self.ctx.field(6): self.fg = read_rgb(s) if self.ctx.field(7): self.bkLeft = Uint16LE.unpack(s) if self.ctx.field(8): self.bkTop = Uint16LE.unpack(s) if self.ctx.field(9): self.bkRight = Uint16LE.unpack(s) if self.ctx.field(10): self.bkBottom = Uint16LE.unpack(s) if self.ctx.field(11): self.opLeft = Uint16LE.unpack(s) if self.ctx.field(12): self.opTop = Uint16LE.unpack(s) if self.ctx.field(13): self.opRight = Uint16LE.unpack(s) if self.ctx.field(14): self.opBottom = Uint16LE.unpack(s) self.brush.update(s, self.ctx.fieldFlags >> 14) if self.ctx.field(20): self.x = Uint16LE.unpack(s) if self.ctx.field(21): self.y = Uint16LE.unpack(s) if self.ctx.field(22): cbData = Uint8.unpack(s) self.data = s.read(cbData) return self
def parse(s: BytesIO) -> 'CacheColorTable': self = CacheColorTable() self.cacheIndex = Uint8.unpack(s) numberColors = Uint16LE.unpack(s) assert numberColors == 256 self.colors = [read_color(s) for _ in range(numberColors)] return self
def update(self, s: BytesIO): if self.ctx.field(1): self.srcLeft = read_coord(s, self.ctx.deltaCoords, self.srcLeft) if self.ctx.field(2): self.srcTop = read_coord(s, self.ctx.deltaCoords, self.srcTop) if self.ctx.field(3): self.srcRight = read_coord(s, self.ctx.deltaCoords, self.srcRight) if self.ctx.field(4): self.srcBottom = read_coord(s, self.ctx.deltaCoords, self.srcBottom) if self.ctx.field(5): self.bitmapId = Uint16LE.unpack(s) if self.ctx.field(6): self.nDeltaEntries = Uint8.unpack(s) if self.ctx.field(7): self.cbData = Uint16LE.unpack(s) self.rectangles = read_delta_rectangles(s, self.nDeltaEntries) return self
def parse(s: BytesIO, orderType: int, flags: int) -> CacheBitmap: self = CacheBitmapV1(1) self.cacheId = Uint8.unpack(s) s.read(1) # Padding self.width = Uint8.unpack(s) self.height = Uint8.unpack(s) self.bpp = Uint8.unpack(s) bitmapLength = Uint16LE.unpack(s) self.cacheIndex = Uint16LE.unpack(s) if orderType & Secondary.CACHE_BITMAP_COMPRESSED and \ not flags & GeneralExtraFlag.NO_BITMAP_COMPRESSION_HDR: self.compression = s.read(8) bitmapLength -= 8 self.data = s.read(bitmapLength) return self
def update(self, s: BytesIO): if self.ctx.field(1): self.srcLeft = read_coord(s, self.ctx.deltaCoords, self.srcLeft) if self.ctx.field(2): self.srcTop = read_coord(s, self.ctx.deltaCoords, self.srcTop) if self.ctx.field(3): self.srcRight = read_coord(s, self.ctx.deltaCoords, self.srcRight) if self.ctx.field(4): self.srcBottom = read_coord(s, self.ctx.deltaCoords, self.srcBottom) if self.ctx.field(5): self.bitmapId = Uint16LE.unpack(s) return self
def parse(s: BytesIO, orderType: int, flags: int) -> CacheBitmap: self = CacheBitmapV2() self.cacheId = flags & 0x0003 self.flags = (flags & 0xFF80) >> 7 self.bpp = CBR2_BPP[(flags & 0x0078) >> 3] if self.flags & CBR2_PERSISTENT_KEY_PRESENT: self.key1 = Uint32LE.unpack(s) self.key2 = Uint32LE.unpack(s) if self.flags & CBR2_HEIGHT_SAME_AS_WIDTH: self.height = self.width = read_encoded_uint16(s) else: self.width = read_encoded_uint16(s) self.height = read_encoded_uint16(s) bitmapLength = read_encoded_uint32(s) self.cacheIndex = read_encoded_uint16(s) if self.flags & CBR2_DO_NOT_CACHE: self.cacheIndex = BITMAP_CACHE_WAITING_LIST_INDEX if orderType & Secondary.BITMAP_COMPRESSED_V2 and not \ self.flags & CBR2_NO_BITMAP_COMPRESSION_HDR: # Parse compression header self.cbCompFirstRowSize = Uint16LE.unpack(s) self.cbCompMainBodySize = Uint16LE.unpack(s) self.cbScanWidth = Uint16LE.unpack(s) self.cbUncompressedSize = Uint16LE.unpack(s) bitmapLength = self.cbCompMainBodySize # Read bitmap data self.data = s.read(bitmapLength) return self
def parse(self, orders: FastPathOrdersEvent): """ Entrypoint for parsing TS_FP_UPDATE_ORDERS. """ s = BytesIO(orders.payload) numberOrders = Uint16LE.unpack(s) try: for _ in range(numberOrders): self._parse_order(s) except Exception: LOG.warning('Failed to parse drawing order PDU: %s', orders) return orders
def update(self, s: BytesIO): if self.ctx.field(1): self.bgMode = Uint16LE.unpack(s) if self.ctx.field(2): self.x0 = read_coord(s, self.ctx.deltaCoords, self.x0) if self.ctx.field(3): self.y0 = read_coord(s, self.ctx.deltaCoords, self.y0) if self.ctx.field(4): self.x1 = read_coord(s, self.ctx.deltaCoords, self.x1) if self.ctx.field(5): self.y1 = read_coord(s, self.ctx.deltaCoords, self.y1) if self.ctx.field(6): self.bg = read_rgb(s) if self.ctx.field(7): self.rop2 = Uint8.unpack(s) if self.ctx.field(8): self.penStyle = Uint8.unpack(s) if self.ctx.field(9): self.penWidth = Uint8.unpack(s) if self.ctx.field(10): self.penColor = read_rgb(s) return self
def read_utf16_str(s: BytesIO, size: int) -> [int]: return [Uint16LE.unpack(s) for _ in range(size)] # Decode into str?