From fe7a8064c7345b284c3df885c666cdf5dbba7b09 Mon Sep 17 00:00:00 2001 From: lordmulder Date: Mon, 3 Jan 2011 22:24:58 +0100 Subject: [PATCH] Better method to detect process elevation. This hopefully prevents that the process from being detected as "elevated" on Vista+ systems that have UAC disabled. --- gui/MainWindow.ui | 33 +++++++++++++--------- res/Icons.qrc | 1 + src/Config.h | 2 +- src/Dialog_About.cpp | 2 +- src/Dialog_MainWindow.cpp | 58 ++++++++++++++++++++++----------------- src/Global.cpp | 25 ++++++++++++----- 6 files changed, 74 insertions(+), 47 deletions(-) diff --git a/gui/MainWindow.ui b/gui/MainWindow.ui index c2affc2c..5362c750 100644 --- a/gui/MainWindow.ui +++ b/gui/MainWindow.ui @@ -386,20 +386,23 @@ - - - Qt::Vertical - - - QSizePolicy::Fixed - - + + - 20 - 3 + 16777215 + 2 - + + QFrame::HLine + + + QFrame::Sunken + + + 1 + + @@ -1160,7 +1163,7 @@ - :/icons/door_out.png:/icons/door_out.png + :/icons/door_in.png:/icons/door_in.png @@ -1466,7 +1469,7 @@ true - + :/flags/gb.png:/flags/gb.png @@ -1482,6 +1485,10 @@ + + + + diff --git a/res/Icons.qrc b/res/Icons.qrc index 46b3b288..7a3a9e70 100644 --- a/res/Icons.qrc +++ b/res/Icons.qrc @@ -35,6 +35,7 @@ icons/delete.png icons/disk.png icons/door_out.png + icons/door_in.png icons/drive_cd.png icons/exclamation.png icons/error.png diff --git a/src/Config.h b/src/Config.h index a4203181..6e7b1b46 100644 --- a/src/Config.h +++ b/src/Config.h @@ -25,7 +25,7 @@ #define VER_LAMEXP_MAJOR 4 #define VER_LAMEXP_MINOR_HI 0 #define VER_LAMEXP_MINOR_LO 0 -#define VER_LAMEXP_BUILD 213 +#define VER_LAMEXP_BUILD 215 #define VER_LAMEXP_SUFFIX TechPreview /* diff --git a/src/Dialog_About.cpp b/src/Dialog_About.cpp index bff2ea3d..357c34f5 100644 --- a/src/Dialog_About.cpp +++ b/src/Dialog_About.cpp @@ -247,7 +247,7 @@ void AboutDialog::showMoreAbout(void) moreAboutText += LINK("http://www.ac3filter.net/projects/tools"); moreAboutText += "

