uint64_t BinaryRefReader::get_var_int(uint8_t* nRead)
{
   uint32_t nBytes;
   uint64_t varInt = BtcUtils::readVarInt( bdRef_.getPtr() + pos_, getSizeRemaining(), &nBytes);
   if(nRead != NULL)
      *nRead = nBytes;
   pos_ += nBytes;
   return varInt;
}
Пример #2
0
/* 
 *  Get maximum loop iterations possible
 * 
 *          p: packet data structure, same as the one found in snort.
 *       loop: structure that defines buffer via flags, and has cursor increment
 *     cursor: current position within buffer
 *
 * Returns: 
 *    >= 0 : calculated max possible loop count
 *     < 0 : error
 *
 * Notes:
 *    This function is a sanity check on a loop count.  It presumes the caller is looking
 *    through a content buffer, cursor_increment hops at a time.  It calculates how many whole
 *    hops (plus a last partial hop) are possible given the remaining buffer size.  Passing in
 *    a cursor of NULL means look at the whole buffer.
 *
 */
int32_t getLoopLimit(void *p, LoopInfo *loop, const u_int8_t *cursor)
{
    int32_t loop_max;
    int size;

    size = getSizeRemaining(p, loop->cursorAdjust->flags, cursor);

    if ( size < 0 )
        return -1;

    /* Calculate how many whole hops are within buffer */
    loop_max = size/(loop->cursorAdjust->offset);

    /* Add one for partial hop remaining */
    if ( size%(loop->cursorAdjust->offset) != 0 )
        loop_max++;

    /* Sanity check; limit size to 65535 */
    return loop_max & 0xFFFF;
}