mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 03:00:06 +00:00 
			
		
		
		
	Consistent usage of ValidateMessage() in level 3 packets
This commit is contained in:
		
							parent
							
								
									7a9582a689
								
							
						
					
					
						commit
						03fdd99585
					
				
					 5 changed files with 146 additions and 102 deletions
				
			
		|  | @ -75,6 +75,8 @@ bool LinkedContourVectorPacket::Parse(std::istream& is) | ||||||
| { | { | ||||||
|    bool blockValid = true; |    bool blockValid = true; | ||||||
| 
 | 
 | ||||||
|  |    std::streampos isBegin = is.tellg(); | ||||||
|  | 
 | ||||||
|    is.read(reinterpret_cast<char*>(&p->packetCode_), 2); |    is.read(reinterpret_cast<char*>(&p->packetCode_), 2); | ||||||
|    is.read(reinterpret_cast<char*>(&p->initialPointIndicator_), 2); |    is.read(reinterpret_cast<char*>(&p->initialPointIndicator_), 2); | ||||||
|    is.read(reinterpret_cast<char*>(&p->startI_), 2); |    is.read(reinterpret_cast<char*>(&p->startI_), 2); | ||||||
|  | @ -89,28 +91,6 @@ bool LinkedContourVectorPacket::Parse(std::istream& is) | ||||||
| 
 | 
 | ||||||
|    int vectorSize = static_cast<int>(p->lengthOfVectors_); |    int vectorSize = static_cast<int>(p->lengthOfVectors_); | ||||||
| 
 | 
 | ||||||
|    if (is.eof()) |  | ||||||
|    { |  | ||||||
|       BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; |  | ||||||
|       blockValid = false; |  | ||||||
|    } |  | ||||||
| 
 |  | ||||||
|    // The number of vectors is equal to the size divided by the number of bytes
 |  | ||||||
|    // in a vector coordinate
 |  | ||||||
|    int vectorCount = vectorSize / 4; |  | ||||||
| 
 |  | ||||||
|    p->endI_.resize(vectorCount); |  | ||||||
|    p->endJ_.resize(vectorCount); |  | ||||||
| 
 |  | ||||||
|    for (int v = 0; v < vectorCount && !is.eof(); v++) |  | ||||||
|    { |  | ||||||
|       is.read(reinterpret_cast<char*>(&p->endI_[v]), 2); |  | ||||||
|       is.read(reinterpret_cast<char*>(&p->endJ_[v]), 2); |  | ||||||
| 
 |  | ||||||
|       p->endI_[v] = ntohs(p->endI_[v]); |  | ||||||
|       p->endJ_[v] = ntohs(p->endJ_[v]); |  | ||||||
|    } |  | ||||||
| 
 |  | ||||||
|    if (is.eof()) |    if (is.eof()) | ||||||
|    { |    { | ||||||
|       BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; |       BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; | ||||||
|  | @ -133,6 +113,33 @@ bool LinkedContourVectorPacket::Parse(std::istream& is) | ||||||
|       } |       } | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|  |    if (blockValid) | ||||||
|  |    { | ||||||
|  |       // The number of vectors is equal to the size divided by the number of
 | ||||||
|  |       // bytes in a vector coordinate
 | ||||||
|  |       int vectorCount = vectorSize / 4; | ||||||
|  | 
 | ||||||
|  |       p->endI_.resize(vectorCount); | ||||||
|  |       p->endJ_.resize(vectorCount); | ||||||
|  | 
 | ||||||
|  |       for (int v = 0; v < vectorCount && !is.eof(); v++) | ||||||
|  |       { | ||||||
|  |          is.read(reinterpret_cast<char*>(&p->endI_[v]), 2); | ||||||
|  |          is.read(reinterpret_cast<char*>(&p->endJ_[v]), 2); | ||||||
|  | 
 | ||||||
|  |          p->endI_[v] = ntohs(p->endI_[v]); | ||||||
|  |          p->endJ_[v] = ntohs(p->endJ_[v]); | ||||||
|  |       } | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  |    std::streampos isEnd     = is.tellg(); | ||||||
|  |    std::streamoff bytesRead = isEnd - isBegin; | ||||||
|  | 
 | ||||||
|  |    if (!ValidateMessage(is, bytesRead)) | ||||||
|  |    { | ||||||
|  |       blockValid = false; | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|    return blockValid; |    return blockValid; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -81,6 +81,8 @@ bool LinkedVectorPacket::Parse(std::istream& is) | ||||||
| { | { | ||||||
|    bool blockValid = true; |    bool blockValid = true; | ||||||
| 
 | 
 | ||||||
|  |    std::streampos isBegin = is.tellg(); | ||||||
|  | 
 | ||||||
|    is.read(reinterpret_cast<char*>(&p->packetCode_), 2); |    is.read(reinterpret_cast<char*>(&p->packetCode_), 2); | ||||||
|    is.read(reinterpret_cast<char*>(&p->lengthOfBlock_), 2); |    is.read(reinterpret_cast<char*>(&p->lengthOfBlock_), 2); | ||||||
| 
 | 
 | ||||||
|  | @ -101,15 +103,26 @@ bool LinkedVectorPacket::Parse(std::istream& is) | ||||||
| 
 | 
 | ||||||
|       vectorSize -= 2; |       vectorSize -= 2; | ||||||
|    } |    } | ||||||
|  |    else | ||||||
|  |    { | ||||||
|  |       if (p->packetCode_ != 6 && p->packetCode_ != 9) | ||||||
|  |       { | ||||||
|  |          BOOST_LOG_TRIVIAL(warning) | ||||||
|  |             << logPrefix_ << "Invalid packet code: " << p->packetCode_; | ||||||
|  |          blockValid = false; | ||||||
|  |       } | ||||||
|  |    } | ||||||
| 
 | 
 | ||||||
|  |    if (blockValid) | ||||||
|  |    { | ||||||
|       is.read(reinterpret_cast<char*>(&p->startI_), 2); |       is.read(reinterpret_cast<char*>(&p->startI_), 2); | ||||||
|       is.read(reinterpret_cast<char*>(&p->startJ_), 2); |       is.read(reinterpret_cast<char*>(&p->startJ_), 2); | ||||||
| 
 | 
 | ||||||
|       p->startI_ = ntohs(p->startI_); |       p->startI_ = ntohs(p->startI_); | ||||||
|       p->startJ_ = ntohs(p->startJ_); |       p->startJ_ = ntohs(p->startJ_); | ||||||
| 
 | 
 | ||||||
|    // The number of vectors is equal to the size divided by the number of bytes
 |       // The number of vectors is equal to the size divided by the number of
 | ||||||
|    // in a vector coordinate
 |       // bytes in a vector coordinate
 | ||||||
|       int vectorCount = vectorSize / 4; |       int vectorCount = vectorSize / 4; | ||||||
| 
 | 
 | ||||||
|       p->endI_.resize(vectorCount); |       p->endI_.resize(vectorCount); | ||||||
|  | @ -123,21 +136,15 @@ bool LinkedVectorPacket::Parse(std::istream& is) | ||||||
|          p->endI_[v] = ntohs(p->endI_[v]); |          p->endI_[v] = ntohs(p->endI_[v]); | ||||||
|          p->endJ_[v] = ntohs(p->endJ_[v]); |          p->endJ_[v] = ntohs(p->endJ_[v]); | ||||||
|       } |       } | ||||||
|  |    } | ||||||
| 
 | 
 | ||||||
|    if (is.eof()) |    std::streampos isEnd     = is.tellg(); | ||||||
|  |    std::streamoff bytesRead = isEnd - isBegin; | ||||||
|  | 
 | ||||||
|  |    if (!ValidateMessage(is, bytesRead)) | ||||||
|    { |    { | ||||||
|       BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; |  | ||||||
|       blockValid = false; |       blockValid = false; | ||||||
|    } |    } | ||||||
|    else |  | ||||||
|    { |  | ||||||
|       if (p->packetCode_ != 6 && p->packetCode_ != 9) |  | ||||||
|       { |  | ||||||
|          BOOST_LOG_TRIVIAL(warning) |  | ||||||
|             << logPrefix_ << "Invalid packet code: " << p->packetCode_; |  | ||||||
|          blockValid = false; |  | ||||||
|       } |  | ||||||
|    } |  | ||||||
| 
 | 
 | ||||||
|    return blockValid; |    return blockValid; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -64,6 +64,8 @@ bool SetColorLevelPacket::Parse(std::istream& is) | ||||||
| { | { | ||||||
|    bool blockValid = true; |    bool blockValid = true; | ||||||
| 
 | 
 | ||||||
|  |    std::streampos isBegin = is.tellg(); | ||||||
|  | 
 | ||||||
|    is.read(reinterpret_cast<char*>(&p->packetCode_), 2); |    is.read(reinterpret_cast<char*>(&p->packetCode_), 2); | ||||||
|    is.read(reinterpret_cast<char*>(&p->colorValueIndicator_), 2); |    is.read(reinterpret_cast<char*>(&p->colorValueIndicator_), 2); | ||||||
|    is.read(reinterpret_cast<char*>(&p->valueOfContour_), 2); |    is.read(reinterpret_cast<char*>(&p->valueOfContour_), 2); | ||||||
|  | @ -94,6 +96,14 @@ bool SetColorLevelPacket::Parse(std::istream& is) | ||||||
|       } |       } | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|  |    std::streampos isEnd     = is.tellg(); | ||||||
|  |    std::streamoff bytesRead = isEnd - isBegin; | ||||||
|  | 
 | ||||||
|  |    if (!ValidateMessage(is, bytesRead)) | ||||||
|  |    { | ||||||
|  |       blockValid = false; | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|    return blockValid; |    return blockValid; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -70,16 +70,35 @@ bool UnlinkedContourVectorPacket::Parse(std::istream& is) | ||||||
| { | { | ||||||
|    bool blockValid = true; |    bool blockValid = true; | ||||||
| 
 | 
 | ||||||
|  |    std::streampos isBegin = is.tellg(); | ||||||
|  | 
 | ||||||
|    is.read(reinterpret_cast<char*>(&p->packetCode_), 2); |    is.read(reinterpret_cast<char*>(&p->packetCode_), 2); | ||||||
|    is.read(reinterpret_cast<char*>(&p->lengthOfVectors_), 2); |    is.read(reinterpret_cast<char*>(&p->lengthOfVectors_), 2); | ||||||
| 
 | 
 | ||||||
|    p->packetCode_      = ntohs(p->packetCode_); |    p->packetCode_      = ntohs(p->packetCode_); | ||||||
|    p->lengthOfVectors_ = ntohs(p->lengthOfVectors_); |    p->lengthOfVectors_ = ntohs(p->lengthOfVectors_); | ||||||
| 
 | 
 | ||||||
|  |    if (is.eof()) | ||||||
|  |    { | ||||||
|  |       BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; | ||||||
|  |       blockValid = false; | ||||||
|  |    } | ||||||
|  |    else | ||||||
|  |    { | ||||||
|  |       if (p->packetCode_ != 0x3501) | ||||||
|  |       { | ||||||
|  |          BOOST_LOG_TRIVIAL(warning) | ||||||
|  |             << logPrefix_ << "Invalid packet code: " << p->packetCode_; | ||||||
|  |          blockValid = false; | ||||||
|  |       } | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  |    if (blockValid) | ||||||
|  |    { | ||||||
|       int vectorSize = static_cast<int>(p->lengthOfVectors_); |       int vectorSize = static_cast<int>(p->lengthOfVectors_); | ||||||
| 
 | 
 | ||||||
|    // The number of vectors is equal to the size divided by the number of bytes
 |       // The number of vectors is equal to the size divided by the number of
 | ||||||
|    // in a vector
 |       // bytes in a vector
 | ||||||
|       int vectorCount = vectorSize / 8; |       int vectorCount = vectorSize / 8; | ||||||
| 
 | 
 | ||||||
|       p->beginI_.resize(vectorCount); |       p->beginI_.resize(vectorCount); | ||||||
|  | @ -99,21 +118,15 @@ bool UnlinkedContourVectorPacket::Parse(std::istream& is) | ||||||
|          p->endI_[v]   = ntohs(p->endI_[v]); |          p->endI_[v]   = ntohs(p->endI_[v]); | ||||||
|          p->endJ_[v]   = ntohs(p->endJ_[v]); |          p->endJ_[v]   = ntohs(p->endJ_[v]); | ||||||
|       } |       } | ||||||
|  |    } | ||||||
| 
 | 
 | ||||||
|    if (is.eof()) |    std::streampos isEnd     = is.tellg(); | ||||||
|  |    std::streamoff bytesRead = isEnd - isBegin; | ||||||
|  | 
 | ||||||
|  |    if (!ValidateMessage(is, bytesRead)) | ||||||
|    { |    { | ||||||
|       BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; |  | ||||||
|       blockValid = false; |       blockValid = false; | ||||||
|    } |    } | ||||||
|    else |  | ||||||
|    { |  | ||||||
|       if (p->packetCode_ != 0x3501) |  | ||||||
|       { |  | ||||||
|          BOOST_LOG_TRIVIAL(warning) |  | ||||||
|             << logPrefix_ << "Invalid packet code: " << p->packetCode_; |  | ||||||
|          blockValid = false; |  | ||||||
|       } |  | ||||||
|    } |  | ||||||
| 
 | 
 | ||||||
|    return blockValid; |    return blockValid; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -82,6 +82,8 @@ bool UnlinkedVectorPacket::Parse(std::istream& is) | ||||||
| { | { | ||||||
|    bool blockValid = true; |    bool blockValid = true; | ||||||
| 
 | 
 | ||||||
|  |    std::streampos isBegin = is.tellg(); | ||||||
|  | 
 | ||||||
|    is.read(reinterpret_cast<char*>(&p->packetCode_), 2); |    is.read(reinterpret_cast<char*>(&p->packetCode_), 2); | ||||||
|    is.read(reinterpret_cast<char*>(&p->lengthOfBlock_), 2); |    is.read(reinterpret_cast<char*>(&p->lengthOfBlock_), 2); | ||||||
| 
 | 
 | ||||||
|  | @ -102,9 +104,20 @@ bool UnlinkedVectorPacket::Parse(std::istream& is) | ||||||
| 
 | 
 | ||||||
|       vectorSize -= 2; |       vectorSize -= 2; | ||||||
|    } |    } | ||||||
|  |    else | ||||||
|  |    { | ||||||
|  |       if (p->packetCode_ != 7 && p->packetCode_ != 10) | ||||||
|  |       { | ||||||
|  |          BOOST_LOG_TRIVIAL(warning) | ||||||
|  |             << logPrefix_ << "Invalid packet code: " << p->packetCode_; | ||||||
|  |          blockValid = false; | ||||||
|  |       } | ||||||
|  |    } | ||||||
| 
 | 
 | ||||||
|    // The number of vectors is equal to the size divided by the number of bytes
 |    if (blockValid) | ||||||
|    // in a vector
 |    { | ||||||
|  |       // The number of vectors is equal to the size divided by the number of
 | ||||||
|  |       // bytes in a vector
 | ||||||
|       int vectorCount = vectorSize / 8; |       int vectorCount = vectorSize / 8; | ||||||
| 
 | 
 | ||||||
|       p->beginI_.resize(vectorCount); |       p->beginI_.resize(vectorCount); | ||||||
|  | @ -124,21 +137,15 @@ bool UnlinkedVectorPacket::Parse(std::istream& is) | ||||||
|          p->endI_[v]   = ntohs(p->endI_[v]); |          p->endI_[v]   = ntohs(p->endI_[v]); | ||||||
|          p->endJ_[v]   = ntohs(p->endJ_[v]); |          p->endJ_[v]   = ntohs(p->endJ_[v]); | ||||||
|       } |       } | ||||||
|  |    } | ||||||
| 
 | 
 | ||||||
|    if (is.eof()) |    std::streampos isEnd     = is.tellg(); | ||||||
|  |    std::streamoff bytesRead = isEnd - isBegin; | ||||||
|  | 
 | ||||||
|  |    if (!ValidateMessage(is, bytesRead)) | ||||||
|    { |    { | ||||||
|       BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; |  | ||||||
|       blockValid = false; |       blockValid = false; | ||||||
|    } |    } | ||||||
|    else |  | ||||||
|    { |  | ||||||
|       if (p->packetCode_ != 7 && p->packetCode_ != 10) |  | ||||||
|       { |  | ||||||
|          BOOST_LOG_TRIVIAL(warning) |  | ||||||
|             << logPrefix_ << "Invalid packet code: " << p->packetCode_; |  | ||||||
|          blockValid = false; |  | ||||||
|       } |  | ||||||
|    } |  | ||||||
| 
 | 
 | ||||||
|    return blockValid; |    return blockValid; | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat