Esempio n. 1
0
static bool IdentifyWinExeHeader( FILE *fh, bool win16 )
{
    os2_exe_header  os2_hdr;
    exe_pe_header   pe_hdr;
    uint_16         offset;
    bool            ok;

    ok = ( fh != NULL );

    if( ok ) {
        ok = ( fseek( fh, 0x18, SEEK_SET ) == 0 );
    }

    /* check the reloc offset */
    if( ok ) {
        ok = ( fread( &offset, 1, sizeof( offset ), fh ) == sizeof( offset ) && offset >= 0x0040 );
    }

    if( ok ) {
        ok = ( fseek( fh, NH_OFFSET, SEEK_SET ) == 0 );
    }

    /* check the header offset */
    if( ok ) {
        ok = ( fread( &offset, 1, sizeof( offset ), fh ) == sizeof( offset ) && offset != 0 );
    }

    /* seek to the header */
    if( ok ) {
        ok = ( fseek( fh, offset, SEEK_SET ) == 0 );
    }

    if( ok ) {
        if( win16 ) {
            ok = ( fread( &os2_hdr, 1, sizeof( os2_hdr ), fh ) == sizeof( os2_hdr ));
            /* check for valid Win16 EXE */
            if( ok ) {
                return( WRIsHeaderValidWIN16( &os2_hdr ) );
            }
        } else {
            ok = ( fread( &PE32( pe_hdr ), 1, sizeof( pe_header ), fh ) == sizeof( pe_header ) );
            if( ok && IS_PE64( pe_hdr ) ) {
                /* seek to the header again */
                ok = ( fseek( fh, offset, SEEK_SET ) == 0 );
                if( ok ) {
                    ok = ( fread( &PE64( pe_hdr ), 1, sizeof( pe_header64 ), fh ) == sizeof( pe_header64 ) );
                }
            }
            /* check for valid Win32 EXE */
            if( ok ) {
                return( WRIsHeaderValidWINNT( &pe_hdr ) );
            }
        }
    }

    return( false );
}
Esempio n. 2
0
long int WRReadWin16ExeHeader( WResFileID file_handle, os2_exe_header *header )
{
    long int    old_pos;
    uint_16     offset;
    int         ok;

    old_pos = -1;

    ok = (file_handle != -1 && header != NULL);

    if( ok ) {
        ok = ((old_pos = ResSeek( file_handle, 0x18, SEEK_SET )) != -1);
    }

    /* check the reloc offset */
    if( ok ) {
        ResReadUint16( &offset, file_handle );
        ok = (offset >= 0x0040);
    }

    if( ok ) {
        ok = (ResSeek( file_handle, OS2_NE_OFFSET, SEEK_SET ) != -1);
    }

    /* check header offset */
    if( ok ) {
        ResReadUint16( &offset, file_handle );
        ok = (offset != 0x0000);
    }

    if( ok ) {
        ok = (ResSeek( file_handle, offset, SEEK_SET ) != -1);
    }

    if( ok ) {
        ok = (read( file_handle, header, sizeof( os2_exe_header ) ) ==
              sizeof( os2_exe_header ));
    }

    /* check for valid Win16 EXE */
    if( ok ) {
        ok = WRIsHeaderValidWIN16( header );
    }

    if( old_pos != -1 ) {
        ok = (ResSeek( file_handle, old_pos, SEEK_SET ) != -1 && ok);
    }

    if( ok ) {
        return( offset );
    } else {
        return( 0 );
    }
}