Ejemplo n.º 1
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 );
}
Ejemplo n.º 2
0
WResIDName *WResReadWResIDName( FILE *fp )
/****************************************/
{
    WResIDName      newname;
    WResIDName      *newptr;
    size_t          numread;

    /* read the size of the name in */
    if( ResReadUint8( &(newname.NumChars), fp ) )
        return( NULL );

    /* alloc the space for the new record */
    /* -1 because one of the chars in the name is declared in the struct */
    newptr = WRESALLOC( sizeof( WResIDName ) + newname.NumChars - 1 );
    if( newptr == NULL ) {
        WRES_ERROR( WRS_MALLOC_FAILED );
    } else {
        /* read in the characters */
        newptr->NumChars = newname.NumChars;
        if( (numread = WRESREAD( fp, newptr->Name, newptr->NumChars )) != newptr->NumChars ) {
            WRES_ERROR( WRESIOERR( fp, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE );
            WRESFREE( newptr );
            newptr = NULL;
        }
    }

    return( newptr );
} /* WResReadWResIDName */
Ejemplo n.º 3
0
WResIDName *WResReadWResIDName( WResFileID fid )
/**********************************************/
{
    WResIDName      newname;
    WResIDName      *newptr;
    WResFileSSize   numread;
    bool            error;

    /* read the size of the name in */
    error = ResReadUint8( &(newname.NumChars), fid );

    /* alloc the space for the new record */
    if( error ) {
        return( NULL );
    } else {
        /* -1 because one of the chars in the name is declared in the struct */
        newptr = WRESALLOC( sizeof( WResIDName ) + newname.NumChars - 1 );
    }

    /* read in the characters */
    if( newptr == NULL ) {
        WRES_ERROR( WRS_MALLOC_FAILED );
    } else {
        newptr->NumChars = newname.NumChars;
        numread = WRESREAD( fid, newptr->Name, newptr->NumChars );
        if( numread != newptr->NumChars ) {
            WRES_ERROR( WRESIOERR( fid, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE );
            WRESFREE( newptr );
            newptr = NULL;
        }
    }

    return( newptr );
} /* WResReadWResIDName */
Ejemplo n.º 4
0
static int GetResource( WResLangInfo *res, PHANDLE_INFO hinfo, char *res_buffer )
/***********************************************************************************/
{
    if( WRESSEEK( hinfo->fid, res->Offset, SEEK_SET ) == -1 )
        return( -1 );
    WRESREAD( hinfo->fid, res_buffer, res->Length );
    return( 0 );
}
Ejemplo n.º 5
0
/* look for the resource information in a debugger record at the end of file */
bool FindResources( PHANDLE_INFO hInstance )
{
    long        currpos;
    long        offset;
    dbgheader   header;
    zip_eocd    eocd;
    zip_cdfh    cdfh;
    bool        notfound;

    notfound = true;
    FileShift = 0;
    offset = sizeof( dbgheader );

    /* Look for a PKZIP header and skip archive if present */
    if( WRESSEEK( hInstance->handle, -(long)sizeof( eocd ), SEEK_END ) != -1 ) {
        if( WRESREAD( hInstance->handle, &eocd, sizeof( eocd ) ) == sizeof( eocd ) ) {
            if( memcmp( &eocd.signature, "PK\005\006", 4 ) == 0 ) {
                if( WRESSEEK( hInstance->handle, eocd.cd_offset, SEEK_SET ) != -1 ) {
                    if( WRESREAD( hInstance->handle, &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 );
                        }
                    }
                }
            }
        }
    }
    currpos = WRESSEEK( hInstance->handle, -offset, SEEK_END );
    for( ;; ) {
        WRESREAD( hInstance->handle, &header, sizeof( dbgheader ) );
        if( header.signature == WAT_RES_SIG ) {
            notfound = false;
            FileShift = currpos - header.debug_size + sizeof( dbgheader );
            break;
        } else if( header.signature == VALID_SIGNATURE ||
                   header.signature == FOX_SIGNATURE1 ||
                   header.signature == FOX_SIGNATURE2 ) {
            currpos -= header.debug_size;
            WRESSEEK( hInstance->handle, currpos, SEEK_SET );
        } else {        /* did not find the resource information */
            break;
        }
    }
    return( notfound );
}
Ejemplo n.º 6
0
/*
 * WResReadFixedResRecord1 - reads the fixed part of a Res info record for
 *                           versions 1 and below
 */
bool WResReadFixedResRecord1( WResResInfo1 *newres, FILE *fp )
/************************************************************/
{
    size_t      numread;

    if( (numread = WRESREAD( fp, newres, sizeof( WResResInfo1 ) )) != sizeof( WResResInfo1 ) )
        return( WRES_ERROR( WRESIOERR( fp, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE ) );
    return( false );
}
Ejemplo n.º 7
0
DepInfo *WResGetAutoDep( const char *fname )
{
    WResFileID      handle;
    WResDir         dir;
    bool            dup_discarded;
    WResID          *name;
    WResID          *type;
    WResDirWindow   window;
    WResLangInfo    *info;
    DepInfo         *ret;
    WResFileSSize   numread;

    ret = NULL;
    handle = ResOpenFileRO( fname );
    if( handle != WRES_NIL_HANDLE ) {
        if( WResIsWResFile( handle ) && (dir = WResInitDir()) != NULL ) {
            if( !WResReadDir( handle, dir, &dup_discarded ) ) {
                name = WResIDFromStr( DEP_LIST_NAME );
                type = WResIDFromNum( DEP_LIST_TYPE );
                if( name != NULL && type != NULL ) {
                    window = WResFindResource( type, name, dir, NULL );
                    if( WResIsEmptyWindow( window ) ) {
                        WRES_ERROR( WRS_RES_NOT_FOUND );
                    } else {
                        info = WResGetLangInfo( window );
                        if( WRESSEEK( handle, info->Offset, SEEK_SET ) == -1 ) {
                            WRES_ERROR( WRS_SEEK_FAILED );
                        } else {
                            ret = WRESALLOC( info->Length );
                            if( ret == NULL ) {
                                WRES_ERROR( WRS_MALLOC_FAILED );
                            } else {
                                numread = WRESREAD( handle, ret, info->Length );
                                if( numread != (WResFileSSize)info->Length ) {
                                    WRES_ERROR( WRESIOERR( handle, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE );
                                    ret = NULL;
                                }
                            }
                        }
                    }
                }
                if( name != NULL ) {
                    WResIDFree( name );
                }
                if( type != NULL ) {
                    WResIDFree( type );
                }
            }
            WResFreeDir( dir );
        }
        ResCloseFile( handle );
    }
    return( ret );
}
Ejemplo n.º 8
0
bool ResReadUint32( uint_32 *newint, WResFileID handle )
/******************************************************/
{
    WResFileSSize   numread;

    numread = WRESREAD( handle, newint, sizeof( uint_32 ) );
    if( numread == sizeof( uint_32 ) ) {
        return( false );
    } else {
        WRES_ERROR( WRESIOERR( handle, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE );
    }
    return( true );
}
Ejemplo n.º 9
0
bool ResReadMenuHeader( MenuHeader *currhead, WResFileID handle )
/***************************************************************/
{
    WResFileSSize   numread;

    numread = WRESREAD( handle, currhead, sizeof( MenuHeader ) );
    if( numread != sizeof( MenuHeader ) ) {
        WRES_ERROR( WRESIOERR( handle, numread ) ? WRS_READ_FAILED:WRS_READ_INCOMPLETE );
        return( true );
    } else {
        return( false );
    }
}
Ejemplo n.º 10
0
static int GetResource( WResLangInfo    *res,
                        PHANDLE_INFO    hInstance,
                        char            *res_buffer )
/***************************************************/
{
    long        prevpos;
//    int         numread;

    prevpos = WRESSEEK( WRESHANDLE, res->Offset, SEEK_SET );
    if ( prevpos == -1L ) return( -1 );
//    numread = WRESREAD( WRESHANDLE, res_buffer, res->Length );
    WRESREAD( WRESHANDLE, res_buffer, res->Length );

    return( 0 );
}
Ejemplo n.º 11
0
extern int ResReadUint32( uint_32 * newint, WResFileID handle )
/*************************************************************/
{
    int     numread;

    numread = WRESREAD( handle, newint, sizeof( uint_32 ) );
    if( numread == sizeof( uint_32 ) ) {
        return( FALSE );
    } else if( numread == -1 ) {
        WRES_ERROR( WRS_READ_FAILED );
    } else if( numread != sizeof( uint_32 ) ) {
        WRES_ERROR( WRS_READ_INCOMPLETE );
    }
    return( TRUE );
}
Ejemplo n.º 12
0
int WResReadFixedWResID( WResID *name, WResFileID handle )
/********************************************************/
/* reads the fixed part of a WResID */
{
    int     numread;

    numread = WRESREAD( handle, name, sizeof(WResID) );
    if( numread == sizeof(WResID) ) {
        return( FALSE );
    } else if( numread == -1 ) {
        WRES_ERROR( WRS_READ_FAILED );
    } else {
        WRES_ERROR( WRS_READ_INCOMPLETE );
    }
    return( TRUE );
} /* WResReadFixedWResID */
Ejemplo n.º 13
0
/*
 * WResReadFixedResRecord2 - reads the fixed part of a Res info record for version 2
 */
bool WResReadFixedResRecord2( WResResInfo *newres, FILE *fp )
/***********************************************************/
{
    size_t          numread;
    WResResInfo2    info;

    if( (numread = WRESREAD( fp, &info, sizeof( WResResInfo2 ) )) != sizeof( WResResInfo2 ) )
        return( WRES_ERROR( WRESIOERR( fp, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE ) );
    newres->NumResources = info.NumResources;
    newres->ResName.IsName = info.ResName.IsName;
    if( newres->ResName.IsName ) {
        newres->ResName.ID.Name.Name[0] = info.ResName.ID.Name.Name[0];
        newres->ResName.ID.Name.NumChars = info.ResName.ID.Name.NumChars;
    } else {
        newres->ResName.ID.Num = info.ResName.ID.Num;
    }
    return( false );
}
Ejemplo n.º 14
0
bool ResReadMenuExtraBytes( MenuHeader *header, WResFileID handle, char *buf )
/***************************************************************************/
{
    bool            error;
    WResFileSSize   numread;
    int             size;

    error = false;
    numread = 0;
    size = header->HeaderSize * sizeof( uint_8 );
    if( buf != NULL ) {
        numread = WRESREAD( handle, buf, size );
        if( numread != size ) {
            error = true;
        }
    } else {
        WRESSEEK( handle, size, SEEK_CUR );
    }

    return( error );
}
Ejemplo n.º 15
0
bool WResReadExtraWResID( WResID *name, WResFileID handle )
/*********************************************************/
/* reads the extra bytes into the end of the structure */
/* assumes that the fixed portion has just been read in and is in name and */
/* that name is big enough to hold the extra bytes */
{
    WResFileSSize   numread;
    uint_16         extrabytes;

    if( name->IsName ) {
        extrabytes = name->ID.Name.NumChars - 1;
        if( extrabytes > 0 ) {
            numread = WRESREAD( handle, &(name->ID.Name.Name[1]), extrabytes );
            if( numread != extrabytes ) {
                WRES_ERROR( WRESIOERR( handle, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE );
                return( true );
            }
        }
    }
    return( false );
}
Ejemplo n.º 16
0
WResResInfo *WResReadResRecord( WResFileID handle )
/*************************************************/
/* reads in the fields of a res info record from the current position in */
/* the file identified by fp */
{
    WResResInfo     newres;
    WResResInfo     *newptr;
    WResFileSSize   numread;
    int             numcharsleft;
    bool            error;

    error = WResReadFixedResRecord( &newres, handle );
    if( error ) {
        return( NULL );
    }

    if( newres.ResName.IsName ) {
        numcharsleft = newres.ResName.ID.Name.NumChars - 1;
    } else {
        numcharsleft = 0;
    }
    newptr = WRESALLOC( sizeof( WResResInfo ) + numcharsleft );
    if( newptr == NULL ) {
        WRES_ERROR( WRS_MALLOC_FAILED );
    } else {
        memcpy( newptr, &newres, sizeof( WResResInfo ) );
        if( numcharsleft != 0 ) {
            numread = WRESREAD( handle, newptr->ResName.ID.Name.Name + 1, numcharsleft );
            if( numread != numcharsleft ) {
                WRES_ERROR( WRESIOERR( handle, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE );
                WRESFREE( newptr );
                newptr = NULL;
            }
        }
    }

    return( newptr );
} /* WResReadResRecord */
Ejemplo n.º 17
0
WResID *WResReadWResID( WResFileID handle )
/*****************************************/
{
    WResID          newid;
    WResID          *newidptr;
    WResFileSSize   numread;
    int             extrabytes;     /* chars to be read beyond the fixed size */
    bool            error;

    /* read in the fixed part of the record */
    error = WResReadFixedWResID( &newid, handle );
    if( error ) {
        return( NULL );
    }

    if( newid.IsName ) {
        extrabytes = newid.ID.Name.NumChars - 1;
    } else {
        extrabytes = 0;
    }

    newidptr = WRESALLOC( sizeof( WResID ) + extrabytes );
    if( newidptr == NULL ) {
        WRES_ERROR( WRS_MALLOC_FAILED );
    } else {
        memcpy( newidptr, &newid, sizeof( WResID ) );
        if( extrabytes != 0 ) {
            numread = WRESREAD( handle, newidptr->ID.Name.Name + 1, extrabytes );
            if( numread != extrabytes ) {
                WRES_ERROR( WRESIOERR( handle, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE );
                WRESFREE( newidptr );
                newidptr = NULL;
            }
        }
    }

    return( newidptr );
} /* WResReadWResID */