"; - moreAboutText += VSTR(QString("
  • %1 (%2)
    ").arg(tr("MediaInfo - Media File Analysis Tool")), "mediainfo_i386.exe", "v?.?.?"); + moreAboutText += VSTR(QString("
  • %1 (%2)
    ").arg(tr("MediaInfo - Media File Analysis Tool")), "mediainfo_i386.exe", "v?.?.??"); moreAboutText += QString("%1
    ").arg(tr("Released under the terms of the GNU Leser General Public License.")); moreAboutText += LINK("http://mediainfo.sourceforge.net/"); moreAboutText += "

    "; diff --git a/src/Dialog_MainWindow.cpp b/src/Dialog_MainWindow.cpp index 90ab4d4a..08d29f51 100644 --- a/src/Dialog_MainWindow.cpp +++ b/src/Dialog_MainWindow.cpp @@ -74,14 +74,14 @@ #define TEMP_HIDE_DROPBOX(CMD) { bool __dropBoxVisible = m_dropBox->isVisible(); if(__dropBoxVisible) m_dropBox->hide(); CMD; if(__dropBoxVisible) m_dropBox->show(); } //Helper class -class Index: public QObjectUserData -{ -public: - Index(int index) { m_index = index; } - int value(void) { return m_index; } -private: - int m_index; -}; +//class Index: public QObjectUserData +//{ +//public: +// Index(int index) { m_index = index; } +// int value(void) { return m_index; } +//private: +// int m_index; +//}; //////////////////////////////////////////////////////////// // Constructor @@ -222,11 +222,11 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel *metaInfo, S m_tabActionGroup->addAction(actionCompression); m_tabActionGroup->addAction(actionMetaData); m_tabActionGroup->addAction(actionAdvancedOptions); - actionSourceFiles->setUserData(0, new Index(0)); - actionOutputDirectory->setUserData(0, new Index(1)); - actionMetaData->setUserData(0, new Index(2)); - actionCompression->setUserData(0, new Index(3)); - actionAdvancedOptions->setUserData(0, new Index(4)); + actionSourceFiles->setData(0); + actionOutputDirectory->setData(1); + actionMetaData->setData(2); + actionCompression->setData(3); + actionAdvancedOptions->setData(4); actionSourceFiles->setChecked(true); connect(m_tabActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(tabActionActivated(QAction*))); @@ -237,11 +237,11 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel *metaInfo, S m_styleActionGroup->addAction(actionStyleWindowsVista); m_styleActionGroup->addAction(actionStyleWindowsXP); m_styleActionGroup->addAction(actionStyleWindowsClassic); - actionStylePlastique->setUserData(0, new Index(0)); - actionStyleCleanlooks->setUserData(0, new Index(1)); - actionStyleWindowsVista->setUserData(0, new Index(2)); - actionStyleWindowsXP->setUserData(0, new Index(3)); - actionStyleWindowsClassic->setUserData(0, new Index(4)); + actionStylePlastique->setData(0); + actionStyleCleanlooks->setData(1); + actionStyleWindowsVista->setData(2); + actionStyleWindowsXP->setData(3); + actionStyleWindowsClassic->setData(4); actionStylePlastique->setChecked(true); actionStyleWindowsXP->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) >= QSysInfo::WV_XP && lamexp_themes_enabled()); actionStyleWindowsVista->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) >= QSysInfo::WV_VISTA && lamexp_themes_enabled()); @@ -728,7 +728,7 @@ void MainWindow::encodeButtonClicked(void) if(m_fileListModel->rowCount() < 1) { - QMessageBox::warning(this, tr("LameXP"), tr("You must add at least one file to the list before proceeding!")); + QMessageBox::warning(this, tr("LameXP"), QString("%1").arg(tr("You must add at least one file to the list before proceeding!"))); tabWidget->setCurrentIndex(0); return; } @@ -958,7 +958,9 @@ void MainWindow::tabPageChanged(int idx) QList actions = m_tabActionGroup->actions(); for(int i = 0; i < actions.count(); i++) { - if(actions.at(i)->userData(0) && dynamic_cast(actions.at(i)->userData(0))->value() == idx) + bool ok = false; + int actionIndex = actions.at(i)->data().toInt(&ok); + if(ok && actionIndex == idx) { actions.at(i)->setChecked(true); } @@ -970,10 +972,14 @@ void MainWindow::tabPageChanged(int idx) */ void MainWindow::tabActionActivated(QAction *action) { - if(action && action->userData(0)) + if(action && action->data().isValid()) { - int index = dynamic_cast(action->userData(0))->value(); - tabWidget->setCurrentIndex(index); + bool ok = false; + int index = action->data().toInt(&ok); + if(ok) + { + tabWidget->setCurrentIndex(index); + } } } @@ -982,9 +988,11 @@ void MainWindow::tabActionActivated(QAction *action) */ void MainWindow::styleActionActivated(QAction *action) { - if(action && action->userData(0)) + if(action && action->data().isValid()) { - m_settings->interfaceStyle(dynamic_cast(action->userData(0))->value()); + bool ok = false; + int actionIndex = action->data().toInt(&ok); + m_settings->interfaceStyle(actionIndex); } switch(m_settings->interfaceStyle()) diff --git a/src/Global.cpp b/src/Global.cpp index c6f20608..4c8ad3c9 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -422,22 +422,33 @@ static bool lamexp_check_compatibility_mode(const char *exportName) */ static bool lamexp_check_elevation(void) { - typedef enum { lamexp_token_elevation_class = 20 }; - typedef struct { DWORD TokenIsElevated; } LAMEXP_TOKEN_ELEVATION; + typedef enum { lamexp_token_elevationType_class = 18, lamexp_token_elevation_class = 20 } LAMEXP_TOKEN_INFORMATION_CLASS; + typedef enum { lamexp_elevationType_default = 1, lamexp_elevationType_full, lamexp_elevationType_limited } LAMEXP_TOKEN_ELEVATION_TYPE; HANDLE hToken = NULL; bool bIsProcessElevated = false; if(OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) { - LAMEXP_TOKEN_ELEVATION tokenElevation; + LAMEXP_TOKEN_ELEVATION_TYPE tokenElevationType; DWORD returnLength; - if(GetTokenInformation(hToken, (TOKEN_INFORMATION_CLASS) lamexp_token_elevation_class, &tokenElevation, sizeof(LAMEXP_TOKEN_ELEVATION), &returnLength)) + if(GetTokenInformation(hToken, (TOKEN_INFORMATION_CLASS) lamexp_token_elevationType_class, &tokenElevationType, sizeof(LAMEXP_TOKEN_ELEVATION_TYPE), &returnLength)) { - if(returnLength == sizeof(LAMEXP_TOKEN_ELEVATION) && tokenElevation.TokenIsElevated != 0) + if(returnLength == sizeof(LAMEXP_TOKEN_ELEVATION_TYPE)) { - qWarning("Process token is elevated -> potential security risk!\n"); - bIsProcessElevated = true; + switch(tokenElevationType) + { + case lamexp_elevationType_default: + qDebug("Process token elevation type: Default -> UAC is disabled.\n"); + break; + case lamexp_elevationType_full: + qWarning("Process token elevation type: Full -> potential security risk!\n"); + bIsProcessElevated = true; + break; + case lamexp_elevationType_limited: + qDebug("Process token elevation type: Limited -> not elevated.\n"); + break; + } } } CloseHandle(hToken);