Exemplo n.º 1
0
void COffsetReadHook::ReadObject(CObjectIStream &in, 
                                 const CObjectInfo &object)
{
    CCallStackGuard guard(m_Sniffer->m_CallStack, object);
    
    if (m_EventMode == CObjectsSniffer::eCallAlways) {

        // Clear the discard flag before calling sniffer's event reactors
        m_Sniffer->SetDiscardCurrObject(false);

        m_Sniffer->OnObjectFoundPre(object, in.GetStreamPos());
     
        DefaultRead(in, object);

        m_Sniffer->OnObjectFoundPost(object);

        // Relay discard flag to the stream
        bool discard = m_Sniffer->GetDiscardCurrObject();
        in.SetDiscardCurrObject(discard);
    }
    else {
        if (m_EventMode == CObjectsSniffer::eSkipObject) {
            DefaultSkip(in, object);
        }
        else {
            DefaultRead(in, object);
        }
    }
}
Exemplo n.º 2
0
void CObjectsSniffer::ProbeASN1_Bin(CObjectIStream& input)
{
    TCandidates::const_iterator last_cand = m_Candidates.end();
    for ( ;; ) {
        m_StreamPos = input.GetStreamPos();

        if ( last_cand != m_Candidates.end() ) {
            // Check the previously found candidate first
            // (performance optimization)
            try {
                TCandidates::const_iterator it = last_cand;
                CObjectInfo object_info(it->type_info.GetTypeInfo());
                input.Read(object_info);
                m_TopLevelMap.push_back(
                    SObjectDescription(it->type_info, m_StreamPos));
                _TRACE("Same type ASN.1 binary top level object found:" 
                       << it->type_info.GetTypeInfo()->GetName());
                continue;
            }
            catch ( CEofException& ) {
                // no more objects
                return;
            }
            catch ( exception& ) {
                Reset();
                input.SetStreamPos(m_StreamPos);
            }
        }

        bool found = false;
        // Scan through all candidates
        ITERATE ( TCandidates, it, m_Candidates ) {
            if ( it == last_cand ) {
                // already tried
                continue;
            }
            try {
                CObjectInfo object_info(it->type_info.GetTypeInfo());
                input.Read(object_info);
                found = true;
                last_cand = it;
                m_TopLevelMap.push_back(
                    SObjectDescription(it->type_info, m_StreamPos));
                LOG_POST_X(2, Info 
                           << "ASN.1 binary top level object found:" 
                           << it->type_info.GetTypeInfo()->GetName());
                break;
            }
            catch ( CEofException& ) {
                // no more objects
                return;
            }
            catch ( exception& ) {
                Reset();
                input.SetStreamPos(m_StreamPos);
            }
        }
        if ( !found ) {
            // no matching candidate
            break;
        }
    } // while
}
Exemplo n.º 3
0
void CObjectsSniffer::ProbeText(CObjectIStream& input)
{
    TCandidates::const_iterator last_cand = m_Candidates.end();

    string format_name;  // for LOG_POST messages
    if (input.GetDataFormat() == eSerial_AsnText) {
        format_name = "ASN.1 text";
    } else {
        format_name = "XML";
    }

    try {
        while (true) {
            m_StreamPos = input.GetStreamPos();
            string header = input.ReadFileHeader();

            if ( last_cand != m_Candidates.end() ) {
                // Check the previously found candidate first
                // (performance optimization)
                if (header == last_cand->type_info.GetTypeInfo()->GetName()) {
                    TCandidates::const_iterator it = last_cand;
                    CObjectInfo object_info(it->type_info.GetTypeInfo());
                    input.Read(object_info, CObjectIStream::eNoFileHeader);
                    m_TopLevelMap.push_back(
                        SObjectDescription(it->type_info, m_StreamPos));

                    _TRACE("Same type "
                           << format_name << " top level object found:" 
                           << it->type_info.GetTypeInfo()->GetName());
                    continue;
                }
            }

            bool found = false;
            // Scan through all candidates
            ITERATE ( TCandidates, it, m_Candidates ) {
                if ( header == it->type_info.GetTypeInfo()->GetName() ) {
                    CObjectInfo object_info(it->type_info.GetTypeInfo());
                    input.Read(object_info, CObjectIStream::eNoFileHeader);
                    found = true;
                    last_cand = it;
                    m_TopLevelMap.push_back(
                        SObjectDescription(it->type_info, m_StreamPos));

                    LOG_POST_X(2, Info 
                                << format_name << " top level object found:" 
                                << it->type_info.GetTypeInfo()->GetName());
                    break;
                }
            } // for
            if ( !found ) {
                input.SetStreamPos(m_StreamPos);
                return;
            }
        } // while
    }
    catch (CEofException& /*ignored*/) {
    }
    catch (exception& e) {
        LOG_POST_X(3, Info << "Exception reading "
                   << format_name << " " << e.what());
        input.SetStreamPos(m_StreamPos);
    }
}