bool Qca2ByteArrayChecksumAlgorithm::calculateChecksum( QString* result,
                                                        const Okteta::AbstractByteArrayModel* model, const Okteta::AddressRange& range ) const
{
    QCA::Hash hash( mType );

    // TODO: find a way without needing to copy, perhaps by smart iterator which can return spans of original data
    // TODO: see if buffer size could be a value which matches the algorithm and qca2

    char buffer[CalculatedByteCountSignalLimit];
    int bufferLength = CalculatedByteCountSignalLimit;
    Okteta::Address nextBlockEnd = range.start() + CalculatedByteCountSignalLimit;
    for( Okteta::Address i = range.start(); i<=range.end(); i+=CalculatedByteCountSignalLimit )
    {
        if( range.end() < i+CalculatedByteCountSignalLimit )
            bufferLength = range.end() - i + 1;
        model->copyTo( reinterpret_cast<Okteta::Byte*>(buffer), i, bufferLength );
        hash.update( buffer, bufferLength );

        if( i >= nextBlockEnd )
        {
            nextBlockEnd += CalculatedByteCountSignalLimit;
            emit calculatedBytes( range.localIndex(i)+1 );
        }
    }

    const QByteArray hashResult = hash.final().toByteArray();

    *result = QCA::arrayToHex( hashResult );
    return true;
}
quint16 ModSum16ByteArrayChecksumAlgorithm::calculateModSumWithBigEndian( const Okteta::AbstractByteArrayModel* model, const Okteta::AddressRange& range ) const
{
    quint16 modSum = 0x0000;
    Okteta::Address nextBlockEnd = range.start() + CalculatedByteCountSignalLimit;

    // TODO: move padding checks into extra code before and after loop
    for( Okteta::Address i = range.start(); i<=range.end(); ++i )
    {
        quint16 value = (quint16)( (quint8)(model->byte( i )) ) << 8;
        ++i;
        if( i<=range.end() )
            value |= (quint16)( (quint8)(model->byte( i )) );

        modSum += value;
#if 0
        const uchar value = (crcBits & 0xFF) + model->byte( i );
        crcBits >>= 8;
        crcBits ^= lookupTable[value];
#endif
        if( i >= nextBlockEnd )
        {
            nextBlockEnd += CalculatedByteCountSignalLimit;
            emit calculatedBytes( range.localIndex(i)+1 );
        }
    }

    return modSum;
}
Ejemplo n.º 3
0
bool OrByteArrayFilter::filter( Okteta::Byte* result,
                                Okteta::AbstractByteArrayModel *model, const Okteta::AddressRange& range ) const
{
    const QByteArray operand = mParameterSet.operand();
    const int operandSize = operand.size();

    if( mParameterSet.alignAtEnd() )
    {
        const int behindLastResult = range.width();
        int r = behindLastResult;
        Okteta::Address m = range.nextBehindEnd();
        int nextBlockEnd = r - FilteredByteCountSignalLimit;

        while( m > range.start() )
        {
            int o = operandSize;
            while( m > range.start() && o > 0 )
                result[(r--)-1] = model->byte( (m--)-1 ) | operand[(o--)-1];

            if( r <= nextBlockEnd )
            {
                nextBlockEnd -= FilteredByteCountSignalLimit;
                emit filteredBytes( behindLastResult - r );
            }
        }
    }
    else
    {
        Okteta::Address r = 0;
        Okteta::Address m = range.start();
        Okteta::Address nextBlockEnd = FilteredByteCountSignalLimit;

        while( m <= range.end() )
        {
            int o = 0;
            while( m <= range.end() && o < operandSize )
                result[r++] = model->byte( m++ ) | operand[o++];

            if( r >= nextBlockEnd )
            {
                nextBlockEnd += FilteredByteCountSignalLimit;
                emit filteredBytes( r );
            }
        }
    }

    return true;
}
bool Adler32ByteArrayChecksumAlgorithm::calculateChecksum( QString* result,
                                                           const Okteta::AbstractByteArrayModel* model, const Okteta::AddressRange& range ) const
{
    quint32 a = 1;
    quint32 b = 0;

    // TODO: this is the "inefficient but straightforward implementation" from the Wikipedia entry, search for improved
    Okteta::Address nextBlockEnd = range.start() + CalculatedByteCountSignalLimit;
    for( Okteta::Address i = range.start(); i<=range.end(); ++i )
    {
        a = (a + model->byte( i )) % MOD_ADLER;
        b = (b + a) % MOD_ADLER;

        if( i >= nextBlockEnd )
        {
            nextBlockEnd += CalculatedByteCountSignalLimit;
            emit calculatedBytes( range.localIndex(i)+1 );
        }
    }

    const quint32 sum = (b << 16) | a;
    *result = QString::fromLatin1("%1").arg( sum, 8, 16, QChar::fromLatin1('0') );

    return true;
}
Ejemplo n.º 5
0
bool ByteArrayValuesStreamEncoder::encodeDataToStream( QIODevice *device,
                                                       const ByteArrayView* byteArrayView,
                                                       const Okteta::AbstractByteArrayModel* byteArrayModel,
                                                       const Okteta::AddressRange& range )
{
    bool success = true;

    // settings
    mSettings.undefinedChar = byteArrayView->undefinedChar();
    mSettings.substituteChar = byteArrayView->substituteChar();
    mSettings.valueCoding = (Okteta::ValueCoding)byteArrayView->valueCoding();

    // encode
    QTextStream textStream( device );

    Okteta::ValueCodec* valueCodec = Okteta::ValueCodec::createCodec( mSettings.valueCoding );

    // prepare 
    QString valueString;
    valueString.resize( valueCodec->encodingWidth() );

    for( Okteta::Address i=range.start(); i<=range.end(); ++i )
    {
        if( i > range.start() )
            textStream << mSettings.separation;

        valueCodec->encode( valueString, 0, byteArrayModel->byte(i) );

        textStream << valueString;
    }
    // clean up
    delete valueCodec;

    return success;
}
Ejemplo n.º 6
0
ByteArrayView::ByteArrayView( ByteArrayView* other, ByteArrayViewProfileSynchronizer* synchronizer,
                              Qt::Alignment alignment )
    : AbstractView( static_cast<ByteArrayDocument*>(other->baseModel()) )
    , mDocument( static_cast<ByteArrayDocument*>(other->baseModel()) )
    , mByteArrayViewProfileSynchronizer( synchronizer )
{
    init();

    mWidget->setStartOffset( other->startOffset() );
    mWidget->setFirstLineOffset( other->firstLineOffset() );

    setViewModus( other->viewModus() );
    setVisibleByteArrayCodings( other->visibleByteArrayCodings() );
    toggleOffsetColumn( other->offsetColumnVisible() );
    setOffsetCoding( other->offsetCoding() );

    setCharCoding( other->charCodingName() );
    setShowsNonprinting( other->showsNonprinting() );
    setSubstituteChar( other->substituteChar() );
    setUndefinedChar( other->undefinedChar() );

    setValueCoding( other->valueCoding() );

    setNoOfGroupedBytes( other->noOfGroupedBytes() );
    setNoOfBytesPerLine( other->noOfBytesPerLine() );
    // TODO: this can lead to different layouts due to possible one-pixel difference in width!
    setLayoutStyle( other->layoutStyle() );

    const Okteta::AddressRange selection = other->selection();
    setSelection( selection.start(), selection.end() );
    setZoomLevel( other->zoomLevel() );
    setCursorPosition( other->cursorPosition() );

    setOverwriteMode( other->isOverwriteMode() );
    setReadOnly( other->isReadOnly() );
    // TODO: all width

    const QRect otherViewRect = other->mWidget->viewRect();

    QPoint viewPos = otherViewRect.topLeft();
    if( alignment == Qt::AlignBottom )
    {
        viewPos.setY( otherViewRect.bottom() + 1 );
    }
    // TODO: care for resize style
    else if( alignment == Qt::AlignRight )
    {
        viewPos.setX( otherViewRect.right() + 1 );
    }
    // TODO: doesn't really work at this stage, because the widget will get resized when inserted
    // and then ensureCursorVisible destroys the fun
    mWidget->setViewPos( viewPos );

    synchronizer->setView( this );
}
Ejemplo n.º 7
0
bool InvertByteArrayFilter::filter( Okteta::Byte* result,
                                    Okteta::AbstractByteArrayModel *model, const Okteta::AddressRange& range ) const
{
    int r = 0;
    Okteta::Address m = range.start();
    int nextBlockEnd = FilteredByteCountSignalLimit;
    while( m <= range.end() )
    {
        result[r++] = ~model->byte( m++ );

        if( r >= nextBlockEnd )
        {
            nextBlockEnd += FilteredByteCountSignalLimit;
            emit filteredBytes( r );
        }
    }

    return true;
}