static
YR_RULES*
    loadYaraRules
    (
        RPU8 buffer,
        RU32 bufferSize
    )
{
    YR_RULES* rules = NULL;
    YR_STREAM stream = { 0 };

    stream.read = _yara_stream_read;
    stream.write = _yara_stream_write;
    if( NULL != ( stream.user_data = rpal_blob_createFromBuffer( buffer, bufferSize ) ) )
    {
        if( ERROR_SUCCESS != yr_rules_load_stream( &stream, &rules ) )
        {
            rules = NULL;
        }

        rpal_blob_freeWrapperOnly( stream.user_data );
    }

    return rules;
}
RVOID
rpal_stringbuffer_freeWrapper
(
    rString pStringBuffer
)
{
    if( rpal_memory_isValid( pStringBuffer ) )
    {
        rpal_blob_freeWrapperOnly( ( (_rString*)pStringBuffer )->blob );
        rpal_memory_free( pStringBuffer );
    }
}
Exemple #3
0
static
RBOOL
    postHttp
    (
        RPCHAR location,
        RPCHAR params,
        RBOOL isEnforceCert,
        RPVOID* receivedData,
        RU32* receivedSize
    )
{
    RBOOL isSuccess = FALSE;
    CURL* curlCtx = NULL;
    RU32 timeout = ( 1000 * 10 );
    RCHAR userAgent[] = "rpHCP";
    rBlob dataReceived = NULL;
    RBOOL isDataReturned = FALSE;
    CURLcode curlError = CURLE_OK;
    
    if( NULL != location )
    {
        if( NULL != ( dataReceived = rpal_blob_create( 0, 0 ) ) )
        {
            if( NULL != ( curlCtx = curl_easy_init() ) )
            {
                rpal_debug_info( "posting to %s", location );
                
                if( CURLE_OK == ( curlError = curl_easy_setopt( curlCtx, CURLOPT_URL, location ) ) &&
                    CURLE_OK == ( curlError = curl_easy_setopt( curlCtx, CURLOPT_USERAGENT, userAgent ) ) &&
                    CURLE_OK == ( curlError = curl_easy_setopt( curlCtx, CURLOPT_POSTFIELDS, params ) ) &&
                    CURLE_OK == ( curlError = curl_easy_setopt( curlCtx, CURLOPT_WRITEFUNCTION, (RPVOID)_curlToBuffer ) ) &&
                    CURLE_OK == ( curlError = curl_easy_setopt( curlCtx, CURLOPT_WRITEDATA, (RPVOID)dataReceived ) ) &&
                    CURLE_OK == ( curlError = curl_easy_setopt( curlCtx, CURLOPT_NOSIGNAL, 1 ) ) )
                {
                    if( CURLE_OK == ( curlError = curl_easy_perform( curlCtx ) ) )
                    {
                        isSuccess = TRUE;
                        
                        if( NULL != receivedData )
                        {
                            *receivedData = rpal_blob_getBuffer( dataReceived );
                            isDataReturned = TRUE;
                        }
                        if( NULL != receivedSize )
                        {
                            *receivedSize = rpal_blob_getSize( dataReceived );
                        }
                    }
                    else
                    {
                        rpal_debug_warning( "error performing post: %d", curlError );
                    }
                }
                else
                {
                    rpal_debug_error( "error setting curl options: %d", curlError );
                }
                
                curl_easy_cleanup( curlCtx );
            }
            else
            {
                rpal_debug_error( "error creating curl context" );
            }
            
            if( !isDataReturned )
            {
                rpal_blob_free( dataReceived );
            }
            else
            {
                rpal_blob_freeWrapperOnly( dataReceived );
            }
        }
    }
    
    return isSuccess;
}