Esempio n. 1
0
int WRSaveResourceToWinNTEXE ( WRInfo *info, int backup )
{
    int        ok;

    ok = ( ( info->file_type != WR_WIN16_EXE ) &&
           ( info->file_type != WR_WIN16_DLL ) );

    if( !ok ) {
        WRDisplayErrorMsg( WR_NOCONV1632 );
    }

    if( ok ) {
        ok = ( ( info->file_type == WR_WINNT_EXE ) ||
               ( info->file_type == WR_WINNT_DLL ) );
        if( !ok ) {
            WRDisplayErrorMsg( WR_NOTWINNT );
        }
    }

    if( ok ) {
        ok = WRSaveResourceToEXE( info, backup, WR_WINNTW_RES );
    }

    return( ok );
}
Esempio n. 2
0
bool WRLoadResourceFrom_RC( WRInfo *info )
{
    WResTargetOS        target_os;
    WRFileType          target;
    char                fn_path[_MAX_PATH];
    bool                is_wres;
    bool                ok;

    ok = (info != NULL && info->file_name != NULL);

    if( ok ) {
        WRGetInternalRESName( info->file_name, fn_path );
    }

#ifndef __NT__
    if( ok ) {
        target = WRIdentifyFile( fn_path );
        ok = !WRIs32Bit( target );
        if( !ok ) {
            WRDisplayErrorMsg( WR_NOLOAD32IN16 );
        }
    }
#endif

    if( ok ) {
        ok = loadResDirFromRES( info, fn_path, &is_wres );
    }

    if( ok ) {
        target_os = WResGetTargetOS( info->dir );
        target = WR_INVALID_FILE;
        switch( target_os ) {
        case WRES_OS_WIN16:
            target = WR_WIN16M_RES;
            if( is_wres ) {
                target = WR_WIN16W_RES;
            }
            break;
        case WRES_OS_WIN32:
            target = WR_WINNTM_RES;
            if( is_wres ) {
                target = WR_WINNTW_RES;
            }
            break;
        }
        info->internal_type = target;
        if( target == WR_INVALID_FILE ) {
            WRDisplayErrorMsg( WR_INVALIDFILE );
            ok = false;
        }
    }

    if( ok ) {
        info->internal_filename = WRStrDup( fn_path );
        ok = (info->internal_filename != NULL);
    }

    return( ok );
}
Esempio n. 3
0
static bool loadResDirFromRES( WRInfo *info, const char *filename, bool *is_wres )
{
    WResFileID  fid;
    bool        dup_discarded;
    bool        ok;

    ok = ((fid = ResOpenFileRO( filename )) != WRES_NIL_HANDLE);

    if( ok ) {
        *is_wres = WResIsWResFile( fid );
    }

    if( ok ) {
        ok = ((info->dir = WResInitDir()) != NULL);
    }

    if( ok ) {
        ok = !WResReadDir( fid, info->dir, &dup_discarded );
        if( ok && dup_discarded ) {
            WRDisplayErrorMsg( WR_DUPRESDISCARD );
        }
    }

    if( fid != WRES_NIL_HANDLE ) {
        ResCloseFile( fid );
    }

    return( ok );
}
Esempio n. 4
0
void * WRAPI WRCopyResData( WRInfo *info, WResLangNode *lnode )
{
    void        *rdata;
    int         ok;

    rdata = NULL;

    ok = (info != NULL && lnode != NULL);

    if( ok && lnode->data != NULL ) {
        return( WRCopyExistingData( lnode ) );
    }

    if( ok ) {
        ok = (lnode->Info.Length < UINT_MAX);
        if( !ok ) {
            WRDisplayErrorMsg( WR_RESTOOLARGE );
        }
    }

    if( ok ) {
        rdata = WRLoadResData( info->tmp_file, lnode->Info.Offset, lnode->Info.Length );
        ok = (rdata != NULL);
    }

    if( !ok ) {
        if( rdata != NULL ) {
            WRMemFree( rdata );
            rdata = NULL;
        }
    }

    return( rdata );
}
Esempio n. 5
0
bool WRHandleWinNTLangIDEntry( WResFileID file, WResDir *dir, WResID *type,
                               WResID *name, resource_dir_entry *rd_entry )
{
    WResLangType    lang;
    resource_entry  res_entry;
    uint_32         offset;
    bool            ok;

    ok = (name != NULL);

    if( ok ) {
        /* is the entry_rva is a subdir */
        if( rd_entry->entry_rva & PE_RESOURCE_MASK_ON ) {
            WRDisplayErrorMsg( WR_BADLANGDISCARDNAME );
            ok = false;
        } else {
            offset = WR_MAP_RES_RVA( rd_entry->entry_rva );
            ok = WRReadResourceEntry( file, offset, &res_entry );
        }
    }

    if( ok ) {
        offset = WR_MAP_DATA_RVA( res_entry.data_rva );
        lang.lang = HIWORD( rd_entry->id_name );
        lang.sublang = LOWORD( rd_entry->id_name );
        ok = !WResAddResource( type, name, 0, offset, res_entry.size, *dir, &lang, NULL );
    }

    return( ok );
}
Esempio n. 6
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 );
}
Esempio n. 7
0
bool WRLoadResourceFromRES( WRInfo *info )
{
    WResTargetOS        target_os;
    WRFileType          target;
    bool                is_wres;
    bool                ok;

    ok = WRLoadResDirFromRES( info, &is_wres );

    if( ok ) {
        target_os = WResGetTargetOS( info->dir );
        target = WR_INVALID_FILE;
        switch( target_os ) {
        case WRES_OS_WIN16:
            target = WR_WIN16M_RES;
            if( is_wres ) {
                target = WR_WIN16W_RES;
            }
            break;
        case WRES_OS_WIN32:
            target = WR_WINNTM_RES;
            if( is_wres ) {
                target = WR_WINNTW_RES;
            }
            break;
        }
        if( target == WR_INVALID_FILE ) {
            WRDisplayErrorMsg( WR_INVALIDFILE );
            ok = false;
        } else if( target != info->file_type ) {
            if( target == WR_WIN16W_RES ) {
                WRDisplayErrorMsg( WR_BADFILEWWIN16 );
            } else if( target == WR_WINNTW_RES ) {
                WRDisplayErrorMsg( WR_BADFILEWWINNT );
            } else if( target == WR_WIN16M_RES ) {
                WRDisplayErrorMsg( WR_BADFILEMWIN16 );
            } else if( target == WR_WINNTM_RES ) {
                WRDisplayErrorMsg( WR_BADFILEMWINNT );
            }
            ok = false;
        }
    }

    return( ok );
}
Esempio n. 8
0
int WRSaveIconResource( WRInfo *info, int backup )
{
    WResTypeNode        *tnode;
    WResResNode         *rnode;
    WResLangNode        *lnode;
    WResLangType        lang;
    BYTE                *data;
    uint_32             size;
    int                 use_rename;
    int                 ok;

    data = NULL;
    lang.lang = DEF_LANG;
    lang.sublang = DEF_SUBLANG;

    ok = ( info && info->dir );

    if( ok ) {
        if( backup && WRFileExists ( info->save_name ) ) {
            use_rename = ( info->file_name &&
                           stricmp( info->file_name, info->save_name ) );
            ok = WRBackupFile( info->save_name, use_rename );
        }
    }

    if( ok ) {
        tnode = WRFindTypeNode( info->dir, (uint_16)RT_GROUP_ICON, NULL );
        ok = ( tnode != NULL );
        if( !ok ) {
            WRDisplayErrorMsg( WR_PRJNOICON );
        }
    }

    if( ok ) {
        rnode = tnode->Head;
        ok = ( rnode != NULL );
    }

    if( ok ) {
        lnode = WRFindLangNodeFromLangType( rnode, &lang );
        ok = ( lnode != NULL );
    }

    if( ok ) {
        ok = WRCreateIconData( info, lnode, &data, &size );
    }

    if( ok ) {
        ok = WRSaveDataToFile( info->save_name, data, size );
    }

    if( data ) {
        WRMemFree( data );
    }

    return( ok );
}
Esempio n. 9
0
bool WRHandleWinNTNameEntry( WResFileID file, WResDir *dir, WResID *type,
                             resource_dir_entry *rd_entry, bool is_name )
{
    WResLangType    def_lang;
    resource_entry  res_entry;
    uint_32         offset;
    WResID          *name;
    bool            add_now;
    bool            ok;

    def_lang.lang = DEF_LANG;
    def_lang.sublang = DEF_SUBLANG;

    /* verify the id_name */
    if ( ((rd_entry->id_name & PE_RESOURCE_MASK_ON) && !is_name) ||
            (!(rd_entry->id_name & PE_RESOURCE_MASK_ON) && is_name) ) {
        WRDisplayErrorMsg( WR_BADIDDISCARDNAME );
        return( FALSE );
    }

    if( is_name ) {
        name = WRGetUniCodeWResID( file, PE_RESOURCE_MASK & rd_entry->id_name );
    } else {
        name = WResIDFromNum( rd_entry->id_name );
    }

    ok = (name != NULL);

    if( ok ) {
        /* is the entry_rva is a subdir */
        if( rd_entry->entry_rva & PE_RESOURCE_MASK_ON ) {
            add_now = false;
            ok = WRHandleWinNTLangIDDir( file, dir, type, name,
                                         rd_entry->entry_rva & PE_RESOURCE_MASK );
        } else {
            /* will this to happen often ???? */
            add_now = true;
            offset = WR_MAP_RES_RVA( rd_entry->entry_rva );
            ok = WRReadResourceEntry( file, offset, &res_entry );
        }
    }

    if( ok ) {
        if( add_now ) {
            offset = WR_MAP_RES_RVA( res_entry.data_rva );
            ok = !WResAddResource( type, name, 0, offset, res_entry.size,
                                   *dir, &def_lang, NULL );
        }
    }

    if( name != NULL ) {
        WResIDFree( name );
    }

    return( ok );
}
Esempio n. 10
0
bool WRHandleWinNTTypeEntry( WResFileID file, WResDir *dir,
                             resource_dir_entry *rd_entry, int is_name )
{
    WResID  *type;
    bool    ok;

    /* verify the id_name */
    if( ((rd_entry->id_name & PE_RESOURCE_MASK_ON) && !is_name) ||
            (!(rd_entry->id_name & PE_RESOURCE_MASK_ON) && is_name) ) {
        WRDisplayErrorMsg( WR_BADIDDISCARDTYPE );
        return( FALSE );
    }

    if( is_name ) {
        type = WRGetUniCodeWResID( file, PE_RESOURCE_MASK & rd_entry->id_name );
    } else {
        type = WResIDFromNum( rd_entry->id_name );
    }

    ok = (type != NULL);

    if( ok ) {
        /* verify that entry_rva is a subdir */
        ok = ((rd_entry->entry_rva & PE_RESOURCE_MASK_ON) != 0);
        if( !ok ) {
            WRDisplayErrorMsg( WR_BADRVADISCARDTYPE );
        }
    }

    if( ok ) {
        ok = WRHandleWinNTNameDir( file, dir, type, rd_entry->entry_rva & PE_RESOURCE_MASK );
    }

    if( type != NULL ) {
        WResIDFree( type );
    }

    return( ok );
}
Esempio n. 11
0
static bool WRSetWinInfo( HWND hdlg, WRSelectImageInfo *info )
{
    WResTypeNode        *tnode;
    bool                lbox_set;

    if( info == NULL || hdlg == (HWND)NULL ) {
        return( false );
    }

    lbox_set = false;

    tnode = WRFindTypeNode( info->info->dir, (uint_16)(pointer_int)RT_BITMAP, NULL );
    if( tnode != NULL ) {
        CheckDlgButton( hdlg, IDM_SELIMGBMP, BST_CHECKED );
        info->type = (uint_16)(pointer_int)RT_BITMAP;
        WRSetEntries( hdlg, info );
        lbox_set = true;
    } else {
        EnableWindow( GetDlgItem( hdlg, IDM_SELIMGBMP ), FALSE );
    }

    tnode = WRFindTypeNode( info->info->dir, (uint_16)(pointer_int)RT_GROUP_CURSOR, NULL );
    if( tnode != NULL ) {
        if( !lbox_set ) {
            CheckDlgButton( hdlg, IDM_SELIMGCUR, BST_CHECKED );
            info->type = (uint_16)(pointer_int)RT_GROUP_CURSOR;
            WRSetEntries( hdlg, info );
            lbox_set = true;
        }
    } else {
        EnableWindow( GetDlgItem( hdlg, IDM_SELIMGCUR ), FALSE );
    }

    tnode = WRFindTypeNode( info->info->dir, (uint_16)(pointer_int)RT_GROUP_ICON, NULL );
    if( tnode != NULL ) {
        if( !lbox_set ) {
            CheckDlgButton( hdlg, IDM_SELIMGICO, BST_CHECKED );
            info->type = (uint_16)(pointer_int)RT_GROUP_ICON;
            WRSetEntries( hdlg, info );
            lbox_set = true;
        }
    } else {
        EnableWindow( GetDlgItem( hdlg, IDM_SELIMGICO ), FALSE );
    }

    if( !lbox_set ) {
        WRDisplayErrorMsg( WR_PRJNOIMAGES );
    }

    return( lbox_set );
}
Esempio n. 12
0
static bool saveResourceToRES( WRInfo *info, bool backup, const char *save_name, const char *file_name )
{
    WResFileID  src_fid;
    WResFileID  dst_fid;
    bool        is_wres;
    bool        ok;
    bool        use_rename;
    WRFileType  save_type;

    src_fid = WRES_NIL_HANDLE;
    dst_fid = WRES_NIL_HANDLE;

    ok = true;

    if( ok ) {
        save_type = info->save_type;
        if( save_type != WR_WIN16M_RES && save_type != WR_WIN16W_RES &&
            save_type != WR_WINNTM_RES && save_type != WR_WINNTW_RES ) {
            if( info->internal_type != WR_DONT_KNOW ) {
                save_type = info->internal_type;
            }
        }
#ifndef __NT__
        ok = !WRIs32Bit( save_type );
        if( !ok ) {
            WRDisplayErrorMsg( WR_NOSAVE32IN16 );
        }
#endif
    }

    if( ok ) {
        if( backup && WRFileExists( save_name ) ) {
            use_rename = (file_name != NULL && stricmp( file_name, save_name ));
            ok = WRBackupFile( save_name, use_rename );
        }
    }

    if( ok ) {
        if( file_name != NULL ) {
            ok = ((src_fid = ResOpenFileRO( info->tmp_file )) != WRES_NIL_HANDLE);
        }
    }

    is_wres = (save_type == WR_WIN16W_RES || save_type == WR_WINNTW_RES);

    if( ok ) {
        ok = ((dst_fid = ResOpenNewFile( save_name )) != WRES_NIL_HANDLE);
        if( ok && is_wres ) {
            ok = !WResFileInit( dst_fid );
        }
    }

    if( ok ) {
        if( is_wres ) {
            ok = WRSaveResourceToWRES( info, src_fid, dst_fid );
        } else {
            ok = WRSaveResourceToMRES( info, src_fid, dst_fid );
        }
    }

    if( src_fid != WRES_NIL_HANDLE ) {
        ResCloseFile( src_fid );
    }

    if( dst_fid != WRES_NIL_HANDLE ) {
        ResCloseFile( dst_fid );
    }

    if( !ok ) {
        if( dst_fid != WRES_NIL_HANDLE ) {
            WRDeleteFile( save_name );
        }
    }

    return( ok );
}
Esempio n. 13
0
int WRLoadWResDirFromWin16EXE( WResFileID file_handle, WResDir *dir )
{
    os2_exe_header  win_header;
    long int        offset;
    uint_16         align_shift;
    uint_32         name_offset;
    WResTypeNode    *type_node;
    uint_8          *name_table;
    uint_8          *leftover;
    uint_32         name_table_len;
    uint_32         num_leftover;
    int             ok;

    ok = (file_handle != -1);

    if( ok ) {
        ok = ((*dir = WResInitDir()) != NULL);
    }

    if( ok ) {
        ok = ((offset = WRReadWin16ExeHeader( file_handle, &win_header )) != 0);
    }

    /* check if a resource table is present */
    if( ok ) {
        ok = WRWin16HeaderHasResourceTable( &win_header );
        if( !ok ) {
            return( TRUE );
        }
    }

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

    if( ok ) {
        ok = (ResSeek( file_handle, win_header.resource_off, SEEK_CUR ) != -1);
    }

    if( ok ) {
        ResReadUint16( &align_shift, file_handle );
        ok = (align_shift <= 16);
        if( !ok ) {
            WRDisplayErrorMsg( WR_BADEXE );
        }
    }

    if( ok ) {
        (*dir)->NumResources = 0;
        type_node = WRReadWResTypeNodeFromExe( file_handle, align_shift );
        while( type_node != NULL ) {
            type_node->Next = NULL;
            type_node->Prev = (*dir)->Tail;
            if( (*dir)->Tail != NULL ) {
                (*dir)->Tail->Next = type_node;
            }
            if ( (*dir)->Head == NULL ) {
                (*dir)->Head = type_node;
            }
            (*dir)->Tail = type_node;
            (*dir)->NumTypes++;
            (*dir)->NumResources += type_node->Info.NumResources;
            type_node = WRReadWResTypeNodeFromExe ( file_handle, align_shift );
        }
        name_offset = tell( file_handle ) - offset - win_header.resource_off;
        ok = WRReadResourceNames( *dir, file_handle, name_offset );
    }

    if( ok && win_header.expver <= 0x300 ) {
        num_leftover = 0;
        leftover = NULL;
        name_table_len = WRReadNameTable( *dir, file_handle,
                                          &name_table, num_leftover, leftover );
        while( name_table_len != 0 ) {
            num_leftover = WRUseNameTable( *dir, name_table, name_table_len, &leftover );
            if( name_table != NULL ) {
                WRMemFree( name_table );
            }
            name_table_len = WRReadNameTable( NULL, file_handle, &name_table,
                                              num_leftover, leftover );
            if( leftover != NULL ) {
                WRMemFree( leftover );
                leftover = NULL;
            }
        }
    }

    return( ok );
}
Esempio n. 14
0
int WRSaveBitmapResource( WRInfo *info, int backup )
{
    int                 ok;
    WResTypeNode        *tnode;
    WResLangNode        *lnode;
    BYTE                *data;
    uint_32             dsize;

    ok = ( info && info->dir );

    if( ok ) {
        tnode = WRFindTypeNode( info->dir, (uint_16)RT_BITMAP, NULL );
        ok = ( tnode != NULL );
        if( !ok ) {
            WRDisplayErrorMsg( WR_PRJNOBMP );
        }
    }

    if( ok ) {
        ok = ((info->dir->NumTypes == 1) && (info->dir->NumResources == 1));
        if( !ok ) {
            WRDisplayErrorMsg( WR_PRJMORETHANONE );
        }
    }

    if( ok ) {
        lnode = NULL;
        if( tnode->Head && tnode->Head->Head ) {
            lnode = tnode->Head->Head;
        }
        ok = ( lnode != NULL );
    }

    if( ok ) {
        if( lnode->data == NULL ) {
            lnode->data = WRLoadResData( info->file_name, lnode->Info.Offset,
                                         lnode->Info.Length );
        }
        ok = ( lnode->data && lnode->Info.Length );
    }

    if( ok ) {
        data = lnode->data;
        dsize = lnode->Info.Length;
        ok = WRAddBitmapFileHeader( &data, &dsize );
    }

    if( ok ) {
        lnode->data = data;
        lnode->Info.Length = dsize;
        ok = WRSaveImageToFile( info, tnode, backup );
    }

    if( ok ) {
        data = lnode->data;
        dsize = lnode->Info.Length;
        ok = WRStripBitmapFileHeader( &data, &dsize );
    }

    if( ok ) {
        lnode->data = data;
        lnode->Info.Length = dsize;
    }

    return( ok );
}
Esempio n. 15
0
WINEXPORT BOOL CALLBACK WRSelectFileTypeProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
    WRSFT       *sft;
    BOOL        ret;

    ret = FALSE;

    switch( message ) {
    case WM_DESTROY:
        WRUnregisterDialog( hDlg );
        break;

    case WM_INITDIALOG:
        sft = (WRSFT *)lParam;
        SET_DLGDATA( hDlg, sft );
        WRRegisterDialog( hDlg );
        WRSetWinInfo( hDlg, sft );
        ret = TRUE;
        break;

    case WM_SYSCOLORCHANGE:
        WRCtl3dColorChange();
        break;

    case WM_COMMAND:
        switch( LOWORD( wParam ) ) {
        case IDM_SFTHELP:
            sft = (WRSFT *)GET_DLGDATA( hDlg );
            if( sft != NULL && sft->hcb != NULL ) {
                (*(void (*)(void))sft->hcb)();
            }
            break;

        case IDOK:
            sft = (WRSFT *)GET_DLGDATA( hDlg );
            if( sft == NULL ) {
                EndDialog( hDlg, FALSE );
                ret = TRUE;
            } else if( WRGetWinInfo( hDlg, sft ) ) {
                EndDialog( hDlg, TRUE );
                ret = TRUE;
            } else {
                WRDisplayErrorMsg( WR_INVALIDSELECTION );
            }
            break;

        case IDCANCEL:
            EndDialog( hDlg, FALSE );
            ret = TRUE;
            break;

        case IDM_TSWINNT:
            if( GET_WM_COMMAND_CMD( wParam, lParam ) != BN_CLICKED ) {
                break;
            }
            if( !IsDlgButtonChecked( hDlg, IDM_FTRES ) ) {
                break;
            }
            if( IsDlgButtonChecked( hDlg, LOWORD( wParam ) ) ) {
                EnableWindow( GetDlgItem( hDlg, IDM_RFMS ), FALSE );
                CheckDlgButton( hDlg, IDM_RFMS, BST_UNCHECKED );
                CheckDlgButton( hDlg, IDM_RFWAT, BST_CHECKED );
            } else {
                EnableWindow( GetDlgItem( hDlg, IDM_RFMS ), TRUE );
            }
            break;

        case IDM_TSWIN:
            if( GET_WM_COMMAND_CMD( wParam, lParam ) != BN_CLICKED ) {
                break;
            }
            if( !IsDlgButtonChecked( hDlg, IDM_FTRES ) ) {
                break;
            }
            if( IsDlgButtonChecked( hDlg, LOWORD( wParam ) ) ) {
                EnableWindow( GetDlgItem( hDlg, IDM_RFMS ), TRUE );
            }
            break;

        case IDM_FTEXE:
        case IDM_FTDLL:
            if( GET_WM_COMMAND_CMD( wParam, lParam ) != BN_CLICKED ) {
                break;
            }
            if( IsDlgButtonChecked( hDlg, LOWORD( wParam ) ) ) {
                EnableWindow( GetDlgItem( hDlg, IDM_RFWAT ), FALSE );
                EnableWindow( GetDlgItem( hDlg, IDM_RFMS ), FALSE );
                CheckDlgButton( hDlg, IDM_RFWAT, BST_UNCHECKED );
                CheckDlgButton( hDlg, IDM_RFMS, BST_UNCHECKED );
            }
            break;

        case IDM_FTRES:
            if( GET_WM_COMMAND_CMD( wParam, lParam ) != BN_CLICKED ) {
                break;
            }
            if( IsDlgButtonChecked( hDlg, LOWORD( wParam ) ) ) {
                EnableWindow( GetDlgItem( hDlg, IDM_RFWAT ), TRUE );
                if( IsDlgButtonChecked( hDlg, IDM_TSWINNT ) ) {
                    EnableWindow( GetDlgItem( hDlg, IDM_RFMS ), FALSE );
                    CheckDlgButton( hDlg, IDM_RFMS, BST_UNCHECKED );
                    CheckDlgButton( hDlg, IDM_RFWAT, BST_CHECKED );
                } else {
                    EnableWindow( GetDlgItem( hDlg, IDM_RFMS ), TRUE );
                    CheckDlgButton( hDlg, IDM_RFMS, BST_UNCHECKED );
                    CheckDlgButton( hDlg, IDM_RFWAT, BST_CHECKED );
                }
            }
            break;
        }
        break;
    }

    return( ret );
}
Esempio n. 16
0
bool WRLoadWResDirFromWinNTEXE( WResFileID file_handle, WResDir *dir )
{
    exe_pe_header       nt_header;
    pe_object           *otable;
    uint_32             physical_size;
    uint_32             physical_offset;
    int                 i;
    bool                ok;
    unsigned_32         resource_rva;

    ok = (file_handle != -1);

    if( ok ) {
        ok = ((*dir = WResInitDir()) != NULL);
    }

    if( ok ) {
        ok = (WRReadWinNTExeHeader( file_handle, &nt_header ) != 0);
    }

    /* check if a resource table is present */
    if( ok ) {
        ok = WRWinNTHeaderHasResourceTable( &nt_header );
        if( !ok ) {
            WRDisplayErrorMsg( WR_EXENORES );
            return( TRUE );
        }
    }

    /* read NT object table */
    otable = NULL;
    if( ok ) {
        ok = WRReadNTObjectTable( file_handle, &nt_header, &otable );
    }

    /* find resource object in object table */
    resource_rva = 0;
    if( ok ) {
        int         num_objects;
        unsigned_32 file_align;

        physical_size = 0;
        physical_offset = 0;
        if( IS_PE64( nt_header ) ) {
            resource_rva = PE64( nt_header ).table[PE_TBL_RESOURCE].rva;
            num_objects = PE64( nt_header ).num_objects;
            file_align = PE64( nt_header ).file_align;
        } else {
            resource_rva = PE32( nt_header ).table[PE_TBL_RESOURCE].rva;
            num_objects = PE32( nt_header ).num_objects;
            file_align = PE32( nt_header ).file_align;
        }
        for( i = 0; i < num_objects; i++ ) {
            if( otable[i].rva == resource_rva ) {
                physical_size = otable[i].physical_size;
                physical_offset = otable[i].physical_offset;
                break;
            }
        }
        ok = (physical_size != 0 && physical_offset != 0 && physical_size % file_align == 0 && physical_offset % file_align == 0);
    }

    if( otable != NULL ) {
        MemFree( otable );
    }

    /* read the resource information */
    if( ok ) {
        res_offset = physical_offset;
        res_rva = resource_rva;
        ok = WRHandleWinNTTypeDir( file_handle, dir, physical_offset );
    }

    return( ok );
}