VirtualBox

Changeset 67979 in vbox


Ignore:
Timestamp:
Jul 15, 2017 11:02:00 AM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
116982
Message:

Added RTUTf16NICmpAscii.

Location:
trunk
Files:
7 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/mangling.h

    r67797 r67979  
    34853485# define RTUtf16End                                     RT_MANGLER(RTUtf16End)
    34863486# define RTUtf16ICmpAscii                               RT_MANGLER(RTUtf16ICmpAscii)
     3487# define RTUtf16NICmpAscii                              RT_MANGLER(RTUtf16NICmpAscii)
    34873488# define RTUtf16NLen                                    RT_MANGLER(RTUtf16NLen)
    34883489# define RTUtf16NLenEx                                  RT_MANGLER(RTUtf16NLenEx)
  • trunk/include/iprt/nt/nt.h

    r67360 r67979  
    26642664                                                                 IN PSIZE_T pcbFilename OPTIONAL,
    26652665                                                                 IN PSIZE_T pcbNeeded OPTIONAL);
     2666/** @since Windows 8.
     2667 * @note Status code is always zero in windows 10 build 14393. */
     2668NTSYSAPI NTSTATUS ApiSetQueryApiSetPresence(IN PCUNICODE_STRING pAllegedApiSetDll, OUT PBOOLEAN pfPresent);
     2669/** @copydoc ApiSetQueryApiSetPresence */
     2670typedef NTSTATUS (NTAPI *PFNAPISETQUERYAPISETPRESENCE)(IN PCUNICODE_STRING pAllegedApiSetDll, OUT PBOOLEAN pfPresent);
     2671
    26662672
    26672673# ifdef IPRT_NT_USE_WINTERNL
  • trunk/include/iprt/utf16.h

    r67391 r67979  
    462462
    463463/**
    464  * Performs a case insensitive string compare between an UTF-16 string and an
     464 * Performs a case insensitive string compare between an UTF-16 string and a
    465465 * pure ASCII string.
    466466 *
     
    525525 */
    526526RTDECL(int) RTUtf16BigNICmp(PCRTUTF16 pwsz1, PCRTUTF16 pwsz2, size_t cwcMax);
     527
     528/**
     529 * Performs a case insensitive string compare between a UTF-16 string and a pure
     530 * ASCII string, stopping after N characters.
     531 *
     532 * Since this compare only takes cares about the first 128 codepoints in
     533 * unicode, no tables are needed and there aren't any real complications.
     534 *
     535 * @returns < 0 if the first string less than the second string.
     536 * @returns 0 if the first string identical to the second string.
     537 * @returns > 0 if the first string greater than the second string.
     538 * @param   pwsz1       The UTF-16 first string. Null is allowed.
     539 * @param   psz2        The pure ASCII second string. Null is allowed.
     540 * @param   cwcMax      Maximum number of UTF-16 characters to compare.
     541 */
     542RTDECL(int) RTUtf16NICmpAscii(PCRTUTF16 pwsz1, const char *psz2, size_t cwcMax);
     543
    527544
    528545/**
  • trunk/src/VBox/HostDrivers/Support/Makefile.kmk

    r66714 r67979  
    313313        $(VBOX_PATH_RUNTIME_SRC)/common/string/RTUtf16PrintHexBytes.cpp \
    314314        $(VBOX_PATH_RUNTIME_SRC)/common/string/RTUtf16ICmpAscii.cpp \
     315        $(VBOX_PATH_RUNTIME_SRC)/common/string/RTUtf16NICmpAscii.cpp \
    315316        $(VBOX_PATH_RUNTIME_SRC)/common/string/RTUtf16CatAscii.cpp \
    316317        $(VBOX_PATH_RUNTIME_SRC)/common/string/RTUtf16CopyAscii.cpp \
  • trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp

    r67978 r67979  
    16721672
    16731673/**
     1674 * Checks if the given name is a valid ApiSet name.
     1675 *
     1676 * This is only called on likely looking names.
     1677 *
     1678 * @returns true if ApiSet name, false if not.
     1679 * @param   pName               The name to check out.
     1680 */
     1681static bool supR3HardenedIsApiSetDll(PUNICODE_STRING pName)
     1682{
     1683    /*
     1684     * API added in Windows 8, or so they say.
     1685     */
     1686    if (ApiSetQueryApiSetPresence != NULL)
     1687    {
     1688        BOOLEAN fPresent = FALSE;
     1689        NTSTATUS rcNt = ApiSetQueryApiSetPresence(pName, &fPresent);
     1690        SUP_DPRINTF(("supR3HardenedIsApiSetDll: ApiSetQueryApiSetPresence(%.*ls) -> %#x, fPresent=%d\n",
     1691                     pName->Length / sizeof(WCHAR), pName->Buffer, rcNt, fPresent));
     1692        return fPresent != 0;
     1693    }
     1694
     1695    /*
     1696     * Fallback needed for Windows 7.  Fortunately, there aren't too many fake DLLs here.
     1697     */
     1698    if (   supHardViUtf16PathStartsWithEx(pName->Buffer, pName->Length / sizeof(WCHAR),
     1699                                          L"api-ms-win-", 11, false /*fCheckSlash*/)
     1700        || supHardViUtf16PathStartsWithEx(pName->Buffer, pName->Length / sizeof(WCHAR),
     1701                                          L"ext-ms-win-", 11, false /*fCheckSlash*/) )
     1702    {
     1703#define MY_ENTRY(a) { a, sizeof(a) - 1 }
     1704        static const struct { const char *psz; size_t cch; } s_aKnownSets[] =
     1705        {
     1706            MY_ENTRY("api-ms-win-core-console-l1-1-0 "),
     1707            MY_ENTRY("api-ms-win-core-datetime-l1-1-0"),
     1708            MY_ENTRY("api-ms-win-core-debug-l1-1-0"),
     1709            MY_ENTRY("api-ms-win-core-delayload-l1-1-0"),
     1710            MY_ENTRY("api-ms-win-core-errorhandling-l1-1-0"),
     1711            MY_ENTRY("api-ms-win-core-fibers-l1-1-0"),
     1712            MY_ENTRY("api-ms-win-core-file-l1-1-0"),
     1713            MY_ENTRY("api-ms-win-core-handle-l1-1-0"),
     1714            MY_ENTRY("api-ms-win-core-heap-l1-1-0"),
     1715            MY_ENTRY("api-ms-win-core-interlocked-l1-1-0"),
     1716            MY_ENTRY("api-ms-win-core-io-l1-1-0"),
     1717            MY_ENTRY("api-ms-win-core-libraryloader-l1-1-0"),
     1718            MY_ENTRY("api-ms-win-core-localization-l1-1-0"),
     1719            MY_ENTRY("api-ms-win-core-localregistry-l1-1-0"),
     1720            MY_ENTRY("api-ms-win-core-memory-l1-1-0"),
     1721            MY_ENTRY("api-ms-win-core-misc-l1-1-0"),
     1722            MY_ENTRY("api-ms-win-core-namedpipe-l1-1-0"),
     1723            MY_ENTRY("api-ms-win-core-processenvironment-l1-1-0"),
     1724            MY_ENTRY("api-ms-win-core-processthreads-l1-1-0"),
     1725            MY_ENTRY("api-ms-win-core-profile-l1-1-0"),
     1726            MY_ENTRY("api-ms-win-core-rtlsupport-l1-1-0"),
     1727            MY_ENTRY("api-ms-win-core-string-l1-1-0"),
     1728            MY_ENTRY("api-ms-win-core-synch-l1-1-0"),
     1729            MY_ENTRY("api-ms-win-core-sysinfo-l1-1-0"),
     1730            MY_ENTRY("api-ms-win-core-threadpool-l1-1-0"),
     1731            MY_ENTRY("api-ms-win-core-ums-l1-1-0"),
     1732            MY_ENTRY("api-ms-win-core-util-l1-1-0"),
     1733            MY_ENTRY("api-ms-win-core-xstate-l1-1-0"),
     1734            MY_ENTRY("api-ms-win-security-base-l1-1-0"),
     1735            MY_ENTRY("api-ms-win-security-lsalookup-l1-1-0"),
     1736            MY_ENTRY("api-ms-win-security-sddl-l1-1-0"),
     1737            MY_ENTRY("api-ms-win-service-core-l1-1-0"),
     1738            MY_ENTRY("api-ms-win-service-management-l1-1-0"),
     1739            MY_ENTRY("api-ms-win-service-management-l2-1-0"),
     1740            MY_ENTRY("api-ms-win-service-winsvc-l1-1-0"),
     1741        };
     1742#undef MY_ENTRY
     1743
     1744        /* drop the dll suffix if present. */
     1745        PCRTUTF16 pawcName = pName->Buffer;
     1746        size_t    cwcName  = pName->Length / sizeof(WCHAR);
     1747        if (   cwcName > 5
     1748            && (pawcName[cwcName - 1] == 'l' || pawcName[cwcName - 1] == 'L')
     1749            && (pawcName[cwcName - 2] == 'l' || pawcName[cwcName - 2] == 'L')
     1750            && (pawcName[cwcName - 3] == 'd' || pawcName[cwcName - 3] == 'D')
     1751            &&  pawcName[cwcName - 4] == '.')
     1752            cwcName -= 4;
     1753
     1754        /* Search the table. */
     1755        for (size_t i = 0; i < RT_ELEMENTS(s_aKnownSets); i++)
     1756            if (   cwcName == s_aKnownSets[i].cch
     1757                && RTUtf16NICmpAscii(pawcName, s_aKnownSets[i].psz, cwcName) == 0)
     1758            {
     1759                SUP_DPRINTF(("supR3HardenedIsApiSetDll: '%.*ls' -> true\n", pName->Length / sizeof(WCHAR)));
     1760                return true;
     1761            }
     1762
     1763        SUP_DPRINTF(("supR3HardenedIsApiSetDll: Warning! '%.*ls' looks like an API set, but it's not in the list!\n",
     1764                     pName->Length / sizeof(WCHAR), pName->Buffer));
     1765    }
     1766
     1767    SUP_DPRINTF(("supR3HardenedIsApiSetDll: '%.*ls' -> false\n", pName->Length / sizeof(WCHAR)));
     1768    return false;
     1769}
     1770
     1771
     1772/**
     1773 * Checks whether the given unicode string contains a path separator and at
     1774 * least one dash.
     1775 *
     1776 * This is used to check for likely ApiSet name.  So far, all the pseudo DLL
     1777 * names include multiple dashes, so we use that as a criteria for recognizing
     1778 * them.  By happy coincident, most regular DLLs doesn't include dashes.
     1779 *
     1780 * @returns true if it contains path separator, false if only a name.
     1781 * @param   pPath               The path to check.
     1782 */
     1783static bool supR3HardenedHasDashButNoPath(PUNICODE_STRING pPath)
     1784{
     1785    size_t    cDashes = 0;
     1786    size_t    cwcLeft = pPath->Length / sizeof(WCHAR);
     1787    PCRTUTF16 pwc     = pPath->Buffer;
     1788    while (cwcLeft-- > 0)
     1789    {
     1790        RTUTF16 wc = *pwc++;
     1791        switch (wc)
     1792        {
     1793            default:
     1794                break;
     1795
     1796            case '-':
     1797                cDashes++;
     1798                break;
     1799
     1800            case '\\':
     1801            case '/':
     1802            case ':':
     1803                return false;
     1804        }
     1805    }
     1806    return cDashes > 0;
     1807}
     1808
     1809
     1810/**
    16741811 * Helper for supR3HardenedMonitor_LdrLoadDll.
    16751812 *
     
    17241861        return false;
    17251862    return RTUtf16ICmpAscii(pwszTmp, pszName) == 0;
    1726 }
    1727 
    1728 /**
    1729  * Checks whether the given unicode string contains a path separator.
    1730  *
    1731  * @returns true if it contains path separator, false if only a name.
    1732  * @param   pPath               The path to check.
    1733  */
    1734 static bool supR3HardenedContainsPathSep(PUNICODE_STRING pPath)
    1735 {
    1736     size_t    cwcLeft = pPath->Length / sizeof(WCHAR);
    1737     PCRTUTF16 pwc     = pPath->Buffer;
    1738     while (cwcLeft-- > 0)
    1739     {
    1740         RTUTF16 wc = *pwc++;
    1741         switch (wc)
    1742         {
    1743             default:
    1744                 break;
    1745             case '\\':
    1746             case '/':
    1747             case ':':
    1748                 return true;
    1749         }
    1750     }
    1751     return false;
    17521863}
    17531864
     
    19552066     * or something we're known to use but should be taken from WinSxS.
    19562067     */
    1957     else if (   (   supHardViUtf16PathStartsWithEx(pName->Buffer, pName->Length / sizeof(WCHAR),
    1958                                                   L"api-ms-win-", 11, false /*fCheckSlash*/)
    1959                  || supHardViUtf16PathStartsWithEx(pName->Buffer, pName->Length / sizeof(WCHAR),
    1960                                                   L"ext-ms-win-", 11, false /*fCheckSlash*/) )
    1961              && !supR3HardenedContainsPathSep(pName))
     2068    else if (   supR3HardenedHasDashButNoPath(pName)
     2069             && supR3HardenedIsApiSetDll(pName))
    19622070    {
    19632071        memcpy(wszPath, pName->Buffer, pName->Length);
  • trunk/src/VBox/HostDrivers/Support/win/import-template-ntdll.h

    r54998 r67979  
    6363SUPHARNT_IMPORT_STDCALL_EARLY_OPTIONAL(LdrRegisterDllNotification, 16)
    6464SUPHARNT_IMPORT_STDCALL_EARLY(LdrGetDllHandle, 16)
     65SUPHARNT_IMPORT_STDCALL_EARLY_OPTIONAL(ApiSetQueryApiSetPresence, 8)
    6566
    6667SUPHARNT_IMPORT_STDCALL(RtlAddAccessAllowedAce, 16)
  • trunk/src/VBox/Runtime/Makefile.kmk

    r67677 r67979  
    20962096        common/string/RTStrNLenEx.cpp \
    20972097        common/string/RTUtf16ICmpAscii.cpp \
     2098        common/string/RTUtf16NICmpAscii.cpp \
    20982099        common/string/straprintf.cpp \
    20992100        common/string/strformat.cpp \
  • trunk/src/VBox/Runtime/common/string/RTUtf16NICmpAscii.cpp

    r67978 r67979  
    3636
    3737
    38 RTDECL(int) RTUtf16ICmpAscii(PCRTUTF16 pwsz1, const char *psz2)
     38RTDECL(int) RTUtf16NICmpAscii(PCRTUTF16 pwsz1, const char *psz2, size_t cwcMax)
    3939{
    4040    for (;;)
    4141    {
     42        if (cwcMax == 0)
     43            return 0;
     44
    4245        RTUTF16         wc1  = *pwsz1++;
    4346        unsigned char   uch2 = *psz2++; Assert(uch2 < 0x80);
     
    4952                return wc1 < uch2 ? -1 : 1;
    5053        }
     54
    5155        if (!uch2)
    5256            return 0;
     57        cwcMax--;
    5358    }
    5459}
    55 RT_EXPORT_SYMBOL(RTUtf16ICmpAscii);
     60RT_EXPORT_SYMBOL(RTUtf16NICmpAscii);
    5661
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