bool OperationPlan::updateFeasible() { if (!getOperation()->getDetectProblems()) { // No problems to be flagged on this operation setFeasible(true); return true; } // The implementation of this method isn't really cleanly object oriented. It uses // logic which only the different resource and buffer implementation classes should be // aware. if (firstsubopplan) { // Check feasibility of child operationplans for (OperationPlan *i = firstsubopplan; i; i = i->nextsubopplan) { if (!i->updateFeasible()) { setFeasible(false); return false; } } } else { // Before current and before fence problems are only detected on child operationplans if (getConfirmed()) { if (dates.getEnd() < Plan::instance().getCurrent()) { // Before current violation setFeasible(false); return false; } } else { if (dates.getStart() < Plan::instance().getCurrent()) { // Before current violation setFeasible(false); return false; } else if (dates.getStart() < Plan::instance().getCurrent() + oper->getFence() && getProposed()) { // Before fence violation setFeasible(false); return false; } } } if (nextsubopplan && getEnd() > nextsubopplan->getStart() + Duration(1L) && !nextsubopplan->getConfirmed() && owner && !owner->getOperation()->hasType<OperationSplit>() ) { // Precedence violation // Note: 1 second grace period for precedence problems to avoid rounding issues setFeasible(false); return false; } // Verify the capacity constraints for (auto ldplan = getLoadPlans(); ldplan != endLoadPlans(); ++ldplan) { if (ldplan->getResource()->hasType<ResourceDefault>() && ldplan->getQuantity() > 0) { auto curMax = ldplan->getMax(); for ( auto cur = ldplan->getResource()->getLoadPlans().begin(&*ldplan); cur != ldplan->getResource()->getLoadPlans().end(); ++cur ) { if (cur->getOperationPlan() == this && cur->getQuantity() < 0) break; if (cur->getEventType() == 4) curMax = cur->getMax(false); if ( cur->getEventType() != 5 && cur->isLastOnDate() && cur->getOnhand() > curMax + ROUNDING_ERROR ) { // Overload on default resource setFeasible(false); return false; } } } else if (ldplan->getResource()->hasType<ResourceBuckets>()) { for ( auto cur = ldplan->getResource()->getLoadPlans().begin(&*ldplan); cur != ldplan->getResource()->getLoadPlans().end() && cur->getEventType() != 2; ++cur ) { if (cur->getOnhand() < -ROUNDING_ERROR) { // Overloaded capacity on bucketized resource setFeasible(false); return false; } } } } // Verify the material constraints for (auto flplan = beginFlowPlans(); flplan != endFlowPlans(); ++flplan) { if ( !flplan->getFlow()->isConsumer() || flplan->getBuffer()->hasType<BufferInfinite>() ) continue; auto flplaniter = flplan->getBuffer()->getFlowPlans(); for (auto cur = flplaniter.begin(&*flplan); cur != flplaniter.end(); ++cur) { if (cur->getOnhand() < -ROUNDING_ERROR && cur->isLastOnDate()) { // Material shortage setFeasible(false); return false; } } } // After all checks, it turns out to be feasible setFeasible(true); return true; }
bool TcpPacket::parsePacket() { memcpy (&header, buffer, sizeof (TCP_HEADER)); // // check for correct header values to make sure the packet is not corrupt // if is is corrupt we will stop the parsing here and return // header.headerlen_flags = swap16 (header.headerlen_flags); if (! ( TCP_HEADER_NO_OPTIONS_LEN <= getHeaderlength() && getHeaderlength() <= getSize() )) { layersize = getSize (); nextProtocol = Packet::PROTO_NONE; options.size = 0; options.buf = NULL; return true; } // // get the options, if any are provided // options.size = getHeaderlength() - TCP_HEADER_NO_OPTIONS_LEN; options.buf = NULL; if (options.size > 0 && getSize() >= TCP_HEADER_NO_OPTIONS_LEN + options.size) { options.buf = (uint8_t*) malloc (options.size); memcpy (options.buf, buffer + TCP_HEADER_NO_OPTIONS_LEN, options.size); } else options.size = 0; nextProtocol = Packet::PROTO_DATA_PAYLOAD; layersize = sizeof (TCP_HEADER) + options.size; header.headerlen_flags = swap16 (header.headerlen_flags); // // check for correct checksum // if (Configuration::instance()->getSetBadChecksumsToBad ()) { uint16_t chksum = header.checksum; header.checksum = 0; void* pipsource = (ipProtocol == Packet::PROTO_IP ? (void*)&sourceip : (void*)&sourceip6); void* pipdest = (ipProtocol == Packet::PROTO_IP ? (void*)&destip : (void*)&destip6 ); this->checksumgood = (checksum (&header, pipsource, pipdest, ipProtocol, options.buf, options.size, getBuffer () + layersize, getSize () - layersize ) == chksum); header.checksum = chksum; } // if (Configuration::instance()->getSetBadChecksumsToBad ()) // // swap some values // header.acknum = swap32(header.acknum ); header.checksum = swap16(header.checksum ); header.destport = swap16(header.destport ); header.headerlen_flags = swap16(header.headerlen_flags ); header.sequencenum = swap32(header.sequencenum ); header.sourceport = swap16(header.sourceport ); header.urgentpointer = swap16(header.urgentpointer ); header.windowsize = swap16(header.windowsize ); return true; }
int bbcp_File::Passthru(bbcp_BuffPool* iBP, bbcp_BuffPool* oBP, bbcp_FileChkSum* csP, int nstrms) { bbcp_Buffer* outbuff; bbcp_ChkSum* csObj; long long Offset = nextoffset; int csLen, csVer, numadd, maxbufs, maxadds = nstrms; int rc = 0, unordered = !(bbcp_Config.Options & bbcp_ORDER); // Determine if we will be piggy-backing checksumming here // if (csP && (csObj = csP->csObj)) { csVer = csP->csVer; csLen = csObj->csSize(); } else csVer = csLen = 0; // Record the maximum number of buffers we have here // maxbufs = iBP->BuffCount(); numadd = nstrms + 1; // Read all of the data until eof (note that we are single threaded) // while (nstrms) { // Obtain a full buffer // if (!(outbuff = iBP->getFullBuff())) break; // Check if this is an eof marker // // cerr <<nstrms <<" Passt " <<outbuff->blen <<'@' <<outbuff->boff <<endl; if (!(outbuff->blen)) { iBP->putEmptyBuff(outbuff); nstrms--; continue; } // Do an unordered write if allowed // if (unordered) { oBP->putFullBuff(outbuff); continue; } // Check if this buffer is in the correct sequence // if (outbuff->boff != Offset) { if (outbuff->boff < 0) { rc = -ESPIPE; break; } outbuff->next = nextbuff; nextbuff = outbuff; bufreorders++; if (++curq > maxreorders) { maxreorders = curq; DEBUG("Buff disorder " << curq << " rcvd " << outbuff->boff << " want " << Offset); } if (curq >= maxbufs - nstrms) { if (!(--maxadds)) { rc = -ENOBUFS; break; } DEBUG("Too few buffs; adding " << numadd << " more; " << maxadds << " tries left."); bbcp_BPool.Allocate(numadd); maxbufs += numadd; } continue; } // Pass through any queued buffers // do { Offset += outbuff->blen; if (csObj) { csObj->Update(outbuff->data, outbuff->blen); if (csVer && memcmp(outbuff->bHdr.cksm, csObj->csCurr(), csLen)) { char buff[32]; sprintf(buff, "%lld", outbuff->boff); bbcp_Fmsg("Write", iofn, "xfr checksum error at offset", buff); rc = -EILSEQ; nstrms = 0; break; } } oBP->putFullBuff(outbuff); } while (nextbuff && (outbuff = getBuffer(Offset))); } // Check if we should print an error here // if (rc && rc != -EILSEQ) bbcp_Emsg("Write", rc, "unable to write", iofn); // Queue an empty buffer indicating eof or abort the stream // if (!rc && (outbuff = iBP->getEmptyBuff())) { outbuff->blen = 0; outbuff->boff = Offset; oBP->putFullBuff(outbuff); } else { if (!rc) rc = -ENOBUFS; oBP->Abort(); iBP->Abort(); } // All done // return rc; }
void BufferedTextOutput::pushBundle() { AutoMutex _l(mLock); BufferState* b = getBuffer(); b->bundle++; }
GpuMat getBuffer(Size size, int type) { return getBuffer(size.height, size.width, type); }
void pcl::gpu::kinfuLS::CyclicalBuffer::performShift (const TsdfVolume::Ptr volume, const pcl::PointXYZ &target_point, const bool last_shift) { // compute new origin and offsets int offset_x, offset_y, offset_z; computeAndSetNewCubeMetricOrigin (target_point, offset_x, offset_y, offset_z); // extract current slice from the TSDF volume (coordinates are in indices! (see fetchSliceAsCloud() ) DeviceArray<PointXYZ> points; DeviceArray<float> intensities; int size; if(!last_shift) { size = volume->fetchSliceAsCloud (cloud_buffer_device_xyz_, cloud_buffer_device_intensities_, &buffer_, offset_x, offset_y, offset_z); } else { size = volume->fetchSliceAsCloud (cloud_buffer_device_xyz_, cloud_buffer_device_intensities_, &buffer_, buffer_.voxels_size.x - 1, buffer_.voxels_size.y - 1, buffer_.voxels_size.z - 1); } points = DeviceArray<PointXYZ> (cloud_buffer_device_xyz_.ptr (), size); intensities = DeviceArray<float> (cloud_buffer_device_intensities_.ptr(), size); PointCloud<PointXYZI>::Ptr current_slice (new PointCloud<PointXYZI>); PointCloud<PointXYZ>::Ptr current_slice_xyz (new PointCloud<PointXYZ>); PointCloud<PointIntensity>::Ptr current_slice_intensities (new PointCloud<PointIntensity>); // Retrieving XYZ points.download (current_slice_xyz->points); current_slice_xyz->width = (int) current_slice_xyz->points.size (); current_slice_xyz->height = 1; // Retrieving intensities // TODO change this mechanism by using PointIntensity directly (in spite of float) // when tried, this lead to wrong intenisty values being extracted by fetchSliceAsCloud () (padding pbls?) std::vector<float , Eigen::aligned_allocator<float> > intensities_vector; intensities.download (intensities_vector); current_slice_intensities->points.resize (current_slice_xyz->points.size ()); for(size_t i = 0 ; i < current_slice_intensities->points.size () ; ++i) current_slice_intensities->points[i].intensity = intensities_vector[i]; current_slice_intensities->width = (int) current_slice_intensities->points.size (); current_slice_intensities->height = 1; // Concatenating XYZ and Intensities pcl::concatenateFields (*current_slice_xyz, *current_slice_intensities, *current_slice); current_slice->width = (int) current_slice->points.size (); current_slice->height = 1; // transform the slice from local to global coordinates Eigen::Affine3f global_cloud_transformation; global_cloud_transformation.translation ()[0] = buffer_.origin_GRID_global.x; global_cloud_transformation.translation ()[1] = buffer_.origin_GRID_global.y; global_cloud_transformation.translation ()[2] = buffer_.origin_GRID_global.z; global_cloud_transformation.linear () = Eigen::Matrix3f::Identity (); transformPointCloud (*current_slice, *current_slice, global_cloud_transformation); // retrieve existing data from the world model PointCloud<PointXYZI>::Ptr previously_existing_slice (new PointCloud<PointXYZI>); world_model_.getExistingData (buffer_.origin_GRID_global.x, buffer_.origin_GRID_global.y, buffer_.origin_GRID_global.z, offset_x, offset_y, offset_z, buffer_.voxels_size.x - 1, buffer_.voxels_size.y - 1, buffer_.voxels_size.z - 1, *previously_existing_slice); //replace world model data with values extracted from the TSDF buffer slice world_model_.setSliceAsNans (buffer_.origin_GRID_global.x, buffer_.origin_GRID_global.y, buffer_.origin_GRID_global.z, offset_x, offset_y, offset_z, buffer_.voxels_size.x, buffer_.voxels_size.y, buffer_.voxels_size.z); PCL_INFO ("world contains %d points after update\n", world_model_.getWorldSize ()); world_model_.cleanWorldFromNans (); PCL_INFO ("world contains %d points after cleaning\n", world_model_.getWorldSize ()); // clear buffer slice and update the world model pcl::device::kinfuLS::clearTSDFSlice (volume->data (), &buffer_, offset_x, offset_y, offset_z); // insert current slice in the world if it contains any points if (current_slice->points.size () != 0) { world_model_.addSlice(current_slice); } // shift buffer addresses shiftOrigin (volume, offset_x, offset_y, offset_z); // push existing data in the TSDF buffer if (previously_existing_slice->points.size () != 0 ) { volume->pushSlice(previously_existing_slice, getBuffer () ); } }
bool QMakeSourceFileInfo::findMocs(SourceFile *file) { if(file->moc_checked) return true; files_changed = true; file->moc_checked = true; int buffer_len; char *buffer = 0; { struct stat fst; int fd; #if defined(_MSC_VER) && _MSC_VER >= 1400 if (_sopen_s(&fd, fixPathForFile(file->file, true).local().toLocal8Bit().constData(), _O_RDONLY, _SH_DENYRW, _S_IREAD) != 0) fd = -1; #else fd = open(fixPathForFile(file->file, true).local().toLocal8Bit().constData(), O_RDONLY); #endif if(fd == -1 || fstat(fd, &fst) || S_ISDIR(fst.st_mode)) return false; //shouldn't happen buffer = getBuffer(fst.st_size); for(int have_read = buffer_len = 0; (have_read = QT_READ(fd, buffer + buffer_len, fst.st_size - buffer_len)); buffer_len += have_read); QT_CLOSE(fd); } debug_msg(2, "findMocs: %s", file->file.local().toLatin1().constData()); int line_count = 1; bool ignore_qobject = false, ignore_qgadget = false; /* qmake ignore Q_GADGET */ /* qmake ignore Q_OBJECT */ for(int x = 0; x < buffer_len; x++) { if(*(buffer + x) == '/') { ++x; if(buffer_len >= x) { if(*(buffer + x) == '/') { //c++ style comment for(;x < buffer_len && !qmake_endOfLine(*(buffer + x)); ++x); } else if(*(buffer + x) == '*') { //c style comment for(++x; x < buffer_len; ++x) { if(*(buffer + x) == 't' || *(buffer + x) == 'q') { //ignore if(buffer_len >= (x + 20) && !strncmp(buffer + x + 1, "make ignore Q_OBJECT", 20)) { debug_msg(2, "Mocgen: %s:%d Found \"qmake ignore Q_OBJECT\"", file->file.real().toLatin1().constData(), line_count); x += 20; ignore_qobject = true; } else if(buffer_len >= (x + 20) && !strncmp(buffer + x + 1, "make ignore Q_GADGET", 20)) { debug_msg(2, "Mocgen: %s:%d Found \"qmake ignore Q_GADGET\"", file->file.real().toLatin1().constData(), line_count); x += 20; ignore_qgadget = true; } } else if(*(buffer + x) == '*') { if(buffer_len >= (x+1) && *(buffer + (x+1)) == '/') { ++x; break; } } else if(Option::debug_level && qmake_endOfLine(*(buffer + x))) { ++line_count; } } } } } else if(*(buffer+x) == '\'' || *(buffer+x) == '"') { const char term = *(buffer+(x++)); while(x < buffer_len) { if(*(buffer+x) == term) break; if(*(buffer+x) == '\\') { x+=2; } else { if(qmake_endOfLine(*(buffer+x))) ++line_count; ++x; } } } if(Option::debug_level && qmake_endOfLine(*(buffer+x))) ++line_count; if(((buffer_len > x+2 && *(buffer+x+1) == 'Q' && *(buffer+x+2) == '_') || (buffer_len > x+4 && *(buffer+x+1) == 'Q' && *(buffer+x+2) == 'O' && *(buffer+x+3) == 'M' && *(buffer+x+4) == '_')) && *(buffer + x) != '_' && (*(buffer + x) < 'a' || *(buffer + x) > 'z') && (*(buffer + x) < 'A' || *(buffer + x) > 'Z') && (*(buffer + x) < '0' || *(buffer + x) > '9')) { ++x; int match = 0; static const char *interesting[] = { "OBJECT", "GADGET", "M_OBJECT" }; for(int interest = 0, m1, m2; interest < 3; ++interest) { if(interest == 0 && ignore_qobject) continue; else if(interest == 1 && ignore_qgadget) continue; for(m1 = 0, m2 = 0; *(interesting[interest]+m1); ++m1) { if(*(interesting[interest]+m1) != *(buffer+x+2+m1)) { m2 = -1; break; } ++m2; } if(m1 == m2) { match = m2 + 2; break; } } if(match && *(buffer+x+match) != '_' && (*(buffer+x+match) < 'a' || *(buffer+x+match) > 'z') && (*(buffer+x+match) < 'A' || *(buffer+x+match) > 'Z') && (*(buffer+x+match) < '0' || *(buffer+x+match) > '9')) { if(Option::debug_level) { *(buffer+x+match) = '\0'; debug_msg(2, "Mocgen: %s:%d Found MOC symbol %s", file->file.real().toLatin1().constData(), line_count, buffer+x); } file->mocable = true; return true; } } } return true; }
//* Creation / loading methods ******************************************** void GLTexture::createInternalResourcesImpl(void) { if (!GLEW_VERSION_1_2 && mTextureType == TEX_TYPE_3D) OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "3D Textures not supported before OpenGL 1.2", "GLTexture::createInternalResourcesImpl"); if (!GLEW_VERSION_2_0 && mTextureType == TEX_TYPE_2D_ARRAY) OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "2D texture arrays not supported before OpenGL 2.0", "GLTexture::createInternalResourcesImpl"); // Convert to nearest power-of-two size if required mWidth = GLPixelUtil::optionalPO2(mWidth); mHeight = GLPixelUtil::optionalPO2(mHeight); mDepth = GLPixelUtil::optionalPO2(mDepth); // Adjust format if required mFormat = TextureManager::getSingleton().getNativeFormat(mTextureType, mFormat, mUsage); // Check requested number of mipmaps size_t maxMips = GLPixelUtil::getMaxMipmaps(mWidth, mHeight, mDepth, mFormat); mNumMipmaps = mNumRequestedMipmaps; if(mNumMipmaps>maxMips) mNumMipmaps = maxMips; // Generate texture name glGenTextures( 1, &mTextureID ); // Set texture type glBindTexture( getGLTextureTarget(), mTextureID ); // This needs to be set otherwise the texture doesn't get rendered if (GLEW_VERSION_1_2) glTexParameteri( getGLTextureTarget(), GL_TEXTURE_MAX_LEVEL, mNumMipmaps ); // Set some misc default parameters so NVidia won't complain, these can of course be changed later glTexParameteri(getGLTextureTarget(), GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(getGLTextureTarget(), GL_TEXTURE_MAG_FILTER, GL_NEAREST); if (GLEW_VERSION_1_2) { glTexParameteri(getGLTextureTarget(), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(getGLTextureTarget(), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } // If we can do automip generation and the user desires this, do so mMipmapsHardwareGenerated = Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_AUTOMIPMAP); // NVIDIA 175.16 drivers break hardware mip generation for non-compressed // textures - disable until fixed // Leave hardware gen on compressed textures since that's the only way we // can realistically do it since GLU doesn't support DXT // However DON'T do this on Apple, their drivers aren't subject to this // problem yet and in fact software generation appears to cause a crash // in some cases which I've yet to track down #if OGRE_PLATFORM != OGRE_PLATFORM_APPLE if (Root::getSingleton().getRenderSystem()->getCapabilities()->getVendor() == GPU_NVIDIA && !PixelUtil::isCompressed(mFormat)) { mMipmapsHardwareGenerated = false; } #endif if((mUsage & TU_AUTOMIPMAP) && mNumRequestedMipmaps && mMipmapsHardwareGenerated) { glTexParameteri( getGLTextureTarget(), GL_GENERATE_MIPMAP, GL_TRUE ); } // Allocate internal buffer so that glTexSubImageXD can be used // Internal format GLenum format = GLPixelUtil::getClosestGLInternalFormat(mFormat, mHwGamma); size_t width = mWidth; size_t height = mHeight; size_t depth = mDepth; if(PixelUtil::isCompressed(mFormat)) { // Compressed formats size_t size = PixelUtil::getMemorySize(mWidth, mHeight, mDepth, mFormat); // Provide temporary buffer filled with zeroes as glCompressedTexImageXD does not // accept a 0 pointer like normal glTexImageXD // Run through this process for every mipmap to pregenerate mipmap piramid uint8 *tmpdata = new uint8[size]; memset(tmpdata, 0, size); for(size_t mip=0; mip<=mNumMipmaps; mip++) { size = PixelUtil::getMemorySize(width, height, depth, mFormat); switch(mTextureType) { case TEX_TYPE_1D: glCompressedTexImage1DARB(GL_TEXTURE_1D, mip, format, width, 0, size, tmpdata); break; case TEX_TYPE_2D: glCompressedTexImage2DARB(GL_TEXTURE_2D, mip, format, width, height, 0, size, tmpdata); break; case TEX_TYPE_2D_ARRAY: case TEX_TYPE_3D: glCompressedTexImage3DARB(getGLTextureTarget(), mip, format, width, height, depth, 0, size, tmpdata); break; case TEX_TYPE_CUBE_MAP: for(int face=0; face<6; face++) { glCompressedTexImage2DARB(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, mip, format, width, height, 0, size, tmpdata); } break; }; if(width>1) width = width/2; if(height>1) height = height/2; if(depth>1 && mTextureType != TEX_TYPE_2D_ARRAY) depth = depth/2; } delete [] tmpdata; } else { // Run through this process to pregenerate mipmap pyramid for(size_t mip=0; mip<=mNumMipmaps; mip++) { // Normal formats switch(mTextureType) { case TEX_TYPE_1D: glTexImage1D(GL_TEXTURE_1D, mip, format, width, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); break; case TEX_TYPE_2D: glTexImage2D(GL_TEXTURE_2D, mip, format, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); break; case TEX_TYPE_2D_ARRAY: case TEX_TYPE_3D: glTexImage3D(getGLTextureTarget(), mip, format, width, height, depth, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); break; case TEX_TYPE_CUBE_MAP: for(int face=0; face<6; face++) { glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, mip, format, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); } break; }; if(width>1) width = width/2; if(height>1) height = height/2; if(depth>1 && mTextureType != TEX_TYPE_2D_ARRAY) depth = depth/2; } } _createSurfaceList(); // Get final internal format mFormat = getBuffer(0,0)->getFormat(); }
/* * extract byte value from data * * Return 1 if successfully extract value. * Return < 0 if fail to extract value. */ int extractValueInternal(void *p, ByteData *byteData, uint32_t *value, const uint8_t *cursor) { char byteArray[BYTE_STRING_LEN]; uint32_t i; char *endPtr; uint32_t extracted = 0; int base = 10; const uint8_t *start; const uint8_t *end; int ret; SFSnortPacket *sp = (SFSnortPacket *) p; ret = getBuffer(sp, byteData->flags, &start, &end); if ( ret < 0 ) { return ret; } /* Check for byte_extract variables and use them if present. */ if (byteData->offset_location) { byteData->offset = *byteData->offset_location; } if (byteData->value_location) { byteData->value = *byteData->value_location; } /* Check the start location */ if (checkCursorSimple(cursor, byteData->flags, start, end, byteData->offset) <= 0) return -1; /* and the end location */ if (checkCursorSimple(cursor, byteData->flags, start, end, byteData->offset + byteData->bytes - 1) <= 0) return -1; /* Extract can be from beginning of buffer, or relative to cursor */ if ( cursor == NULL || !(byteData->flags & CONTENT_RELATIVE) ) { cursor = start; } if (byteData->flags & EXTRACT_AS_BYTE) { if ( byteData->bytes != 1 && byteData->bytes != 2 && byteData->bytes != 4 ) { return -5; /* We only support 1, 2, or 4 bytes */ } if (byteData->bytes < 1 || byteData->bytes > 4) return -2; if ( byteData->flags & BYTE_BIG_ENDIAN ) { for (i = byteData->bytes; i > 0; i--) { extracted |= *(cursor + byteData->offset + byteData->bytes - i) << 8*(i-1); } } else { for (i = 0; i < byteData->bytes; i++) { extracted |= *(cursor + byteData->offset + i) << 8*i; } } *value = extracted; return 1; } else if (byteData->flags & EXTRACT_AS_STRING) { const uint8_t *space_ptr = cursor + byteData->offset; if (byteData->bytes < 1 || byteData->bytes > (BYTE_STRING_LEN - 1)) { /* Log Error message */ return -2; } // Only positive numbers should be processed and strtoul will // eat up white space and process '-' and '+' so move past // white space and check for a negative sign. while ((space_ptr < (cursor + byteData->offset + byteData->bytes)) && isspace((int)*space_ptr)) space_ptr++; // If all spaces or a negative sign is found, return error. if ((space_ptr == (cursor + byteData->offset + byteData->bytes)) || (*space_ptr == '-')) return -2; if (byteData->flags & EXTRACT_AS_DEC) base = 10; else if (byteData->flags & EXTRACT_AS_HEX) base = 16; else if (byteData->flags & EXTRACT_AS_OCT) base = 8; else if (byteData->flags & EXTRACT_AS_BIN) base = 2; for (i=0;i<byteData->bytes;i++) { byteArray[i] = *(cursor + byteData->offset + i); } byteArray[i] = '\0'; extracted = strtoul(byteArray, &endPtr, base); if (endPtr == &byteArray[0]) return -3; /* Nothing to convert */ *value = extracted; return 1; } return -4; }
int ruleIMAIL_LDAPeval(void *p) { uint32_t current_byte = 0; uint32_t width, value, lengthwidth; int retval; uint32_t payload_len; const uint8_t *cursor_normal, *beg_of_payload, *end_of_payload; SFSnortPacket *sp = (SFSnortPacket *) p; if(sp == NULL) return RULE_NOMATCH; if(sp->payload == NULL) return RULE_NOMATCH; /* call flow match */ if (checkFlow(sp, ruleIMAIL_LDAPoptions[0]->option_u.flowFlags) <= 0 ) return RULE_NOMATCH; /* call content match */ if (contentMatch(sp, ruleIMAIL_LDAPoptions[1]->option_u.content, &cursor_normal) <= 0) { return RULE_NOMATCH; } if(getBuffer(sp, CONTENT_BUF_NORMALIZED, &beg_of_payload, &end_of_payload) <= 0) return RULE_NOMATCH; payload_len = end_of_payload - beg_of_payload; if(payload_len < 10) /* Minimum bind request length */ return RULE_NOMATCH; /* our contentMatch already assures us the first byte is \x30, so just jump over it */ current_byte++; /* Begin packet structure processing */ /* Packet length (only care about width of the specifier) */ if(beg_of_payload[current_byte] & 0x80) { current_byte += beg_of_payload[current_byte] & 0x0F; /* Does imail do this properly? */ } current_byte++; /* Message number (only care about width of the specifier) */ if(payload_len < current_byte + 8) return RULE_NOMATCH; if(beg_of_payload[current_byte] != 0x02) /* Int data type */ return RULE_NOMATCH; current_byte++; /* int width specifier */ if(beg_of_payload[current_byte] & 0x80) { width = beg_of_payload[current_byte] & 0x0F; current_byte++; if(payload_len < current_byte + width) return RULE_NOMATCH; retval = process_val(&(beg_of_payload[current_byte]), width, &value); if(retval < 0) return RULE_NOMATCH; /* width is either 0 or > 4 */ current_byte += width; /* width of data width specifier */ current_byte += value; /* width of data itself */ } else { current_byte += beg_of_payload[current_byte] + 1; } /* Bind request */ if(payload_len < current_byte + 5) return RULE_NOMATCH; if(beg_of_payload[current_byte] != 0x60) return RULE_NOMATCH; current_byte++; /* Message length (only care about width of the specifier) */ if(beg_of_payload[current_byte] & 0x80) { current_byte += beg_of_payload[current_byte] & 0x0F; } current_byte++; /* ldap version */ if(payload_len < current_byte + 3) return RULE_NOMATCH; /* ldap version */ if(beg_of_payload[current_byte] != 0x02) /* Int data type */ return RULE_NOMATCH; current_byte++; /* Now check for funkiness with the version field */ /* Get width of version number */ if(beg_of_payload[current_byte] & 0x80) { /* Excess bits in the high nibble */ if(beg_of_payload[current_byte] & 0x70) return RULE_MATCH; lengthwidth = beg_of_payload[current_byte] & 0x0F; current_byte++; if(payload_len < current_byte + lengthwidth) return RULE_NOMATCH; retval = process_val(&(beg_of_payload[current_byte]), lengthwidth, &value); if(retval < 0) return RULE_MATCH; /* Something screwy's going on around here */ width = value; current_byte += lengthwidth; } else { width = beg_of_payload[current_byte]; current_byte++; } if(payload_len < current_byte + width) return RULE_NOMATCH; /* In this case, if the version value is this fubar, trigger */ retval = process_val(&(beg_of_payload[current_byte]), width, &value); if(retval < 0) return RULE_MATCH; /* LDAP version > 9 (currently, should be 1-3) */ if(value > 9) return RULE_MATCH; return RULE_NOMATCH; }
int ruleOPENLDAP_BIND_DOSeval(void *p) { int retval; u_int32_t size_len, size; const u_int8_t *cursor_normal, *end_of_payload; /*, *end_of_payload;*/ SFSnortPacket *sp = (SFSnortPacket *) p; BER_ELEMENT element; if(sp == NULL) return RULE_NOMATCH; if(sp->payload == NULL) return RULE_NOMATCH; if(getBuffer(sp, CONTENT_BUF_NORMALIZED, &cursor_normal, &end_of_payload) <= 0) return RULE_NOMATCH; if((end_of_payload - cursor_normal) < 285) /* Minimum malicious BIND request length */ return RULE_NOMATCH; /* call flow match */ if (checkFlow(sp, ruleOPENLDAP_BIND_DOSoptions[0]->option_u.flowFlags) <= 0 ) return RULE_NOMATCH; /* call content match */ if (contentMatch(sp, ruleOPENLDAP_BIND_DOSoptions[1]->option_u.content, &cursor_normal) <= 0) { return RULE_NOMATCH; } /* our contentMatch already assures us the first byte is \x30, so we're pointing at the size */ /* Begin packet structure processing */ retval = ber_get_size(p, cursor_normal, &size_len, &size); // message length if(retval < 0) return(RULE_NOMATCH); cursor_normal += size_len; /* Message number (only care about width of the specifier) */ retval = ber_get_element(p, cursor_normal, &element); if(retval < 0 || element.type != 0x02) return(RULE_NOMATCH); cursor_normal += element.total_len; /* BIND request */ retval = ber_get_element(p, cursor_normal, &element); if(retval < 0 || element.type != 0x60) return RULE_NOMATCH; /* We're inside the BIND request. Now we need to parse the internals */ cursor_normal = element.data.data_ptr; /* bind version */ retval = ber_get_element(p, cursor_normal, &element); if(retval < 0 || element.type != 0x02) return RULE_NOMATCH; cursor_normal += element.total_len; /* DN */ retval = ber_get_element(p, cursor_normal, &element); if(retval < 0 || element.type != 0x04) return RULE_NOMATCH; cursor_normal += element.total_len; /* SASL authtype request */ retval = ber_get_element(p, cursor_normal, &element); if(retval < 0 || element.type != 0xa3) return RULE_NOMATCH; /* We're inside the SASL BIND request. Now we need to parse the internals */ cursor_normal = element.data.data_ptr; /* SASL auth mechanism */ retval = ber_get_element(p, cursor_normal, &element); if((retval < 0) || (element.type != 0x04) || (element.data_len != 8)) return RULE_NOMATCH; /* call content match "CRAM-MD5" */ /* This will modify element.data.data_ptr, but we don't care */ if(contentMatch(sp, ruleOPENLDAP_BIND_DOSoptions[1]->option_u.content, &(element.data.data_ptr)) <= 0) { return RULE_NOMATCH; } cursor_normal += element.total_len; /* Credentials For our check, we need to have 255 bytes in the actual buffer, so we need to verify the number of bytes present, not just the data_len reported by the BER element. */ retval = ber_get_element(p, cursor_normal, &element); if((retval < 255) || (element.type != 0x04)) return RULE_NOMATCH; /* Here's the actual exploit detection -- see if there's a space at 255 bytes */ if(element.data.data_ptr[254] == ' ') return RULE_MATCH; return RULE_NOMATCH; }
//in doTransfer the buffer contains adr and data fields, so dotransfer copies the //buffer to cout and resets it void Viousbdebug::doTransfer(uint id) { getInbuf()->clear(); cout<<getBuffer()->size()<<" "<<requests[id].out<<" "<<requests[id].in<<endl; unsigned char *cbuf=(unsigned char *)(getBuffer()->data()); //start at buffer begin for(ts_t i=0; i<requests[id].out*4; i++) //loop over bytes { printf("%02x ",cbuf[i]); if((i+1)%16==0) { cout<<endl; }; } for(ts_t i=0; i<requests[id].in; i++) getInbuf()->push_back( (*getBuffer())[i] ); //generate dummy return data //interpret packet and emulate part of the hw sp6data *obuf=getBuffer()->data(); sp6data *ibuf=getInbuf()->data(); uint cmd=(obuf[0]); uint adr=(obuf[1]); uint data=(obuf[2]); switch(cmd) { case Vusbmaster::CMD_READSTATUS: ibuf[2]=(statusreg); break; case Vusbmaster::CMD_WRITESTATUS: statusreg=data; break; case Vusbmaster::CMD_READBURST: for(uint i=0; i<data; i++)ibuf[3+i]=mem.at(adr+i); break; case Vusbmaster::CMD_WRITEBURST: for(uint i=0; i<data; i++)mem.at(adr+i)=obuf[3+i]; break; case Vusbmaster::CMD_WRITEOCPBURST: for(uint i=0; i<data/2; i++) ocpmem.at((obuf[3+i*2]) & 0x7fffffffU)=obuf[4+i*2]; case Vusbmaster::CMD_READOCP: //emulate timeout: all odd addresses have empty fifo ibuf[2]=ocpmem.at(adr); if(adr%2)ibuf[1] = ibuf[1] | (0x80000000); break; case Vusbmaster::CMD_READOCPFIFO: ibuf[2]=ocpmem.at(adr); break; } unsigned char *icbuf=(unsigned char *)(getInbuf()->data()); //start at buffer begin for(ts_t i=0; i<requests[id].in*4; i++) //loop over bytes { printf("%02x ",icbuf[i]); if((i+1)%16==0) { cout<<endl; }; } getBuffer()->clear(); }
U8 *BitStream::getBytePtr() { return getBuffer() + getBytePosition(); }
size_t __read(int fd, char buffer, size_t count){ int c = getBuffer(); if(c == 0) return 0; return c; }
/* detection functions */ int rule15327eval(void *p) { const uint8_t *cursor_normal = 0; const uint8_t *end_of_payload; uint16_t numanswers; uint16_t numqueries; uint16_t len; uint32_t total = 0; int i; SFSnortPacket *sp = (SFSnortPacket *) p; if(sp == NULL) return RULE_NOMATCH; if(sp->payload == NULL) return RULE_NOMATCH; // flow:to_client; if (checkFlow(p, rule15327options[0]->option_u.flowFlags) > 0 ) { // byte_test:size 2, value 7999, operator >, offset 2; if (byteTest(p, rule15327options[1]->option_u.byte, cursor_normal) > 0) { if(getBuffer(sp, CONTENT_BUF_NORMALIZED, &cursor_normal, &end_of_payload) <= 0) return RULE_NOMATCH; if ((cursor_normal+12) > end_of_payload) return RULE_NOMATCH; // Extract number of query and answer records numqueries = read_big_16(cursor_normal+4); numanswers = read_big_16(cursor_normal+6); cursor_normal += 12; // Iterate through variable-sized query records to skip to the answer records. for(i = 0; i < numqueries; i++) { while(cursor_normal < end_of_payload && *cursor_normal != 0 && !((*cursor_normal & 0xc0) == 0xc0)) { cursor_normal += *cursor_normal + 1; } if (cursor_normal >= end_of_payload) return RULE_NOMATCH; cursor_normal += ((*cursor_normal & 0xc0) == 0xc0) ? 2 : 1 ; cursor_normal += 2+2; } if(cursor_normal >= end_of_payload) return RULE_NOMATCH; // Iterate through answer records for(i = 0; i < numanswers; i++) { // Reset the counter used to detect the overflow for each new answer record total = 0; while(cursor_normal < end_of_payload && *cursor_normal != 0 && !((*cursor_normal & 0xc0) == 0xc0)) { cursor_normal += *cursor_normal + 1; } if(cursor_normal >= end_of_payload) return RULE_NOMATCH; cursor_normal += ((*cursor_normal & 0xc0) == 0xc0) ? 2 : 1 ; if ((cursor_normal + 1) >= end_of_payload) return RULE_NOMATCH; // Check that the record type is TXT, that is, 0x10 if (*(cursor_normal + 1) != 0x10) return RULE_NOMATCH; cursor_normal += 2+2+4; if (cursor_normal + 1 >= end_of_payload) return RULE_NOMATCH; // Extract the length field len = read_big_16_inc(cursor_normal); // Iterate through the byte[data] section and add each of the // individual string lengths together while(cursor_normal < end_of_payload && total < len) { total += *cursor_normal + 1; cursor_normal += *cursor_normal + 1; } // Alert if the sum (total) of the inidividual string lengths // exceeds the length field for the entire data section if(cursor_normal >= end_of_payload) return RULE_NOMATCH; else if(total > len) return RULE_MATCH; } } } return RULE_NOMATCH; }
/* detection functions */ int rule27906eval(void *p) { const u_int8_t *cursor_normal = 0, *end_of_payload; SFSnortPacket *sp = (SFSnortPacket *) p; BER_ELEMENT kerberos_string; int i; if(sp == NULL) return RULE_NOMATCH; if(sp->payload == NULL) return RULE_NOMATCH; // flow:to_server; if(checkFlow(p, rule27906options[0]->option_u.flowFlags) <= 0) return RULE_NOMATCH; if(getBuffer(sp, CONTENT_BUF_NORMALIZED, &cursor_normal, &end_of_payload) <= 0) return RULE_NOMATCH; BER_DATA(0x6c); // KDC-REQ [12] BER_DATA(0x30); // SEQUENCE [16] BER_SKIP(0xA1); // pvno [1] BER_SKIP(0xA2); // msg-type [2] // if optional PA-DATA exists, skip it // 10 1 00011 (context-specific, structured, tag number 3) if(cursor_normal+1 > end_of_payload) return RULE_NOMATCH; if(*cursor_normal == 0xA3) BER_SKIP(0xA3); // KDC-REQ-BODY [4] ::= SEQUENCE [16] // kdc-options [0] // realm [2] server's realm // sname [3] PrincipalName BER_DATA(0xA4); // KDC-REQ-BODY BER_DATA(0x30); // SEQUENCE BER_SKIP(0xA0); // kdc-options BER_SKIP(0xA2); // realm // PrincipalName [3] ::= SEQUENCE [16] // name-type [0] Int32 // name-string [1] SEQUENCE [16] of KerberosString BER_DATA(0xA3); BER_DATA(0x30); BER_SKIP(0xA0); BER_DATA(0xA1); BER_DATA(0x30); // check up to 20 strings for the vulnerable condition for(i=0; (ber_get_element(sp, cursor_normal, &kerberos_string) >= 0) && (i < 20); i++) { // verify we are looking at a string element if(kerberos_string.type != 0x1b) return RULE_NOMATCH; DEBUG_SO(fprintf(stderr,"kerberos_string:\n data_len = 0x%02x\n",kerberos_string.data_len);) // vulnerable condition is kerberos_string.data_len == 0 if(kerberos_string.data_len == 0) return RULE_MATCH; // Move to the end of the current element. Guaranteed to move us forward in the packet. cursor_normal += kerberos_string.total_len; }
String::String( const String &value ) { getBuffer( _length = value._length ); if ( _buffer != NULL ) strcpy( _buffer, value._buffer ); }
void GLEScontext::getBufferUsage(GLenum target,GLint* param) { GLuint bufferName = getBuffer(target); GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).Ptr()); *param = vbo->getUsage(); }
bool QMakeSourceFileInfo::findDeps(SourceFile *file) { if(file->dep_checked || file->type == TYPE_UNKNOWN) return true; files_changed = true; file->dep_checked = true; struct stat fst; char *buffer = 0; int buffer_len = 0; { int fd; #if defined(_MSC_VER) && _MSC_VER >= 1400 if (_sopen_s(&fd, fixPathForFile(file->file, true).local().toLatin1().constData(), _O_RDONLY, _SH_DENYNO, _S_IREAD) != 0) fd = -1; #else fd = open(fixPathForFile(file->file, true).local().toLatin1().constData(), O_RDONLY); #endif if(fd == -1 || fstat(fd, &fst) || S_ISDIR(fst.st_mode)) return false; buffer = getBuffer(fst.st_size); for(int have_read = 0; (have_read = QT_READ(fd, buffer + buffer_len, fst.st_size - buffer_len)); buffer_len += have_read); QT_CLOSE(fd); } if(!buffer) return false; if(!file->deps) file->deps = new SourceDependChildren; int line_count = 1; for(int x = 0; x < buffer_len; ++x) { bool try_local = true; char *inc = 0; if(file->type == QMakeSourceFileInfo::TYPE_UI) { // skip whitespaces while(x < buffer_len && (*(buffer+x) == ' ' || *(buffer+x) == '\t')) ++x; if(*(buffer + x) == '<') { ++x; if(buffer_len >= x + 12 && !strncmp(buffer + x, "includehint", 11) && (*(buffer + x + 11) == ' ' || *(buffer + x + 11) == '>')) { for(x += 11; *(buffer + x) != '>'; ++x); int inc_len = 0; for(x += 1 ; *(buffer + x + inc_len) != '<'; ++inc_len); *(buffer + x + inc_len) = '\0'; inc = buffer + x; } else if(buffer_len >= x + 13 && !strncmp(buffer + x, "customwidget", 12) && (*(buffer + x + 12) == ' ' || *(buffer + x + 12) == '>')) { for(x += 13; *(buffer + x) != '>'; ++x); //skip up to > while(x < buffer_len) { for(x++; *(buffer + x) != '<'; ++x); //skip up to < x++; if(buffer_len >= x + 7 && !strncmp(buffer+x, "header", 6) && (*(buffer + x + 6) == ' ' || *(buffer + x + 6) == '>')) { for(x += 7; *(buffer + x) != '>'; ++x); //skip up to > int inc_len = 0; for(x += 1 ; *(buffer + x + inc_len) != '<'; ++inc_len); *(buffer + x + inc_len) = '\0'; inc = buffer + x; break; } else if(buffer_len >= x + 14 && !strncmp(buffer+x, "/customwidget", 13) && (*(buffer + x + 13) == ' ' || *(buffer + x + 13) == '>')) { x += 14; break; } } } else if(buffer_len >= x + 8 && !strncmp(buffer + x, "include", 7) && (*(buffer + x + 7) == ' ' || *(buffer + x + 7) == '>')) { for(x += 8; *(buffer + x) != '>'; ++x) { if(buffer_len >= x + 9 && *(buffer + x) == 'i' && !strncmp(buffer + x, "impldecl", 8)) { for(x += 8; *(buffer + x) != '='; ++x); if(*(buffer + x) != '=') continue; for(++x; *(buffer+x) == '\t' || *(buffer+x) == ' '; ++x); char quote = 0; if(*(buffer+x) == '\'' || *(buffer+x) == '"') { quote = *(buffer + x); ++x; } int val_len; for(val_len = 0; true; ++val_len) { if(quote) { if(*(buffer+x+val_len) == quote) break; } else if(*(buffer + x + val_len) == '>' || *(buffer + x + val_len) == ' ') { break; } } //? char saved = *(buffer + x + val_len); *(buffer + x + val_len) = '\0'; if(!strcmp(buffer+x, "in implementation")) { //### do this } } } int inc_len = 0; for(x += 1 ; *(buffer + x + inc_len) != '<'; ++inc_len); *(buffer + x + inc_len) = '\0'; inc = buffer + x; } } //read past new line now.. for(; x < buffer_len && !qmake_endOfLine(*(buffer + x)); ++x); ++line_count; } else if(file->type == QMakeSourceFileInfo::TYPE_QRC) { } else if(file->type == QMakeSourceFileInfo::TYPE_C) { for(int beginning=1; x < buffer_len; ++x) { // whitespace comments and line-endings for(; x < buffer_len; ++x) { if(*(buffer+x) == ' ' || *(buffer+x) == '\t') { // keep going } else if(*(buffer+x) == '/') { ++x; if(buffer_len >= x) { if(*(buffer+x) == '/') { //c++ style comment for(; x < buffer_len && !qmake_endOfLine(*(buffer + x)); ++x); beginning = 1; } else if(*(buffer+x) == '*') { //c style comment for(++x; x < buffer_len; ++x) { if(*(buffer+x) == '*') { if(x < buffer_len-1 && *(buffer + (x+1)) == '/') { ++x; break; } } else if(qmake_endOfLine(*(buffer+x))) { ++line_count; } } } } } else if(qmake_endOfLine(*(buffer+x))) { ++line_count; beginning = 1; } else { break; } } if(x >= buffer_len) break; // preprocessor directive if(beginning && *(buffer+x) == '#') break; // quoted strings if(*(buffer+x) == '\'' || *(buffer+x) == '"') { const char term = *(buffer+(x++)); for(; x < buffer_len; ++x) { if(*(buffer+x) == term) { ++x; break; } else if(*(buffer+x) == '\\') { ++x; } else if(qmake_endOfLine(*(buffer+x))) { ++line_count; } } } beginning = 0; } if(x >= buffer_len) break; //got a preprocessor symbol ++x; while(x < buffer_len) { if(*(buffer+x) != ' ' && *(buffer+x) != '\t') break; ++x; } int keyword_len = 0; const char *keyword = buffer+x; while(x+keyword_len < buffer_len) { if(((*(buffer+x+keyword_len) < 'a' || *(buffer+x+keyword_len) > 'z')) && *(buffer+x+keyword_len) != '_') { for(x+=keyword_len; //skip spaces after keyword x < buffer_len && (*(buffer+x) == ' ' || *(buffer+x) == '\t'); x++); break; } else if(qmake_endOfLine(*(buffer+x+keyword_len))) { x += keyword_len-1; keyword_len = 0; break; } keyword_len++; } if(keyword_len == 7 && !strncmp(keyword, "include", keyword_len)) { char term = *(buffer + x); if(term == '<') { try_local = false; term = '>'; } else if(term != '"') { //wtf? continue; } x++; int inc_len; for(inc_len = 0; *(buffer + x + inc_len) != term && !qmake_endOfLine(*(buffer + x + inc_len)); ++inc_len); *(buffer + x + inc_len) = '\0'; inc = buffer + x; x += inc_len; } else if(keyword_len == 13 && !strncmp(keyword, "qmake_warning", keyword_len)) { char term = 0; if(*(buffer + x) == '"') term = '"'; if(*(buffer + x) == '\'') term = '\''; if(term) x++; int msg_len; for(msg_len = 0; (term && *(buffer + x + msg_len) != term) && !qmake_endOfLine(*(buffer + x + msg_len)); ++msg_len); *(buffer + x + msg_len) = '\0'; debug_msg(0, "%s:%d %s -- %s", file->file.local().toLatin1().constData(), line_count, keyword, buffer+x); x += msg_len; } else if(*(buffer+x) == '\'' || *(buffer+x) == '"') { const char term = *(buffer+(x++)); while(x < buffer_len) { if(*(buffer+x) == term) break; if(*(buffer+x) == '\\') { x+=2; } else { if(qmake_endOfLine(*(buffer+x))) ++line_count; ++x; } } } else { --x; } } if(inc) { if(!includes) includes = new SourceFiles; SourceFile *dep = includes->lookupFile(inc); if(!dep) { bool exists = false; QMakeLocalFileName lfn(inc); if(QDir::isRelativePath(lfn.real())) { if(try_local) { QString dir = findFileInfo(file->file).path(); if(QDir::isRelativePath(dir)) dir.prepend(qmake_getpwd() + "/"); if(!dir.endsWith("/")) dir += "/"; QMakeLocalFileName f(dir + lfn.local()); if(findFileInfo(f).exists()) { lfn = fixPathForFile(f); exists = true; } } if(!exists) { //path lookup for(QList<QMakeLocalFileName>::Iterator it = depdirs.begin(); it != depdirs.end(); ++it) { QMakeLocalFileName f((*it).real() + Option::dir_sep + lfn.real()); QFileInfo fi(findFileInfo(f)); if(fi.exists() && !fi.isDir()) { lfn = fixPathForFile(f); exists = true; break; } } } if(!exists) { //heuristic lookup lfn = findFileForDep(QMakeLocalFileName(inc), file->file); if((exists = !lfn.isNull())) lfn = fixPathForFile(lfn); } } else { exists = QFile::exists(lfn.real()); } if(!lfn.isNull()) { dep = files->lookupFile(lfn); if(!dep) { dep = new SourceFile; dep->file = lfn; dep->type = QMakeSourceFileInfo::TYPE_C; files->addFile(dep); includes->addFile(dep, inc, false); } dep->exists = exists; } } if(dep && dep->file != file->file) { dep->included_count++; if(dep->exists) { debug_msg(5, "%s:%d Found dependency to %s", file->file.real().toLatin1().constData(), line_count, dep->file.local().toLatin1().constData()); file->deps->addChild(dep); } } } } if(dependencyMode() == Recursive) { //done last because buffer is shared for(int i = 0; i < file->deps->used_nodes; i++) { if(!file->deps->children[i]->deps) findDeps(file->deps->children[i]); } } return true; }
bool GLEScontext::setBufferData(GLenum target,GLsizeiptr size,const GLvoid* data,GLenum usage) { GLuint bufferName = getBuffer(target); if(!bufferName) return false; GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).Ptr()); return vbo->setBuffer(size,usage,data); }
status_t BufferedTextOutput::print(const char* txt, size_t len) { //printf("BufferedTextOutput: printing %d\n", len); AutoMutex _l(mLock); BufferState* b = getBuffer(); const char* const end = txt+len; status_t err; while (txt < end) { // Find the next line. const char* first = txt; while (txt < end && *txt != '\n') txt++; // Include this and all following empty lines. while (txt < end && *txt == '\n') txt++; // Special cases for first data on a line. if (b->atFront) { if (b->indent > 0) { // If this is the start of a line, add the indent. const char* prefix = stringForIndent(b->indent); err = b->append(prefix, strlen(prefix)); if (err != NO_ERROR) return err; } else if (*(txt-1) == '\n' && !b->bundle) { // Fast path: if we are not indenting or bundling, and // have been given one or more complete lines, just write // them out without going through the buffer. // Slurp up all of the lines. const char* lastLine = txt+1; while (txt < end) { if (*txt++ == '\n') lastLine = txt; } struct iovec vec; vec.iov_base = (void*)first; vec.iov_len = lastLine-first; //printf("Writing %d bytes of data!\n", vec.iov_len); writeLines(vec, 1); txt = lastLine; continue; } } // Append the new text to the buffer. err = b->append(first, txt-first); if (err != NO_ERROR) return err; b->atFront = *(txt-1) == '\n'; // If we have finished a line and are not bundling, write // it out. //printf("Buffer is now %d bytes\n", b->bufferPos); if (b->atFront && !b->bundle) { struct iovec vec; vec.iov_base = b->buffer; vec.iov_len = b->bufferPos; //printf("Writing %d bytes of data!\n", vec.iov_len); writeLines(vec, 1); b->restart(); } } return NO_ERROR; }
/* detection functions */ int rule13887eval(void *p) { const uint8_t *cursor_normal = 0, *beg_of_payload, *end_of_payload; SFSnortPacket *sp = (SFSnortPacket *) p; uint16_t num_of_queries, num_of_answers, num_of_authorities; uint16_t comp_offset; uint16_t data_len; uint8_t seglen; uint8_t new_root_name[ROOT_NAME_BUF_LEN], prev_root_name[ROOT_NAME_BUF_LEN]; const uint8_t *rr_ptr; uint8_t root_name_len = 0; // flags uint8_t first_NS_record; // cruft uint16_t i,j; DEBUG_WRAP(uint16_t k); DEBUG_WRAP(printf("rule13887eval dns auth nameserver enter\n")); if(sp == NULL) return RULE_NOMATCH; if(sp->payload == NULL) return RULE_NOMATCH; // flow:established, to_client; if(checkFlow(p, rule13887options[0]->option_u.flowFlags) <= 0 ) return RULE_NOMATCH; DEBUG_WRAP(printf("passed flow\n")); // content:"|00 01|", offset 4, depth 2; if(contentMatch(p, rule13887options[1]->option_u.content, &cursor_normal) <= 0) return RULE_NOMATCH; DEBUG_WRAP(printf("passed content\n")); // byte_test:size 2, value 1, operator >, offset 8; if(byteTest(p, rule13887options[2]->option_u.byte, cursor_normal) <= 0) return RULE_NOMATCH; DEBUG_WRAP(printf("passed byte test\n")); // This check doesn't have to actually be here; the structure is only for the fast pattern matcher // // content:"|00 02 00 01|", depth 0, relative, fast_pattern; // if (contentMatch(p, rule13887options[3]->option_u.content, &cursor_normal) <= 0) // return RULE_MATCH; // // DEBUG_WRAP(printf("passed content\n")); if(getBuffer(sp, CONTENT_BUF_NORMALIZED, &beg_of_payload, &end_of_payload) <= 0) return RULE_NOMATCH; if(end_of_payload - beg_of_payload < 25) return RULE_NOMATCH; cursor_normal = beg_of_payload + 4; num_of_queries = *cursor_normal++ << 8; num_of_queries |= *cursor_normal++; num_of_answers = *cursor_normal++ << 8; num_of_answers |= *cursor_normal++; // Our byte_test assures us num_of_authorities is >= 2 so we have // something to compare later num_of_authorities = *cursor_normal++ << 8; num_of_authorities |= *cursor_normal++; cursor_normal += 2; // skip over count of additional RRs DEBUG_WRAP(printf("num_of_queries=%d num_of_answers=%d num_of_authorities=%d\n", num_of_queries, num_of_answers, num_of_authorities)); // Jump over the query records for(i = 0; i < num_of_queries; i++) { DEBUG_WRAP(printf("processing query %d, payload_offset=%x\n", i, cursor_normal - beg_of_payload)); while(cursor_normal < end_of_payload && *cursor_normal != 0 && *cursor_normal < 0xc0) // !((*cursor_normal & 0xc0) == 0xc0) cursor_normal += *cursor_normal + 1; if(cursor_normal >= end_of_payload) return RULE_NOMATCH; // (two bytes for pointer (2 bytes) or null byte (1 byte)) + type (2 bytes) + class (2 bytes) cursor_normal += (*cursor_normal >= 0xc0) ? 6 : 5; // (*cursor_normal & 0xc0) == 0xc0 } //if(cursor_normal >= end_of_payload) // return RULE_NOMATCH; // Jump over the answers for(i = 0; i < num_of_answers; i++) { DEBUG_WRAP(printf("processing answer %d, payload_offset=%x\n", i, cursor_normal - beg_of_payload)); while(cursor_normal < end_of_payload && *cursor_normal != 0 && *cursor_normal < 0xc0) { // performance improvement, !((*cursor_normal & 0xc0) == 0xc0) cursor_normal += *cursor_normal + 1; } if(cursor_normal + 4 > end_of_payload) return RULE_NOMATCH; // (two bytes for pointer (2 bytes) or a single null byte (1 byte)) + type (2 bytes) + class (2 bytes) + ttl (4 bytes) cursor_normal += (*cursor_normal >= 0xc0) ? 2 : 1; if(*cursor_normal++ == 0x00 && *cursor_normal++ == 0x05) { DEBUG_WRAP(printf("We found a CNAME record; let's just bail rather than figure this out for real.\n")); return RULE_NOMATCH; } cursor_normal += 6; if(cursor_normal + 2 > end_of_payload) return RULE_NOMATCH; data_len = (*cursor_normal++) << 8; data_len |= *cursor_normal++; cursor_normal += data_len; } // Now on to the meat... The Authoritative nameservers. If we // change roots, alert. first_NS_record = 1; for(i = 0; i < num_of_authorities; i++) { DEBUG_WRAP(printf("processing authority %d, payload_offset=%x\n", i, cursor_normal - beg_of_payload)); if(cursor_normal + 12 >= end_of_payload) return RULE_NOMATCH; j=0; // index into expanded root name while(cursor_normal < end_of_payload && *cursor_normal != 0 && *cursor_normal < 0xc0) { // performance improvement, !((*cursor_normal & 0xc0) == 0xc0) // copy the size and data for each segment seglen = *cursor_normal++; new_root_name[j++] = seglen; DEBUG_WRAP(printf("seglen = %d\n", seglen)); if((j + seglen < ROOT_NAME_BUF_LEN) && (cursor_normal + seglen < end_of_payload)) { DEBUG_WRAP(printf("copying bytes\n")); memcpy(&(new_root_name[j]), cursor_normal, seglen); cursor_normal += seglen; j += seglen; } else { return RULE_NOMATCH; } } // Either we're at a pointer, a null, or out of data if((cursor_normal + 1 < end_of_payload) && *cursor_normal >= 0xc0) { // pointer // performance improvement, (*cursor_normal & 0xc0) == 0xc0 // Set the pointer comp_offset = (*cursor_normal++ & 0x3F) << 8; comp_offset |= *cursor_normal++; rr_ptr = beg_of_payload + comp_offset; DEBUG_WRAP(printf("offset = %d\n", comp_offset)); while(rr_ptr < end_of_payload && *rr_ptr != 0 && *rr_ptr < 0xc0) { // performance improvement, !((*rr_ptr & 0xc0) == 0xc0) // copy the size and data for each segment seglen = *rr_ptr++; new_root_name[j++] = seglen; DEBUG_WRAP(printf("seglen = %d\n", seglen)); if((j + seglen < ROOT_NAME_BUF_LEN) && (rr_ptr + seglen < end_of_payload)) { DEBUG_WRAP(printf("copying bytes\n")); memcpy(&(new_root_name[j]), rr_ptr, seglen); rr_ptr += seglen; j += seglen; } else { return RULE_NOMATCH; } } DEBUG_WRAP(printf("root: ")); DEBUG_WRAP(for(k=0; k < j; k++) printf("%c", new_root_name[k])); DEBUG_WRAP(printf("\n")); // we only handle one level of compression if(rr_ptr >= end_of_payload || *rr_ptr >= 0xc0) { // performance improvement, ((*rr_ptr & 0xc0) == 0xc0) DEBUG_WRAP(printf("Multiple compression - Stopping\n")); return RULE_NOMATCH; } } else if((cursor_normal < end_of_payload) && (*cursor_normal == 0)) { // null (end of name string)
//* Creation / loading methods ******************************************** void GLTexture::createInternalResourcesImpl(void) { if (!GLEW_VERSION_1_2 && mTextureType == TEX_TYPE_3D) OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "3D Textures not supported before OpenGL 1.2", "GLTexture::createInternalResourcesImpl"); if (!GLEW_VERSION_2_0 && mTextureType == TEX_TYPE_2D_ARRAY) OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "2D texture arrays not supported before OpenGL 2.0", "GLTexture::createInternalResourcesImpl"); if (mTextureType == TEX_TYPE_EXTERNAL_OES) { OGRE_EXCEPT( Exception::ERR_RENDERINGAPI_ERROR, "TEX_TYPE_EXTERNAL_OES is not available for openGL", "GLTexture::createInternalResourcesImpl" ); } // Convert to nearest power-of-two size if required mWidth = GLPixelUtil::optionalPO2(mWidth); mHeight = GLPixelUtil::optionalPO2(mHeight); mDepth = GLPixelUtil::optionalPO2(mDepth); // Adjust format if required mFormat = TextureManager::getSingleton().getNativeFormat(mTextureType, mFormat, mUsage); // Check requested number of mipmaps uint32 maxMips = getMaxMipmaps(); mNumMipmaps = mNumRequestedMipmaps; if(mNumMipmaps>maxMips) mNumMipmaps = maxMips; // Check if we can do HW mipmap generation mMipmapsHardwareGenerated = true; // Generate texture name glGenTextures( 1, &mTextureID ); // Set texture type mRenderSystem->_getStateCacheManager()->bindGLTexture( getGLTextureTarget(), mTextureID ); // This needs to be set otherwise the texture doesn't get rendered if (GLEW_VERSION_1_2) mRenderSystem->_getStateCacheManager()->setTexParameteri(getGLTextureTarget(), GL_TEXTURE_MAX_LEVEL, mNumMipmaps); // Set some misc default parameters so NVidia won't complain, these can of course be changed later mRenderSystem->_getStateCacheManager()->setTexParameteri(getGLTextureTarget(), GL_TEXTURE_MIN_FILTER, GL_NEAREST); mRenderSystem->_getStateCacheManager()->setTexParameteri(getGLTextureTarget(), GL_TEXTURE_MAG_FILTER, GL_NEAREST); if (GLEW_VERSION_1_2) { mRenderSystem->_getStateCacheManager()->setTexParameteri(getGLTextureTarget(), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); mRenderSystem->_getStateCacheManager()->setTexParameteri(getGLTextureTarget(), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } if ((mUsage & TU_AUTOMIPMAP) && mNumRequestedMipmaps) { mRenderSystem->_getStateCacheManager()->setTexParameteri( getGLTextureTarget(), GL_GENERATE_MIPMAP, GL_TRUE ); } // Allocate internal buffer so that glTexSubImageXD can be used // Internal format GLenum internalformat = GLPixelUtil::getGLInternalFormat(mFormat, mHwGamma); uint32 width = mWidth; uint32 height = mHeight; uint32 depth = mDepth; GLenum format = GLPixelUtil::getGLOriginFormat(mFormat); GLenum datatype = GLPixelUtil::getGLOriginDataType(mFormat); if(PixelUtil::isCompressed(mFormat)) { // Compressed formats GLsizei size = static_cast<GLsizei>(PixelUtil::getMemorySize(mWidth, mHeight, mDepth, mFormat)); // Provide temporary buffer filled with zeroes as glCompressedTexImageXD does not // accept a 0 pointer like normal glTexImageXD // Run through this process for every mipmap to pregenerate mipmap piramid std::vector<uint8> tmpdata(size); for(uint32 mip=0; mip<=mNumMipmaps; mip++) { size = static_cast<GLsizei>(PixelUtil::getMemorySize(width, height, depth, mFormat)); switch(mTextureType) { case TEX_TYPE_1D: glCompressedTexImage1DARB(GL_TEXTURE_1D, mip, internalformat, width, 0, size, &tmpdata[0]); break; case TEX_TYPE_2D: glCompressedTexImage2DARB(GL_TEXTURE_2D, mip, internalformat, width, height, 0, size, &tmpdata[0]); break; case TEX_TYPE_2D_ARRAY: case TEX_TYPE_3D: glCompressedTexImage3DARB(getGLTextureTarget(), mip, internalformat, width, height, depth, 0, size, &tmpdata[0]); break; case TEX_TYPE_CUBE_MAP: for(int face=0; face<6; face++) { glCompressedTexImage2DARB(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, mip, internalformat, width, height, 0, size, &tmpdata[0]); } break; case TEX_TYPE_2D_RECT: break; case TEX_TYPE_EXTERNAL_OES: OGRE_EXCEPT( Exception::ERR_RENDERINGAPI_ERROR, "Attempt to create mipmaps for unsupported TEX_TYPE_EXTERNAL_OES, should never happen", "GLTexture::createInternalResourcesImpl" ); break; }; if(width>1) width = width/2; if(height>1) height = height/2; if(depth>1 && mTextureType != TEX_TYPE_2D_ARRAY) depth = depth/2; } } else { // Run through this process to pregenerate mipmap pyramid for(uint32 mip=0; mip<=mNumMipmaps; mip++) { // Normal formats switch(mTextureType) { case TEX_TYPE_1D: glTexImage1D(GL_TEXTURE_1D, mip, internalformat, width, 0, format, datatype, 0); break; case TEX_TYPE_2D: glTexImage2D(GL_TEXTURE_2D, mip, internalformat, width, height, 0, format, datatype, 0); break; case TEX_TYPE_2D_ARRAY: case TEX_TYPE_3D: glTexImage3D(getGLTextureTarget(), mip, internalformat, width, height, depth, 0, format, datatype, 0); break; case TEX_TYPE_CUBE_MAP: for(int face=0; face<6; face++) { glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, mip, internalformat, width, height, 0, format, datatype, 0); } break; case TEX_TYPE_2D_RECT: break; case TEX_TYPE_EXTERNAL_OES: OGRE_EXCEPT( Exception::ERR_RENDERINGAPI_ERROR, "Attempt to create mipmaps for unsupported TEX_TYPE_EXTERNAL_OES, should never happen", "GLTexture::createInternalResourcesImpl" ); break; }; if(width>1) width = width/2; if(height>1) height = height/2; if(depth>1 && mTextureType != TEX_TYPE_2D_ARRAY) depth = depth/2; } } _createSurfaceList(); // Get final internal format mFormat = getBuffer(0,0)->getFormat(); }
//-------------------------------------------------------------------------- void Texture::_loadImages( const ConstImagePtrList& images ) { if(images.size() < 1) OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Cannot load empty vector of images", "Texture::loadImages"); // Set desired texture size and properties from images[0] mSrcWidth = mWidth = images[0]->getWidth(); mSrcHeight = mHeight = images[0]->getHeight(); mSrcDepth = mDepth = images[0]->getDepth(); // Get source image format and adjust if required mSrcFormat = images[0]->getFormat(); if (mTreatLuminanceAsAlpha && mSrcFormat == PF_L8) { mSrcFormat = PF_A8; } if (mDesiredFormat != PF_UNKNOWN) { // If have desired format, use it mFormat = mDesiredFormat; } else { // Get the format according with desired bit depth mFormat = PixelUtil::getFormatForBitDepths(mSrcFormat, mDesiredIntegerBitDepth, mDesiredFloatBitDepth); } // The custom mipmaps in the image have priority over everything uint8 imageMips = images[0]->getNumMipmaps(); if(imageMips > 0) { mNumMipmaps = mNumRequestedMipmaps = images[0]->getNumMipmaps(); // Disable flag for auto mip generation mUsage &= ~TU_AUTOMIPMAP; } // Create the texture createInternalResources(); // Check if we're loading one image with multiple faces // or a vector of images representing the faces size_t faces; bool multiImage; // Load from multiple images? if(images.size() > 1) { faces = images.size(); multiImage = true; } else { faces = images[0]->getNumFaces(); multiImage = false; } // Check whether number of faces in images exceeds number of faces // in this texture. If so, clamp it. if(faces > getNumFaces()) faces = getNumFaces(); if (TextureManager::getSingleton().getVerbose()) { // Say what we're doing StringUtil::StrStreamType str; str << "Texture: " << mName << ": Loading " << faces << " faces" << "(" << PixelUtil::getFormatName(images[0]->getFormat()) << "," << images[0]->getWidth() << "x" << images[0]->getHeight() << "x" << images[0]->getDepth() << ")"; if (!(mMipmapsHardwareGenerated && mNumMipmaps == 0)) { str << " with " << static_cast<int>(mNumMipmaps); if(mUsage & TU_AUTOMIPMAP) { if (mMipmapsHardwareGenerated) str << " hardware"; str << " generated mipmaps"; } else { str << " custom mipmaps"; } if(multiImage) str << " from multiple Images."; else str << " from Image."; } // Scoped { // Print data about first destination surface HardwarePixelBufferSharedPtr buf = getBuffer(0, 0); str << " Internal format is " << PixelUtil::getFormatName(buf->getFormat()) << "," << buf->getWidth() << "x" << buf->getHeight() << "x" << buf->getDepth() << "."; } LogManager::getSingleton().logMessage( LML_NORMAL, str.str()); } // Main loading loop // imageMips == 0 if the image has no custom mipmaps, otherwise contains the number of custom mips for(size_t mip = 0; mip <= std::min(mNumMipmaps, imageMips); ++mip) { for(size_t i = 0; i < faces; ++i) { PixelBox src; if(multiImage) { // Load from multiple images src = images[i]->getPixelBox(0, mip); } else { // Load from faces of images[0] src = images[0]->getPixelBox(i, mip); } // Sets to treated format in case is difference src.format = mSrcFormat; if(mGamma != 1.0f) { // Apply gamma correction // Do not overwrite original image but do gamma correction in temporary buffer MemoryDataStreamPtr buf; // for scoped deletion of conversion buffer buf.bind(OGRE_NEW MemoryDataStream( PixelUtil::getMemorySize( src.getWidth(), src.getHeight(), src.getDepth(), src.format))); PixelBox corrected = PixelBox(src.getWidth(), src.getHeight(), src.getDepth(), src.format, buf->getPtr()); PixelUtil::bulkPixelConversion(src, corrected); Image::applyGamma(static_cast<uint8*>(corrected.data), mGamma, corrected.getConsecutiveSize(), static_cast<uchar>(PixelUtil::getNumElemBits(src.format))); // Destination: entire texture. blitFromMemory does the scaling to // a power of two for us when needed getBuffer(i, mip)->blitFromMemory(corrected); } else { // Destination: entire texture. blitFromMemory does the scaling to // a power of two for us when needed getBuffer(i, mip)->blitFromMemory(src); } } } // Update size (the final size, not including temp space) mSize = getNumFaces() * PixelUtil::getMemorySize(mWidth, mHeight, mDepth, mFormat); }
// Creation / loading methods void GLES2Texture::createInternalResourcesImpl(void) { // Convert to nearest power-of-two size if required mWidth = GLES2PixelUtil::optionalPO2(mWidth); mHeight = GLES2PixelUtil::optionalPO2(mHeight); mDepth = GLES2PixelUtil::optionalPO2(mDepth); // Adjust format if required mFormat = TextureManager::getSingleton().getNativeFormat(mTextureType, mFormat, mUsage); // Check requested number of mipmaps size_t maxMips = GLES2PixelUtil::getMaxMipmaps(mWidth, mHeight, mDepth, mFormat); if(PixelUtil::isCompressed(mFormat) && (mNumMipmaps == 0)) mNumRequestedMipmaps = 0; mNumMipmaps = mNumRequestedMipmaps; if (mNumMipmaps > maxMips) mNumMipmaps = maxMips; // Generate texture name glGenTextures(1, &mTextureID); GL_CHECK_ERROR; // Set texture type glBindTexture(getGLES2TextureTarget(), mTextureID); GL_CHECK_ERROR; // If we can do automip generation and the user desires this, do so mMipmapsHardwareGenerated = Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_AUTOMIPMAP) && !PixelUtil::isCompressed(mFormat); #if GL_APPLE_texture_max_level && OGRE_PLATFORM != OGRE_PLATFORM_NACL glTexParameteri( getGLES2TextureTarget(), GL_TEXTURE_MAX_LEVEL_APPLE, (mMipmapsHardwareGenerated && (mUsage & TU_AUTOMIPMAP)) ? maxMips : mNumMipmaps ); #endif // Set some misc default parameters, these can of course be changed later glTexParameteri(getGLES2TextureTarget(), GL_TEXTURE_MIN_FILTER, GL_NEAREST); GL_CHECK_ERROR; glTexParameteri(getGLES2TextureTarget(), GL_TEXTURE_MAG_FILTER, GL_NEAREST); GL_CHECK_ERROR; glTexParameteri(getGLES2TextureTarget(), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); GL_CHECK_ERROR; glTexParameteri(getGLES2TextureTarget(), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); GL_CHECK_ERROR; // Allocate internal buffer so that glTexSubImageXD can be used // Internal format GLenum format = GLES2PixelUtil::getGLOriginFormat(mFormat); GLenum internalformat = GLES2PixelUtil::getClosestGLInternalFormat(mFormat, mHwGamma); GLenum datatype = GLES2PixelUtil::getGLOriginDataType(mFormat); size_t width = mWidth; size_t height = mHeight; size_t depth = mDepth; if (PixelUtil::isCompressed(mFormat)) { // Compressed formats size_t size = PixelUtil::getMemorySize(mWidth, mHeight, mDepth, mFormat); // Provide temporary buffer filled with zeroes as glCompressedTexImageXD does not // accept a 0 pointer like normal glTexImageXD // Run through this process for every mipmap to pregenerate mipmap pyramid uint8* tmpdata = new uint8[size]; memset(tmpdata, 0, size); for (size_t mip = 0; mip <= mNumMipmaps; mip++) { // LogManager::getSingleton().logMessage("GLES2Texture::create - Mip: " + StringConverter::toString(mip) + // " Width: " + StringConverter::toString(width) + // " Height: " + StringConverter::toString(height) + // " Internal Format: " + StringConverter::toString(internalformat, 0, ' ', std::ios::hex) + // " Format: " + StringConverter::toString(format, 0, ' ', std::ios::hex) + // " Datatype: " + StringConverter::toString(datatype, 0, ' ', std::ios::hex) // ); size = PixelUtil::getMemorySize(width, height, depth, mFormat); switch(mTextureType) { case TEX_TYPE_1D: case TEX_TYPE_2D: glCompressedTexImage2D(GL_TEXTURE_2D, mip, internalformat, width, height, 0, size, tmpdata); GL_CHECK_ERROR; break; case TEX_TYPE_CUBE_MAP: for(int face = 0; face < 6; face++) { glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, mip, internalformat, width, height, 0, size, tmpdata); GL_CHECK_ERROR; } break; case TEX_TYPE_3D: default: break; }; if(width > 1) { width = width / 2; } if(height > 1) { height = height / 2; } if(depth > 1) { depth = depth / 2; } } delete [] tmpdata; } else { // Run through this process to pregenerate mipmap pyramid for(size_t mip = 0; mip <= mNumMipmaps; mip++) { // LogManager::getSingleton().logMessage("GLES2Texture::create - Mip: " + StringConverter::toString(mip) + // " Name: " + mName + // " ID: " + StringConverter::toString(mTextureID) + // " Width: " + StringConverter::toString(width) + // " Height: " + StringConverter::toString(height) + // " Internal Format: " + StringConverter::toString(internalformat, 0, ' ', std::ios::hex) + // " Format: " + StringConverter::toString(format, 0, ' ', std::ios::hex) + // " Datatype: " + StringConverter::toString(datatype, 0, ' ', std::ios::hex) // ); // Normal formats switch(mTextureType) { case TEX_TYPE_1D: case TEX_TYPE_2D: #if OGRE_PLATFORM == OGRE_PLATFORM_NACL if(internalformat != format) { LogManager::getSingleton().logMessage("glTexImage2D: format != internalFormat, " "format=" + StringConverter::toString(format) + ", internalFormat=" + StringConverter::toString(internalformat)); } #endif glTexImage2D(GL_TEXTURE_2D, mip, internalformat, width, height, 0, format, datatype, 0); GL_CHECK_ERROR; break; case TEX_TYPE_CUBE_MAP: for(int face = 0; face < 6; face++) { glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, mip, internalformat, width, height, 0, format, datatype, 0); } break; case TEX_TYPE_3D: default: break; }; if (width > 1) { width = width / 2; } if (height > 1) { height = height / 2; } } } _createSurfaceList(); // Get final internal format mFormat = getBuffer(0,0)->getFormat(); }
int rule15328eval(void *p) { /* data pointers */ const u_int8_t *cursor_normal, *beg_of_payload, *end_of_payload, *end_of_segment, *after_icc_profile_string; /* data */ /* u_int8_t chunk_num, num_chunks; */ /* For multiple chunks (not implemented) */ u_int16_t segment_length; u_int32_t tagcount, tagsize; /* cruft */ int i; SFSnortPacket *sp = (SFSnortPacket *) p; if(sp == NULL) return RULE_NOMATCH; if(sp->payload == NULL) return RULE_NOMATCH; if(getBuffer(sp, CONTENT_BUF_NORMALIZED, &beg_of_payload, &end_of_payload) <= 0) return RULE_NOMATCH; if((end_of_payload - beg_of_payload) < 0xA4) /* Minimum packet length to have enough data */ return RULE_NOMATCH; /* call flow match */ if(checkFlow(sp, rule15328options[0]->option_u.flowFlags) <= 0 ) return RULE_NOMATCH; /* call content match "ICC_PROFILE|00|" */ if(contentMatch(sp, rule15328options[1]->option_u.content, &cursor_normal) <= 0) { return RULE_NOMATCH; } if(cursor_normal < beg_of_payload + 16) { // There isn't enough room to find the segment header, so search for a new "ICC_PROFILE|00|" if(contentMatch(sp, rule15328options[4]->option_u.content, &cursor_normal) <= 0) return RULE_NOMATCH; } /* We do a do..while loop to reuse all of the same code. The contentMatch for the while() is just like the initial contentMatch except it's relative. */ do { after_icc_profile_string = cursor_normal; /* stored for a pointer reset if needed later */ // 1+1+0x80+4+12 for chunk num, num of chunks, ICC header, tag count, first tag if(cursor_normal + 0x92 > end_of_payload) return RULE_NOMATCH; /* call content match "|FF E2|" */ if(contentMatch(sp, rule15328options[2]->option_u.content, &cursor_normal) <= 0) continue; // Loop again to see if we can find a new ICC_PROFILE /* Segment length is right after segment identifier, 16-bit, little-endian */ segment_length = *cursor_normal; segment_length |= *(cursor_normal+1) << 8; /* length includes length field but not the segment identifier */ end_of_segment = cursor_normal + segment_length; /* call content match "ascp" */ if(contentMatch(sp, rule15328options[3]->option_u.content, &cursor_normal) <= 0) { /* If we don't find "ascp", we need to move the cursor back to where it was after "ICC_PROFILE|00|" to prevent an infinite loop. This is preferable to restructuring the loop because we really want to search on "ICC..." because it's a faster search and has way less false matches than "|FF E2|". */ cursor_normal = after_icc_profile_string; continue; // Loop again to see if we can find a new ICC_PROFILE } /* At this point, we definitely have an ICC profile */ /* Get the chunk number and total number of chunks */ /* The content match above ensures the reads below are in the payload */ /* NOTE: We don't handle multiple chunks. This is left here in case later * we do. * chunk_num = *(cursor_normal - 42); * num_chunks = *(cursor_normal - 41); */ /* Get the Tag Count */ tagcount = ntohl(*((u_int32_t*)(cursor_normal + 88))); /* Point cursor_normal at the tag table */ cursor_normal += 92; /* This does not account for tag tables that span icc profile chunks! */ for(i=0; (i < tagcount) && (cursor_normal + 12 < end_of_payload) && (cursor_normal + 12 < end_of_segment); i++) { tagsize = ntohl(*((u_int32_t*)(cursor_normal + 8))); if(tagsize > 0xFFFFFFF7) return RULE_MATCH; cursor_normal += 12; // Next tag } /* Try to find another "ICC_PROFILE|00|" string and loop again */ } while(contentMatch(sp, rule15328options[4]->option_u.content, &cursor_normal) > 0); return RULE_NOMATCH; }
// estimate covariance matrix void FastLSPredictionComputer::estimate(const Point3i& currentPos) { if(context->getNeighborhood().getMask().total() != context->getFullNeighborhood().getMask().total()) LSPredictionComputer::estimate(currentPos); // if full neighborhood not yet available at border regions, for simplicity use WLS implementation else { Mat sampleVector; context->contextOf(currentPos, sampleVector); // get current neighborhood and store it in sampleVector covMat->create(context->getFullNeighborhood().getNumberOfElements(), context->getFullNeighborhood().getNumberOfElements() + 1, CV_64F); // one more row for later variance estimation! sampleVector.reshape(0, sampleVector.cols).copyTo(covMat->col(covMat->cols - 1)); // put neighborhood in last column for variance estimate int left = context->getTrainingregion().getLeft(), right = context->getTrainingregion().getRight(), top = context->getTrainingregion().getTop(); (*covMat)(Rect(0, 0, sampleVector.cols, sampleVector.cols)) = getBuffer(currentPos + Point3i( -1, 0, 0)) - getBuffer(currentPos + Point3i( -1, -1, 0)) + getBuffer(currentPos + Point3i( right, -1, 0)) - getBuffer(currentPos + Point3i(-1-left, 0, 0)) - getBuffer(currentPos + Point3i( right, -1-top, 0)) + getBuffer(currentPos + Point3i(-1-left, -1-top, 0)); if(context->getTrainingregion().getFront()) { // 3-D training region int bottom = context->getTrainingregion().getBottom(), front = context->getTrainingregion().getFront(); (*covMat)(Rect(0, 0, sampleVector.cols, sampleVector.cols)) += - getBuffer(currentPos + Point3i( -1, 0, -1 )) + getBuffer(currentPos + Point3i( -1, -1, -1 )) - getBuffer(currentPos + Point3i( right, -1, -1 )) + getBuffer(currentPos + Point3i(-1-left, 0, -1 )) + getBuffer(currentPos + Point3i( right, bottom, -1 )) - getBuffer(currentPos + Point3i(-1-left, bottom, -1 )) - getBuffer(currentPos + Point3i( right, bottom, -1-front)) + getBuffer(currentPos + Point3i(-1-left, bottom, -1-front)) + getBuffer(currentPos + Point3i( right, -1-top, -1-front)) - getBuffer(currentPos + Point3i(-1-left, -1-top, -1-front)); } *covMat = covMat->rowRange(0, covMat->rows - 1); // make last row invisible for computePrediction function of WLS // context->getContextElementsOf(currentPos); // only necessary if computeVariance method from parent class WLS is used } *weights = weights->colRange(0, 0); // set used region } // end FastLSPredictionComputer::estimate
// Creation / loading methods void GLESTexture::createInternalResourcesImpl(void) { // Convert to nearest power-of-two size if required mWidth = GLESPixelUtil::optionalPO2(mWidth); mHeight = GLESPixelUtil::optionalPO2(mHeight); mDepth = GLESPixelUtil::optionalPO2(mDepth); // Adjust format if required mFormat = TextureManager::getSingleton().getNativeFormat(TEX_TYPE_2D, mFormat, mUsage); // Check requested number of mipmaps size_t maxMips = GLESPixelUtil::getMaxMipmaps(mWidth, mHeight, mDepth, mFormat); if(PixelUtil::isCompressed(mFormat) && (mNumMipmaps == 0)) mNumRequestedMipmaps = 0; mNumMipmaps = mNumRequestedMipmaps; if (mNumMipmaps > maxMips) mNumMipmaps = maxMips; // Generate texture name glGenTextures(1, &mTextureID); GL_CHECK_ERROR; // Set texture type glBindTexture(GL_TEXTURE_2D, mTextureID); GL_CHECK_ERROR; // Set some misc default parameters, these can of course be changed later glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); GL_CHECK_ERROR; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); GL_CHECK_ERROR; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); GL_CHECK_ERROR; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); GL_CHECK_ERROR; // If we can do automip generation and the user desires this, do so mMipmapsHardwareGenerated = Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_AUTOMIPMAP) && !PixelUtil::isCompressed(mFormat); if ((mUsage & TU_AUTOMIPMAP) && mNumRequestedMipmaps && mMipmapsHardwareGenerated) { glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); GL_CHECK_ERROR; } // Allocate internal buffer so that glTexSubImageXD can be used // Internal format GLenum format = GLESPixelUtil::getClosestGLInternalFormat(mFormat, mHwGamma); GLenum datatype = GLESPixelUtil::getGLOriginDataType(mFormat); size_t width = mWidth; size_t height = mHeight; size_t depth = mDepth; if (PixelUtil::isCompressed(mFormat)) { // Compressed formats size_t size = PixelUtil::getMemorySize(mWidth, mHeight, mDepth, mFormat); // Provide temporary buffer filled with zeroes as glCompressedTexImageXD does not // accept a 0 pointer like normal glTexImageXD // Run through this process for every mipmap to pregenerate mipmap pyramid uint8* tmpdata = new uint8[size]; memset(tmpdata, 0, size); for (size_t mip = 0; mip <= mNumMipmaps; mip++) { size = PixelUtil::getMemorySize(width, height, depth, mFormat); glCompressedTexImage2D(GL_TEXTURE_2D, mip, format, width, height, 0, size, tmpdata); GL_CHECK_ERROR; // LogManager::getSingleton().logMessage("GLESTexture::create - Mip: " + StringConverter::toString(mip) + // " Width: " + StringConverter::toString(width) + // " Height: " + StringConverter::toString(height) + // " Internal Format: " + StringConverter::toString(format) // ); if(width > 1) { width = width / 2; } if(height > 1) { height = height / 2; } if(depth > 1) { depth = depth / 2; } } delete [] tmpdata; } else { // Run through this process to pregenerate mipmap pyramid for(size_t mip = 0; mip <= mNumMipmaps; mip++) { glTexImage2D(GL_TEXTURE_2D, mip, format, width, height, 0, format, datatype, 0); GL_CHECK_ERROR; if (width > 1) { width = width / 2; } if (height > 1) { height = height / 2; } } } _createSurfaceList(); // Get final internal format mFormat = getBuffer(0,0)->getFormat(); }
_impl->size = additionalSize; flush( true ); } size_t OCommand::getSize() { return sizeof( uint64_t ) + sizeof( uint32_t ) + sizeof( uint32_t ); } void OCommand::sendData( const void* buffer LB_UNUSED, const uint64_t size, const bool last LB_UNUSED ) { LBASSERT( !_impl->dispatcher ); LBASSERT( last ); LBASSERTINFO( size >= 16, size ); LBASSERT( getBuffer().getData() == buffer ); LBASSERT( getBuffer().getSize() == size ); LBASSERT( getBuffer().getMaxSize() >= COMMAND_MINSIZE ); // Update size field // cppcheck-suppress unreadVariable uint8_t* bytes = getBuffer().getData(); reinterpret_cast< uint64_t* >( bytes )[ 0 ] = _impl->size + size; const uint64_t sendSize = _impl->isLocked ? size : LB_MAX( size, COMMAND_MINSIZE); const Connections& connections = getConnections(); for( ConnectionsCIter i = connections.begin(); i != connections.end(); ++i ) { ConnectionPtr connection = *i; if ( connection ) connection->send( bytes, sendSize, _impl->isLocked );
static void zeroBuffer( void ) { memset( getBuffer(), 0, BUFSIZE + 1 ); }