Exemplo n.º 1
0
WdeDialogBoxInfo *WdeMem2DBI( const uint_8 *data, size_t size, bool is32bit )
{
    WdeDialogBoxInfo    *dbi;
    WdeDialogBoxControl *control;
    LIST                *prev_control;
    int                 index;
    const uint_8        *start;
    bool                ok;
    bool                is32bitEx = false;
    uint_16             sign0;
    uint_16             sign1;

    dbi = NULL;
    start = NULL;

    ok = (data != NULL && size != 0);

    if( ok ) {
        dbi = (WdeDialogBoxInfo *)WRMemAlloc( sizeof( WdeDialogBoxInfo ) );
        ok = (dbi != NULL);
    }


    if( ok ) {
        start = data;

        /* check if the dialog is extended by testing for the signature */
        U16FromMem( data, sign0 );
        U16FromMem( data, sign1 );
        is32bitEx = (sign0 == 0x0001 && sign1 == 0xFFFF);

        data = start;
        dbi->control_list = NULL;
        dbi->MemoryFlags = 0;
        dbi->dialog_header = WdeMem2DialogBoxHeader( &data, is32bit, is32bitEx );
        ok = (dbi->dialog_header != NULL);
    }

    if( ok ) {
        prev_control = NULL;
        for( index = 0; index < GETHDR_NUMITEMS( dbi->dialog_header ); index++ ) {
            if( is32bit ) {
                PADDING_SET( data, start );
            }
            control = WdeMem2DialogBoxControl( &data, is32bit, is32bitEx );
            if( control == NULL ) {
                ok = false;
                break;
            }
            if( prev_control == NULL ) {
                ListAddElt( &dbi->control_list, (void *)control );
                prev_control = dbi->control_list;
            } else {
                ListInsertElt( prev_control, (void *)control );
                prev_control = ListNext( prev_control );
            }
        }
    }

    if( ok ) {
        ok = ( size >= data - start );
    }

    if( !ok ) {
        if( dbi != NULL ) {
            WdeFreeDialogBoxInfo( dbi );
            dbi = NULL;
        }
    }

    return( dbi );
}
Exemplo n.º 2
0
WdeDialogBoxInfo *WdeMem2DBI( uint_8 *data, uint_32 size, Bool is32bit )
{
    WdeDialogBoxInfo    *dbi;
    WdeDialogBoxControl *control;
    LIST                *prev_control;
    int                 index, pad;
    uint_8              *d;
    Bool                ok;
    Bool                is32bitEx = FALSE;
    uint_16             signa[2];

    dbi = NULL;

    ok = ( data && size );

    if( ok ) {
        d = data;
        dbi = (WdeDialogBoxInfo *) WdeMemAlloc( sizeof(WdeDialogBoxInfo) );
        ok = ( dbi != NULL );
    }


    if( ok ) {
        /* check if the dialog is extended by testing for the signature */
        memcpy(signa, data, sizeof(signa));
        is32bitEx = (signa[0] == 0x0001 && signa[1] == 0xFFFF);

        dbi->control_list  = NULL;
        dbi->MemoryFlags   = 0;
        if (is32bitEx) {
            dbi->dialog_header = WdeMem2DialogBoxExHeader( &data );
        } else {
            dbi->dialog_header = WdeMem2DialogBoxHeader( &data, is32bit );
        }
        ok = ( dbi->dialog_header != NULL );
    }

    if( ok ) {
        prev_control = NULL;
        for( index = 0; index < GETHDR_NUMITEMS(dbi->dialog_header); index++ ) {
            if( is32bit ) {
                pad = CALC_PAD( data - d, sizeof(uint_32) );
                data += pad;
            }
            control = WdeMem2DialogBoxControl( &data, is32bit, is32bitEx );
            if( control == NULL  ) {
                ok = FALSE;
                break;
            }
            if ( prev_control == NULL ) {
                ListAddElt( &(dbi->control_list), (void *) control);
                prev_control = dbi->control_list;
            } else {
                ListInsertElt( prev_control, (void *) control);
                prev_control = ListNext(prev_control);
            }
        }
    }

    if( ok ) {
        ok = ( size >= ( data - d ) );
    }

    if( !ok ) {
        if( dbi ) {
            WdeFreeDialogBoxInfo( dbi );
            dbi = NULL;
        }
    }

    return ( dbi );
}