void LibWalk( libfile io, char *name, void (*rtn)( arch_header *, libfile io ) )
/******************************************************************************/
{
    ar_header           ar;
    arch_header         arch;
    file_offset         bytes_read;
//    int                 dict_count;
    file_offset         pos;

//    dict_count = 0;
    arch.fnametab = NULL;
    arch.ffnametab = NULL;
    while( (bytes_read = LibRead( io, &ar, AR_HEADER_SIZE )) != 0 ) {
        if( bytes_read != AR_HEADER_SIZE ) {
            BadLibrary( name );
        }
        if( strncmp( ar.header_ident, AR_HEADER_IDENT, AR_HEADER_IDENT_LEN ) ) {
            BadLibrary( name );
        }
        GetARHeaderValues( &ar, &arch );
        pos = LibTell( io );
        if( ar.name[ 0 ] == '/' && ar.name[ 1 ] == ' ' && ar.name[ 2 ] == ' ' ) {
            // Ignore symbol table.
/*
            dict_count++;
            if( dict_count == 2 ) {
                error = readDict( &arch );
            } else {
                error = MoveAheadFrom( &arch );
                updateNewArchive( &arch );
            }
*/
        } else if( ar.name[ 0 ] == '/' && ar.name[ 1 ] == '/' && ar.name[ 2 ] == ' ' ) {
            AllocFNameTab( name, io, &arch );
        } else if( ar.name[ 0 ] == '/' && ar.name[ 1 ] == '/' && ar.name[ 2 ] == '/' ) {
            AllocFFNameTab( name, io, &arch );
        } else {
            arch.name = GetARName( io, &ar, &arch );
            arch.ffname = GetFFName( &arch );
            rtn( &arch, io );
            MemFree( arch.name );
            MemFree( arch.ffname );
        }
        if( arch.size & 1 )
            ++arch.size;
        LibSeek( io, pos + arch.size, SEEK_SET );
    }
    MemFree( arch.fnametab );
    MemFree( arch.ffnametab );
}
Exemple #2
0
static int ReadOMFDict( file_list *list, unsigned_8 *header, bool makedict )
/***************************************************************************/
{
    omf_dict_entry  *omf_dict;
    unsigned        reclength;

    header += sizeof( unsigned_8 );
    reclength = _ReadLittleEndian16UN( header ) + 3;
    if( makedict ) {
        if( list->u.dict == NULL ) {
            _ChkAlloc( list->u.dict, sizeof( dict_entry ) );
        }
        omf_dict = &list->u.dict->o;
        omf_dict->cache = NULL;
        header += sizeof( unsigned_16 );
        omf_dict->start = _ReadLittleEndian32UN( header );
        header += sizeof( unsigned_32 );
        omf_dict->pages = _ReadLittleEndian16UN( header );
        header += sizeof( unsigned_16 );
        if( omf_dict->start == 0 || omf_dict->pages == 0 ) {
            BadLibrary( list );
            return( -1 );
        }
        omf_dict->rec_length = reclength;
    }
    return( reclength );
}
Exemple #3
0
mod_entry *SearchLib( file_list *lib, char *name )
/********************************************************/
/* Search the specified library file for the specified name & make a module */
{
    mod_entry           *obj;
    unsigned long       pos;
    unsigned long       dummy;
    bool                retval;

    pos = 0;
    if( lib->u.dict == NULL ) {
        if( CheckLibraryType( lib, &pos, TRUE ) == -1 )
            return( NULL );
        if( !(lib->status & STAT_IS_LIB) ) {
            BadLibrary( lib );
            return( NULL );
        }
    }
    if( lib->status & STAT_OMF_LIB ) {
        retval = OMFSearchExtLib( lib, name, &pos );
    } else {
        retval = ARSearchExtLib( lib, name, &pos );
    }
    if( !retval )
        return( NULL );

/*
    update lib struct since we found desired object file
*/
    obj = NewModEntry();
    obj->name = IdentifyObject( lib, &pos, &dummy );
    obj->location = pos;
    obj->f.source = lib;
    obj->modtime = lib->file->modtime;
    obj->modinfo = (lib->status & DBI_MASK) | (ObjFormat & FMT_OBJ_FMT_MASK);
    return( obj );
}
Exemple #4
0
static void ProcessLibOrObj( char *name, objproc obj, void (*process)( arch_header *arch, libfile io ) )
{
    libfile     io;
    unsigned char   buff[ AR_IDENT_LEN ];
    arch_header arch;

    NewArchHeader( &arch, name );
    io = LibOpen( name, LIBOPEN_READ );
    if( LibRead( io, buff, sizeof( buff ) ) != sizeof( buff ) ) {
        FatalError( ERR_CANT_READ, name, strerror( errno ) );
    }
    if( memcmp( buff, AR_IDENT, sizeof( buff ) ) == 0 ) {
        // AR format
        AddInputLib( io, name );
        LibWalk( io, name, process );
        if( Options.libtype == WL_LTYPE_NONE ) {
            Options.libtype = WL_LTYPE_AR;
        }
    } else if( memcmp( buff, LIBMAG, LIBMAG_LEN ) == 0 ) {
        // MLIB format
        if( LibRead( io, buff, sizeof( buff ) ) != sizeof( buff ) ) {
            FatalError( ERR_CANT_READ, name, strerror( errno ) );
        }
        if( memcmp( buff, LIB_CLASS_DATA_SHOULDBE, LIB_CLASS_LEN + LIB_DATA_LEN ) ) {
            BadLibrary( name );
        }
        AddInputLib( io, name );
        LibWalk( io, name, process );
        if( Options.libtype == WL_LTYPE_NONE ) {
            Options.libtype = WL_LTYPE_MLIB;
        }
    } else if( AddImport( &arch, io ) ) {
        LibClose( io );
    } else if( buff[ 0 ] == LIB_HEADER_REC && buff[ 1 ] != 0x01 ) {
        /*
          The buff[ 1 ] != 1 bit above is a bad hack to get around
          the fact that the coff cpu_type for PPC object files is
          0x1f0.  Really, we should be reading in the first object
          record and doing the checksum and seeing if it is actually
          a LIB_HEADER_REC.  All file format designers who are too
          stupid to recognize the need for a signature should be
          beaten up with large blunt objects.
         */
        // OMF format
        AddInputLib( io, name );
        LibSeek( io, 0, SEEK_SET );
        if( Options.libtype == WL_LTYPE_NONE ) {
            Options.libtype = WL_LTYPE_OMF;
        }
        OMFLibWalk( io, name, process );
    } else if( obj == OBJ_PROCESS ) {
        // Object
        LibSeek( io, 0, SEEK_SET );
        AddObjectSymbols( &arch, io, 0 );
        LibClose( io );
    } else if( obj == OBJ_ERROR ) {
        BadLibrary( name );
    } else {
        LibClose( io );
    }
}