VirtualBox

Changeset 82627 in vbox for trunk/src


Ignore:
Timestamp:
Dec 20, 2019 9:22:17 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
135514
Message:

Windows Additions/Installer: Got rid of own system library loading code and use RTLdrLoadSystem() and friends instead.

File:
1 edited

Legend:

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

    r82626 r82627  
    221221
    222222/**
    223  * Loads a system DLL.
    224  *
    225  * @returns Module handle or NULL
    226  * @param   pszName             The DLL name.
    227  */
    228 static HMODULE loadSystemDll(const char *pszName)
    229 {
    230     char   szPath[MAX_PATH];
    231     UINT   cchPath = GetSystemDirectoryA(szPath, sizeof(szPath));
    232     size_t cbName  = strlen(pszName) + 1;
    233     if (cchPath + 1 + cbName > sizeof(szPath))
    234         return NULL;
    235     szPath[cchPath] = '\\';
    236     memcpy(&szPath[cchPath + 1], pszName, cbName);
    237     return LoadLibraryA(szPath);
    238 }
    239 
    240 /**
    241223 * Disables the Windows File Protection for a specified file
    242224 * using an undocumented SFC API call. Don't try this at home!
     
    259241    if (RT_SUCCESS(rc))
    260242    {
    261         HMODULE hSFC = loadSystemDll("sfc_os.dll"); /** @todo Replace this by RTLdr APIs. */
    262         if (NULL != hSFC)
    263         {
    264             g_pfnSfcFileException = (PFNSFCFILEEXCEPTION)GetProcAddress(hSFC, "SfcFileException");
    265             if (g_pfnSfcFileException == NULL)
     243        HMODULE hSFCNative = NULL; /* Native fallback. */
     244
     245        RTLDRMOD hSFC;
     246        rc = RTLdrLoadSystem("sfc_os.dll", true /* fNoUnload */, &hSFC);
     247        if (RT_SUCCESS(rc))
     248        {
     249            rc = RTLdrGetSymbol(hSFC, "SfcFileException", (void **)&g_pfnSfcFileException);
     250            if (RT_FAILURE(rc))
    266251            {
     252                hSFCNative = (HMODULE)RTLdrGetNativeHandle(hSFC);
     253
    267254                /* If we didn't get the proc address with the call above, try it harder with
    268                  * the (zero based) index of the function list. */
    269                 g_pfnSfcFileException = (PFNSFCFILEEXCEPTION)GetProcAddress(hSFC, (LPCSTR)5);
    270                 if (g_pfnSfcFileException == NULL)
    271                     rc = VERR_SYMBOL_NOT_FOUND;
     255                 * the (zero based) index of the function list (ordinal). */
     256                g_pfnSfcFileException = (PFNSFCFILEEXCEPTION)GetProcAddress(hSFCNative, (LPCSTR)5);
     257                if (g_pfnSfcFileException)
     258                    rc = VINF_SUCCESS;
    272259            }
    273         }
    274         else
    275             rc = VERR_FILE_NOT_FOUND;
     260
     261            RTLdrClose(hSFC);
     262        }
    276263
    277264        if (RT_SUCCESS(rc))
     
    283270            {
    284271#else
    285             TCHAR *pwszFile = szFile;
     272                TCHAR *pwszFile = szFile;
    286273#endif
    287274                if (g_pfnSfcFileException(0, pwszFile, UINT32_MAX) != 0)
     
    293280        }
    294281
    295         if (hSFC)
    296             FreeLibrary(hSFC);
     282        if (hSFCNative)
     283            FreeLibrary(hSFCNative);
    297284    }
    298285
Note: See TracChangeset for help on using the changeset viewer.

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