int FillPolyStore::parseIdentity(Message *message, const unsigned char *buffer, unsigned int size, int bigEndian) const { FillPolyMessage *fillPoly = (FillPolyMessage *) message; // // Here is the fingerprint. // fillPoly -> drawable = GetULONG(buffer + 4, bigEndian); fillPoly -> gcontext = GetULONG(buffer + 8, bigEndian); fillPoly -> shape = *(buffer + 12); fillPoly -> mode = *(buffer + 13); if (control -> isProtoStep8() == 1 && size >= (unsigned int) dataOffset) { fillPoly -> x_origin = GetUINT(buffer + 16, bigEndian); fillPoly -> y_origin = GetUINT(buffer + 18, bigEndian); } else { fillPoly -> x_origin = 0; fillPoly -> y_origin = 0; } #ifdef DEBUG *logofs << name() << ": Parsed Identity for message at " << this << ".\n" << logofs_flush; #endif return 1; }
int ImageText16Store::parseIdentity(Message *message, const unsigned char *buffer, unsigned int size, int bigEndian) const { ImageText16Message *imageText16 = (ImageText16Message *) message; // // Here is the fingerprint. // imageText16 -> len = *(buffer + 1); imageText16 -> drawable = GetULONG(buffer + 4, bigEndian); imageText16 -> gcontext = GetULONG(buffer + 8, bigEndian); imageText16 -> x = GetUINT(buffer + 12, bigEndian); imageText16 -> y = GetUINT(buffer + 14, bigEndian); if ((int) size > dataOffset) { int pad = (size - dataOffset) - (imageText16 -> len * 2); if (pad > 0) { CleanData((unsigned char *) buffer + size - pad, pad); } } #ifdef DEBUG *logofs << name() << ": Parsed Identity for message at " << this << ".\n" << logofs_flush; #endif return 1; }
int SendEventStore::parseIdentity(Message *message, const unsigned char *buffer, unsigned int size, int bigEndian) const { SendEventMessage *sendEvent = (SendEventMessage *) message; // // Here is the fingerprint. // sendEvent -> propagate = *(buffer + 1); sendEvent -> window = GetULONG(buffer + 4, bigEndian); sendEvent -> mask = GetULONG(buffer + 8, bigEndian); sendEvent -> code = *(buffer + 12); sendEvent -> byte_data = *(buffer + 13); sendEvent -> sequence = GetUINT(buffer + 14, bigEndian); sendEvent -> int_data = GetULONG(buffer + 16, bigEndian); #ifdef DEBUG *logofs << name() << ": Parsed Identity for message at " << this << ".\n" << logofs_flush; #endif return 1; }
int GetImageStore::parseIdentity(Message *message, const unsigned char *buffer, unsigned int size, int bigEndian) const { GetImageMessage *getImage = (GetImageMessage *) message; // // Here is the fingerprint. // getImage -> format = *(buffer + 1); #ifdef TEST if (getImage -> format != 1 && getImage -> format != 2) { *logofs << name() << ": WARNING! Dirty value " << getImage -> format << " for field format.\n" << logofs_flush; } #endif getImage -> drawable = GetULONG(buffer + 4, bigEndian); getImage -> x = GetUINT(buffer + 8, bigEndian); getImage -> y = GetUINT(buffer + 10, bigEndian); getImage -> width = GetUINT(buffer + 12, bigEndian); getImage -> height = GetUINT(buffer + 14, bigEndian); getImage -> plane_mask = GetULONG(buffer + 16, bigEndian); #ifdef DEBUG *logofs << name() << ": Parsed Identity for message at " << this << ".\n" << logofs_flush; #endif return 1; }
int CopyAreaStore::parseIdentity(Message *message, const unsigned char *buffer, unsigned int size, int bigEndian) const { CopyAreaMessage *copyArea = (CopyAreaMessage *) message; // // Here is the fingerprint. // copyArea -> src_drawable = GetULONG(buffer + 4, bigEndian); copyArea -> dst_drawable = GetULONG(buffer + 8, bigEndian); copyArea -> gcontext = GetULONG(buffer + 12, bigEndian); copyArea -> src_x = GetUINT(buffer + 16, bigEndian); copyArea -> src_y = GetUINT(buffer + 18, bigEndian); copyArea -> dst_x = GetUINT(buffer + 20, bigEndian); copyArea -> dst_y = GetUINT(buffer + 22, bigEndian); copyArea -> width = GetUINT(buffer + 24, bigEndian); copyArea -> height = GetUINT(buffer + 26, bigEndian); #ifdef DEBUG *logofs << name() << ": Parsed Identity for message at " << this << ".\n" << logofs_flush; #endif return 1; }
int CreatePixmapStore::encodeIdentity(EncodeBuffer &encodeBuffer, const unsigned char *buffer, const unsigned int size, int bigEndian, ChannelCache *channelCache) const { ClientCache *clientCache = (ClientCache *) channelCache; encodeBuffer.encodeCachedValue(*(buffer + 1), 8, clientCache -> depthCache); encodeBuffer.encodeNewXidValue(GetULONG(buffer + 4, bigEndian), clientCache -> lastId, clientCache -> lastIdCache, clientCache -> drawableCache, clientCache -> freeDrawableCache); encodeBuffer.encodeXidValue(GetULONG(buffer + 8, bigEndian), clientCache -> windowCache); encodeBuffer.encodeCachedValue(GetUINT(buffer + 12, bigEndian), 16, clientCache -> createPixmapXCache, 8); encodeBuffer.encodeCachedValue(GetUINT(buffer + 14, bigEndian), 16, clientCache -> createPixmapYCache, 8); #ifdef TEST *logofs << name() << ": Encoded message. Size is " << size << ".\n" << logofs_flush; #endif return 1; }
int SetUnpackColormapStore::encodeIdentity(EncodeBuffer &encodeBuffer, const unsigned char *buffer, const unsigned int size, int bigEndian, ChannelCache *channelCache) const { ClientCache *clientCache = (ClientCache *) channelCache; #ifdef DEBUG *logofs << name() << ": Encoding full message identity.\n" << logofs_flush; #endif // // Encode the source length first because // we need it to determine the size of // the output buffer. // // SrcLength. encodeBuffer.encodeValue(GetULONG(buffer + 8, bigEndian), 32, 9); // Client. encodeBuffer.encodeCachedValue(*(buffer + 1), 8, clientCache -> resourceCache); // Method. encodeBuffer.encodeCachedValue(*(buffer + 4), 8, clientCache -> methodCache); // DstLength. encodeBuffer.encodeValue(GetULONG(buffer + 12, bigEndian), 32, 9); #ifdef DEBUG *logofs << name() << ": Encoded full message identity.\n" << logofs_flush; #endif return 1; }
int ChangePropertyStore::parseIdentity(Message *message, const unsigned char *buffer, unsigned int size, int bigEndian) const { ChangePropertyMessage *changeProperty = (ChangePropertyMessage *) message; changeProperty -> mode = *(buffer + 1); changeProperty -> format = *(buffer + 16); changeProperty -> window = GetULONG(buffer + 4, bigEndian); changeProperty -> property = GetULONG(buffer + 8, bigEndian); changeProperty -> type = GetULONG(buffer + 12, bigEndian); changeProperty -> length = GetULONG(buffer + 20, bigEndian); // // Cleanup the padding bytes. // unsigned int uiFormat; unsigned int uiLengthInBytes; if ((int) size > CHANGEPROPERTY_DATA_OFFSET) { uiFormat = *(buffer + 16); uiLengthInBytes = changeProperty -> length; #ifdef DEBUG *logofs << name() << ": length " << uiLengthInBytes << ", format " << uiFormat << ", size " << size << ".\n" << logofs_flush; #endif if (uiFormat == 16) { uiLengthInBytes <<= 1; } else if (uiFormat == 32) { uiLengthInBytes <<= 2; } unsigned char *end = ((unsigned char *) buffer) + size; unsigned char *pad = ((unsigned char *) buffer) + CHANGEPROPERTY_DATA_OFFSET + uiLengthInBytes; CleanData((unsigned char *) pad, end - pad); } #ifdef DEBUG *logofs << name() << ": Parsed identity for message at " << message << ".\n" << logofs_flush; #endif return 1; }
int GetPropertyReplyStore::parseIdentity(Message *message, const unsigned char *buffer, unsigned int size, int bigEndian) const { GetPropertyReplyMessage *getPropertyReply = (GetPropertyReplyMessage *) message; getPropertyReply -> format = *(buffer + 1); getPropertyReply -> type = GetULONG(buffer + 8, bigEndian); getPropertyReply -> after = GetULONG(buffer + 12, bigEndian); getPropertyReply -> items = GetULONG(buffer + 16, bigEndian); // // Cleanup the padding bytes. // unsigned int uiLengthInBytes; unsigned int uiFormat; if ((int) size > GETPROPERTYREPLY_DATA_OFFSET) { uiLengthInBytes = getPropertyReply -> items; uiFormat = *(buffer + 1); #ifdef DEBUG *logofs << name() << ": length " << uiLengthInBytes << ", format " << uiFormat << ", size " << size << ".\n" << logofs_flush; #endif if (uiFormat == 16) { uiLengthInBytes <<= 1; } else if (uiFormat == 32) { uiLengthInBytes <<= 2; } unsigned char *end = ((unsigned char *) buffer) + size; unsigned char *pad = ((unsigned char *) buffer) + GETPROPERTYREPLY_DATA_OFFSET + uiLengthInBytes; CleanData((unsigned char *) pad, end - pad); } #ifdef DEBUG *logofs << name() << ": Parsed identity for message at " << message << ".\n" << logofs_flush; #endif return 1; }
int SetUnpackColormapStore::parseIdentity(Message *message, const unsigned char *buffer, unsigned int size, int bigEndian) const { SetUnpackColormapMessage *setUnpackColormap = (SetUnpackColormapMessage *) message; setUnpackColormap -> client = *(buffer + 1); setUnpackColormap -> method = *(buffer + 4); setUnpackColormap -> src_length = GetULONG(buffer + 8, bigEndian); setUnpackColormap -> dst_length = GetULONG(buffer + 12, bigEndian); #ifdef DEBUG *logofs << name() << ": Parsed identity for message at " << message << ".\n" << logofs_flush; #endif return 1; }
int ChangeGCCompatStore::parseIdentity(Message *message, const unsigned char *buffer, unsigned int size, int bigEndian) const { ChangeGCCompatMessage *changeGC = (ChangeGCCompatMessage *) message; // // Here is the fingerprint. // changeGC -> gcontext = GetULONG(buffer + 4, bigEndian); changeGC -> value_mask = GetULONG(buffer + 8, bigEndian); // // Clear the unused bytes carried in the // payload to increase the effectiveness // of the caching algorithm. // if ((int) size > dataOffset) { #ifdef DEBUG *logofs << name() << ": Removing unused bytes from the " << "data payload.\n" << logofs_flush; #endif changeGC -> value_mask &= (1 << 23) - 1; unsigned int mask = 0x1; unsigned char *source = (unsigned char *) buffer + CHANGEGC_DATA_OFFSET; unsigned long value = 0; for (unsigned int i = 0; i < 23; i++) { if (changeGC -> value_mask & mask) { value = GetULONG(source, bigEndian); value &= (0xffffffff >> (32 - CREATEGC_FIELD_WIDTH[i])); PutULONG(value, source, bigEndian); source += 4; } mask <<= 1; }
static ULONG GetULONG2(LPWSTR String1, LPWSTR String2, PINT i) { ULONG Value; /* Check the first string value */ Value = GetULONG(String1); if (Value == (ULONG)-1) { /* Check the second string value isn't a switch */ if (String2[0] != L'-') { /* Check the value */ Value = GetULONG(String2); *i += 1; } } return Value; }
int GetPropertyReplyStore::encodeIdentity(EncodeBuffer &encodeBuffer, const unsigned char *buffer, const unsigned int size, int bigEndian, ChannelCache *channelCache) const { ServerCache *serverCache = (ServerCache *) channelCache; #ifdef DEBUG *logofs << name() << ": Encoding full message identity.\n" << logofs_flush; #endif unsigned char format = (unsigned int) *(buffer + 1); encodeBuffer.encodeCachedValue(format, 8, serverCache -> getPropertyFormatCache); unsigned int numBytes = GetULONG(buffer + 16, bigEndian); encodeBuffer.encodeValue(numBytes, 32, 9); if (format == 16) { numBytes <<= 1; } else if (format == 32) { numBytes <<= 2; } encodeBuffer.encodeCachedValue(GetULONG(buffer + 8, bigEndian), 29, serverCache -> getPropertyTypeCache, 9); encodeBuffer.encodeValue(GetULONG(buffer + 12, bigEndian), 32, 9); #ifdef DEBUG *logofs << name() << ": Encoded full message identity.\n" << logofs_flush; #endif return 1; }
int CreatePixmapStore::parseIdentity(Message *message, const unsigned char *buffer, unsigned int size, int bigEndian) const { CreatePixmapMessage *createPixmap = (CreatePixmapMessage *) message; createPixmap -> depth = *(buffer + 1); createPixmap -> id = GetULONG(buffer + 4, bigEndian); createPixmap -> drawable = GetULONG(buffer + 8, bigEndian); createPixmap -> width = GetUINT(buffer + 12, bigEndian); createPixmap -> height = GetUINT(buffer + 14, bigEndian); #ifdef TEST *logofs << name() << ": Parsed identity. Size is " << createPixmap -> size_ << " identity is " << createPixmap -> i_size_ << ".\n" << logofs_flush; #endif return 1; }
int GetPropertyStore::parseIdentity(Message *message, const unsigned char *buffer, unsigned int size, int bigEndian) const { GetPropertyMessage *getProperty = (GetPropertyMessage *) message; // // Here is the fingerprint. // getProperty -> property_delete = *(buffer + 1); getProperty -> window = GetULONG(buffer + 4, bigEndian); getProperty -> property = GetULONG(buffer + 8, bigEndian); getProperty -> type = GetULONG(buffer + 12, bigEndian); getProperty -> long_offset = GetULONG(buffer + 16, bigEndian); getProperty -> long_length = GetULONG(buffer + 20, bigEndian); #ifdef DEBUG *logofs << name() << ": Parsed identity for message at " << message << ".\n" << logofs_flush; #endif return 1; }
int SetUnpackColormapCompatStore::parseIdentity(Message *message, const unsigned char *buffer, unsigned int size, int bigEndian) const { SetUnpackColormapCompatMessage *setUnpackColormap = (SetUnpackColormapCompatMessage *) message; setUnpackColormap -> client = *(buffer + 1); setUnpackColormap -> entries = GetULONG(buffer + 4, bigEndian); #ifdef DEBUG *logofs << name() << ": Parsed identity for message at " << message << ".\n" << logofs_flush; #endif return 1; }
int SetClipRectanglesStore::parseIdentity(Message *message, const unsigned char *buffer, unsigned int size, int bigEndian) const { SetClipRectanglesMessage *setClipRectangles = (SetClipRectanglesMessage *) message; // // Here is the fingerprint. // setClipRectangles -> ordering = *(buffer + 1); setClipRectangles -> gcontext = GetULONG(buffer + 4, bigEndian); setClipRectangles -> x_origin = GetUINT(buffer + 8, bigEndian); setClipRectangles -> y_origin = GetUINT(buffer + 10, bigEndian); #ifdef DEBUG *logofs << name() << ": Parsed Identity for message at " << this << ".\n" << logofs_flush; #endif return 1; }
int SetUnpackColormapCompatStore::encodeIdentity(EncodeBuffer &encodeBuffer, const unsigned char *buffer, const unsigned int size, int bigEndian, ChannelCache *channelCache) const { ClientCache *clientCache = (ClientCache *) channelCache; #ifdef DEBUG *logofs << name() << ": Encoding full message identity.\n" << logofs_flush; #endif // Client. encodeBuffer.encodeCachedValue(*(buffer + 1), 8, clientCache -> resourceCache); // Entries. encodeBuffer.encodeValue(GetULONG(buffer + 4, bigEndian), 32, 9); #ifdef DEBUG *logofs << name() << ": Encoded full message identity.\n" << logofs_flush; #endif return 1; }
int ServerReadBuffer::locateMessage(const unsigned char *start, const unsigned char *end, unsigned int &controlLength, unsigned int &dataLength, unsigned int &trailerLength) { unsigned int size = end - start; #ifdef TEST *logofs << "ServerReadBuffer: Locating message for FD#" << transport_ -> fd() << " with " << size << " bytes.\n" << logofs_flush; #endif if (firstMessage_) { if (size < 8) { remaining_ = 8 - size; #ifdef TEST *logofs << "ServerReadBuffer: No message was located " << "with remaining " << remaining_ << ".\n" << logofs_flush; #endif return 0; } dataLength = 8 + (GetUINT(start + 6, bigEndian_) << 2); } else { if (size < 32) { remaining_ = 32 - size; #ifdef TEST *logofs << "ServerReadBuffer: No message was located " << "with remaining " << remaining_ << ".\n" << logofs_flush; #endif return 0; } if (*start == 1) { dataLength = 32 + (GetULONG(start + 4, bigEndian_) << 2); } else { dataLength = 32; } if (dataLength < 32) { #ifdef TEST *logofs << "ServerReadBuffer: WARNING! Assuming length 32 " << "for suspicious message of length " << dataLength << ".\n" << logofs_flush; #endif dataLength = 32; } } #ifdef TEST *logofs << "ServerReadBuffer: Length of the next message is " << dataLength << ".\n" << logofs_flush; #endif if (size < dataLength) { remaining_ = dataLength - size; #ifdef TEST *logofs << "ServerReadBuffer: No message was located " << "with remaining " << remaining_ << ".\n" << logofs_flush; #endif return 0; } firstMessage_ = 0; controlLength = 0; trailerLength = 0; remaining_ = 0; #ifdef TEST *logofs << "ServerReadBuffer: Located message with " << "remaining " << remaining_ << ".\n" << logofs_flush; #endif return 1; }
unsigned char *ServerReadBuffer::peekMessage(unsigned int &offset, unsigned char opcode, unsigned short sequence) { #ifdef TEST *logofs << "ServerReadBuffer: Peeking message " << "for FD#" << transport_ -> fd() << " with size " << length_ << " offset " << offset << " opcode " << (unsigned int) opcode << " and sequence " << sequence << ".\n" << logofs_flush; #endif if (firstMessage_) { return NULL; } unsigned char *next = buffer_ + start_ + offset; unsigned char *end = buffer_ + start_ + length_; int found = 0; while (end - next >= 32) { #ifdef DEBUG *logofs << "ServerReadBuffer: Checking opcode " << (unsigned int) *next << " sequence " << GetUINT(next + 2, bigEndian_) << " at " << next - buffer_ + start_ << ".\n" << logofs_flush; #endif if (*next == opcode && GetUINT(next + 2, bigEndian_) == sequence) { found = 1; break; } else if (*next == 1) { next += (32 + (GetULONG(next + 4, bigEndian_) << 2)); } else { next += 32; } } offset = next - buffer_ + start_; if (found == 1) { #ifdef TEST *logofs << "ServerReadBuffer: Found message at " << "offset " << next - buffer_ + start_ << ".\n" << logofs_flush; #endif return next; } #ifdef TEST *logofs << "ServerReadBuffer: Quitting loop at " << "offset " << next - buffer_ + start_ << ".\n" << logofs_flush; #endif return NULL; }