Esempio n. 1
0
void OMFLibWalk( libfile io, char *name, void (*rtn)( arch_header *arch, libfile io ) )
/*************************************************************************************/
{
    long            pagelen;
    long            offset;
    arch_header     arch;
    char            buff[ MAX_IMPORT_STRING ];
    int             len;
    unsigned_16     rec_len;
    unsigned_8      type;

    if( LibRead( io, &type, 1 ) != 1 )
        return; // nyi - FALSE?
    if( LibRead( io, &rec_len, 2 ) != 2 )
        return;
    offset = GET_LE_16( rec_len );
    pagelen = offset + 3;
    if( Options.page_size == 0 ) {
        Options.page_size = pagelen;
    }
    LibSeek( io, offset, SEEK_CUR );
    NewArchHeader( &arch, name );
    offset = LibTell( io );
    while( LibRead( io, &type, 1 ) == 1 && ( type == CMD_THEADR ) ) {
        LibSeek( io, 2, SEEK_CUR );
        if( LibRead( io, &type, 1 ) != 1 )
            break;
        len = type;
        if( LibRead( io, buff, len ) != len )
            break;
        buff[ len ] = '\0';
        arch.name = buff;
        LibSeek( io, offset, SEEK_SET );
        rtn( &arch, io );
        offset = LibTell( io );
        offset = ( offset + pagelen - 1 ) & ~( pagelen - 1 );
        LibSeek( io, offset, SEEK_SET );
    }
}
Esempio n. 2
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 );
    }
}