Example #1
0
long int WRReadWinNTExeHeader( WResFileID file_handle, exe_pe_header *header )
{
    long int    old_pos;
    uint_16     offset;
    bool        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, PE_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, &PE32( *header ), sizeof( pe_header ) ) == sizeof( pe_header ));
        if( ok && IS_PE64( *header ) ) {
            ok = (ResSeek( file_handle, offset, SEEK_SET ) != -1);
            if( ok ) {
                ok = (read( file_handle, &PE64( *header ), sizeof( pe_header64 ) ) == sizeof( pe_header64 ));
            }
        }
    }

    /* check for valid Win32 EXE */
    if( ok ) {
        ok = WRIsHeaderValidWINNT( header );
    }

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

    if( !ok ) {
        WRDisplayErrorMsg( WR_INVALIDNTEXE );
        offset = 0;
    }

    return( offset );
}
Example #2
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 );
}