VirtualBox

Ignore:
Timestamp:
Mar 29, 2011 11:37:01 AM (14 years ago)
Author:
vboxsync
Message:

Windows Guest Additions installer: Try to replace WFP protected files on the fly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/Installer/InstallHelper/VBoxGuestInstallHelper.cpp

    r35351 r36455  
    55
    66/*
    7  * Copyright (C) 2010 Oracle Corporation
     7 * Copyright (C) 2011 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2626HINSTANCE g_hInstance;
    2727HWND g_hwndParent;
     28
     29typedef DWORD (__stdcall *fnSfcFileException) (DWORD param1, PWCHAR param2, DWORD param3);
     30fnSfcFileException g_pfnSfcFileException = NULL;
    2831
    2932#define VBOXINSTALLHELPER_EXPORT extern "C" void __declspec(dllexport)
     
    181184}
    182185
     186/**
     187 * Disables the Windows File Protection for a specified file
     188 * using an undocumented SFC API call. Don't try this at home!
     189 *
     190 * @param   hwndParent          Window handle of parent.
     191 * @param   string_size         Size of variable string.
     192 * @param   variables           The actual variable string.
     193 * @param   stacktop            Pointer to a pointer to the current stack.
     194 */
     195VBOXINSTALLHELPER_EXPORT DisableWFP(HWND hwndParent, int string_size,
     196                                    TCHAR *variables, stack_t **stacktop)
     197{
     198    TCHAR szFile[MAX_PATH + 1];
     199    HRESULT hr = VBoxPopString(szFile, sizeof(szFile) / sizeof(TCHAR));
     200    if (SUCCEEDED(hr))
     201    {
     202        HMODULE hSFC = LoadLibrary("sfc_os.dll");
     203        if (NULL != hSFC)
     204        {
     205            g_pfnSfcFileException = (fnSfcFileException)GetProcAddress(hSFC, "SfcFileException");
     206            if (g_pfnSfcFileException == NULL)
     207            {
     208                /* If we didn't get the proc address with the call above, try it harder with
     209                 * the (zero based) index of the function list. */
     210                g_pfnSfcFileException = (fnSfcFileException)GetProcAddress(hSFC, (LPCSTR)5);
     211                if (g_pfnSfcFileException == NULL)
     212                    hr = HRESULT_FROM_WIN32(ERROR_PROC_NOT_FOUND);
     213            }
     214        }
     215        else
     216            hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
     217
     218        if (SUCCEEDED(hr))
     219        {
     220            WCHAR wszFile[MAX_PATH + 1];
     221            hr = StringCchPrintfW(wszFile, sizeof(wszFile), L"%s", szFile);
     222            if (SUCCEEDED(hr))
     223                hr = HRESULT_FROM_WIN32(g_pfnSfcFileException(0, wszFile, -1));
     224        }
     225
     226        if (hSFC)
     227            FreeLibrary(hSFC);
     228    }
     229
     230    /* Push simple return value on stack. */
     231    SUCCEEDED(hr) ? pushstring("0") : pushstring("1");
     232}
     233
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette