Exemple #1
0
WResFileOffset ResTell( WResFileID fid )
/**************************************/
/* cover function for tell */
{
    WResFileOffset  posn;

    posn = WRESTELL( fid );
    if( posn == -1 ) {
        WRES_ERROR( WRS_TELL_FAILED );
    }
    return( posn );
}
Exemple #2
0
long ResTell( FILE *fp )
/**********************/
/* cover function for tell */
{
    long    posn;

    posn = WRESTELL( fp );
    if( posn == -1L ) {
        WRES_ERROR( WRS_TELL_FAILED );
    }
    return( posn );
}
Exemple #3
0
extern off_t ResTell( WResFileID handle )
/***************************************/
/* cover function for tell */
{
    off_t       posn;

    posn = WRESTELL( handle );
    if( posn == -1L ) {
        WRES_ERROR( WRS_TELL_FAILED );
    }
    return( posn );
}
Exemple #4
0
/* look for the resource information in a debugger record at the end of file */
bool FindResourcesX( PHANDLE_INFO hinfo, bool res_file )
{
    long                currpos;
    long                offset;
    master_dbg_header   header;
    zip_eocd            eocd;
    zip_cdfh            cdfh;
    bool                notfound;

    notfound = !res_file;
    WResFileShift = 0;
    if( notfound ) {
        offset = sizeof( master_dbg_header );

        /* Look for a PKZIP header and skip archive if present */
        if( !WRESSEEK( hinfo->fp, -(long)sizeof( eocd ), SEEK_END ) ) {
            if( WRESREAD( hinfo->fp, &eocd, sizeof( eocd ) ) == sizeof( eocd ) ) {
                if( memcmp( &eocd.signature, "PK\005\006", 4 ) == 0 ) {
                    if( !WRESSEEK( hinfo->fp, eocd.cd_offset, SEEK_SET ) ) {
                        if( WRESREAD( hinfo->fp, &cdfh, sizeof( cdfh ) ) == sizeof( cdfh ) ) {
                            if( memcmp( &cdfh.signature, "PK\001\002", 4 ) == 0 ) {
                                offset += eocd.cd_offset + eocd.cd_size - cdfh.offset + sizeof( eocd );
                            }
                        }
                    }
                }
            }
        }
        WRESSEEK( hinfo->fp, -offset, SEEK_END );
        currpos = WRESTELL( hinfo->fp );
        for( ;; ) {
            WRESREAD( hinfo->fp, &header, sizeof( master_dbg_header ) );
            if( header.signature == WAT_RES_SIG ) {
                notfound = false;
                WResFileShift = currpos - header.debug_size + sizeof( master_dbg_header );
                break;
            } else if( header.signature == WAT_DBG_SIGNATURE ||
                       header.signature == FOX_SIGNATURE1 ||
                       header.signature == FOX_SIGNATURE2 ) {
                currpos -= header.debug_size;
                WRESSEEK( hinfo->fp, currpos, SEEK_SET );
            } else {        /* did not find the resource information */
                break;
            }
        }
    }
    return( notfound );
}
Exemple #5
0
extern int ResPadDWord( WResFileID handle )
/*****************************************/
/* advances in the file to the next DWORD boundry */
{
    long        curr_pos;
    long        padding;
    int         error;

    error = FALSE;
    curr_pos = WRESTELL( handle );
    if( curr_pos == -1 ) {
        WRES_ERROR( WRS_TELL_FAILED );
        error = TRUE;
    } else {
        padding = RES_PADDING( curr_pos, sizeof(uint_32) );
        curr_pos = WRESSEEK( handle, padding, SEEK_CUR );
        if( curr_pos == -1L ) {
            WRES_ERROR( WRS_SEEK_FAILED );
            error = TRUE;
        }
    }
    return( error );
}
Exemple #6
0
bool ResWritePadDWord( WResFileID handle )
/****************************************/
{
    WResFileOffset  curr_pos;
    WResFileSize    padding;
    bool            error;
    uint_32         zero = 0;

    error = false;
    curr_pos = WRESTELL( handle );
    if( curr_pos == -1 ) {
        WRES_ERROR( WRS_TELL_FAILED );
        return( true );
    }
    padding = RES_PADDING( curr_pos, sizeof( uint_32 ) );
    if( padding != 0 ) {
        if( (WResFileSize)WRESWRITE( handle, &zero, padding ) != padding ) {
            WRES_ERROR( WRS_WRITE_FAILED );
            return( true );
        }
    }
    return( false );
}
Exemple #7
0
static int readMResDir( WResFileID handle, WResDir currdir, int *dup_discarded,
                        char iswin32, void *fileinfo )
/******************************************************************************/
{
    MResResourceHeader     *head = NULL;
    M32ResResourceHeader   *head32 = NULL;
    WResDirWindow           dup;
    int                     error;
    off_t                   seek_rc;
    WResID                 *name;
    WResID                 *type;

    error = FALSE;
    if( iswin32 ) {
        /* Read NULL header */
        head32 = M32ResReadResourceHeader( handle );
        if( head32 != NULL ) {
            MResFreeResourceHeader( head32->head16 );
            WRESFREE( head32 );
        } else {
            error = TRUE;
        }
        if( !error ) {
            head32 = M32ResReadResourceHeader( handle );
            if( head32 != NULL ) {
                head = head32->head16;
            } else {
                error = TRUE;
            }
        }
    } else {
        head = MResReadResourceHeader( handle );
        if( head == NULL ) error = TRUE;
    }
    if(  dup_discarded != NULL  ) {
        *dup_discarded = FALSE;
    }
    if( iswin32 ) {
        currdir->TargetOS = WRES_OS_WIN32;
    } else {
        currdir->TargetOS = WRES_OS_WIN16;
    }
    /* assume that a NULL head is the EOF which is the only way of detecting */
    /* the end of a MS .RES file */
    while( head != NULL && !( iswin32 && head32 == NULL ) && !error ) {
        name = WResIDFromNameOrOrd( head->Name );
        type = WResIDFromNameOrOrd( head->Type );
        error = (name == NULL || type == NULL);

        /* MResReadResourceHeader leaves the file at the start of the resource*/
        if( !error ) {
            if( !type->IsName && type->ID.Num == RT_NAMETABLE ) {
                error = FALSE;
            } else {
                error = WResAddResource2( type, name, head->MemoryFlags,
                                          WRESTELL( handle ), head->Size, currdir, NULL,
                                          &dup, fileinfo );
                if(  error && !WResIsEmptyWindow( dup ) ) {
                    error = FALSE;
                    if(  dup_discarded != NULL  ) {
                        *dup_discarded = TRUE;
                    }
                }
            }
        }

        if( !error ) {
            seek_rc = WRESSEEK( handle, head->Size, SEEK_CUR );
            if( seek_rc == -1L ) {
                error =  TRUE;
                WRES_ERROR( WRS_SEEK_FAILED );
            }
        }

        if( name != NULL ) {
            WRESFREE( name );
            name = NULL;
        }
        if( type != NULL ) {
            WRESFREE( type );
            type = NULL;
        }
        MResFreeResourceHeader( head );
        if( iswin32 ) {
            WRESFREE( head32 );
        }

        if( !error ) {
            if( iswin32 ) {
                head32 = M32ResReadResourceHeader( handle );
                if( head32 != NULL ) {
                    head = head32->head16;
                }
            } else {
                head = MResReadResourceHeader( handle );
            }
        }
    }

    return( error );

} /* readMResDir */