VirtualBox

Changeset 52356 in vbox for trunk/src/VBox/HostDrivers


Ignore:
Timestamp:
Aug 11, 2014 7:24:00 PM (10 years ago)
Author:
vboxsync
Message:

SUP: Manual imports.

Location:
trunk/src/VBox/HostDrivers/Support
Files:
3 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/Makefile.kmk

    r52337 r52356  
    198198        win/SUPR3HardenedMain-win.cpp \
    199199        win/SUPR3HardenedMainA-win.asm \
     200        win/SUPR3HardenedMainImports-win.cpp \
    200201       win/SUPHardenedVerifyProcess-win.cpp \
    201202       win/SUPHardenedVerifyImage-win.cpp \
     
    381382        $(KBUILD_TARGET)/VBoxSupLib-$(KBUILD_TARGET).cpp
    382383VBoxSupLib_LIBS.win = \
     384        kernel32.lib \
    383385        $(SUPR3HardenedStatic_1_TARGET)
    384386
  • trunk/src/VBox/HostDrivers/Support/SUPLibInternal.h

    r52169 r52356  
    436436DECLHIDDEN(void)    supR3HardenedWinInit(uint32_t fFlags);
    437437DECLHIDDEN(void)    supR3HardenedWinInitVersion(void);
     438DECLHIDDEN(void)    supR3HardenedWinInitImports(void);
    438439DECLHIDDEN(void)    supR3HardenedWinVerifyProcess(void);
    439 DECLHIDDEN(void)    supR3HardenedWinResolveVerifyTrustApiAndHookThreadCreation(void);
     440DECLHIDDEN(void)    supR3HardenedWinResolveVerifyTrustApiAndHookThreadCreation(const char *pszProgName);
    440441DECLHIDDEN(bool)    supR3HardenedWinIsReSpawnNeeded(int iWhich, int cArgs, char **papszArgs);
    441442DECLHIDDEN(int)     supR3HardenedWinReSpawn(int iWhich);
  • trunk/src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp

    r52204 r52356  
    10311031static void suplibHardenedPrintPrefix(void)
    10321032{
    1033     if (!g_pszSupLibHardenedProgName)
     1033    if (g_pszSupLibHardenedProgName)
    10341034        suplibHardenedPrintStr(g_pszSupLibHardenedProgName);
    10351035    suplibHardenedPrintStr(": ");
     
    17381738     * Windows: Enable the use of windows APIs to verify images at load time.
    17391739     */
    1740     supR3HardenedWinResolveVerifyTrustApiAndHookThreadCreation();
     1740    supR3HardenedWinResolveVerifyTrustApiAndHookThreadCreation(g_pszSupLibHardenedProgName);
    17411741    g_enmSupR3HardenedMainState = SUPR3HARDENEDMAINSTATE_VERIFY_TRUST_READY;
    17421742#endif
  • trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerify-win.h

    r52204 r52356  
    4141#ifndef SUP_CERTIFICATES_ONLY
    4242# ifdef RT_OS_WINDOWS
    43 DECLHIDDEN(int)      supHardenedWinInitImageVerifier(PRTERRINFO pErrInfo);
    44 DECLHIDDEN(void)     supHardenedWinTermImageVerifier(void);
     43DECLHIDDEN(int)     supHardenedWinInitImageVerifier(PRTERRINFO pErrInfo);
     44DECLHIDDEN(void)    supHardenedWinTermImageVerifier(void);
    4545
    4646typedef enum SUPHARDNTVPKIND
     
    5151    SUPHARDNTVPKIND_32BIT_HACK = 0x7fffffff
    5252} SUPHARDNTVPKIND;
    53 DECLHIDDEN(int)      supHardenedWinVerifyProcess(HANDLE hProcess, HANDLE hThread, SUPHARDNTVPKIND enmKind, PRTERRINFO pErrInfo);
     53DECLHIDDEN(int)     supHardenedWinVerifyProcess(HANDLE hProcess, HANDLE hThread, SUPHARDNTVPKIND enmKind, PRTERRINFO pErrInfo);
    5454
    55 DECLHIDDEN(bool)     supHardViIsAppPatchDir(PCRTUTF16 pwszPath, uint32_t cwcName);
     55DECLHIDDEN(bool)    supHardViUniStrPathStartsWithUniStr(UNICODE_STRING const *pUniStrLeft,
     56                                                        UNICODE_STRING const *pUniStrRight, bool fCheckSlash);
     57DECLHIDDEN(bool)    supHardViUtf16PathStartsWithEx(PCRTUTF16 pwszLeft, uint32_t cwcLeft,
     58                                                PCRTUTF16 pwszRight, uint32_t cwcRight, bool fCheckSlash);
     59DECLHIDDEN(bool)    supHardViIsAppPatchDir(PCRTUTF16 pwszPath, uint32_t cwcName);
    5660
    5761/**
     
    121125extern uint32_t         g_offSupLibHardenedExeNtName;
    122126
     127#   ifdef IN_RING0
    123128/** Pointer to NtQueryVirtualMemory. */
    124129typedef NTSTATUS (NTAPI *PFNNTQUERYVIRTUALMEMORY)(HANDLE, void const *, MEMORY_INFORMATION_CLASS, PVOID, SIZE_T, PSIZE_T);
    125130extern PFNNTQUERYVIRTUALMEMORY g_pfnNtQueryVirtualMemory;
     131#   endif
    126132
    127133#  endif /* SUPHNTVI_NO_NT_STUFF */
  • trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyImage-win.cpp

    r52213 r52356  
    440440 * @param   pszPrefix           The ascii prefix string.
    441441 */
    442 static bool supHardViUtf16PathStartsWith(PCRTUTF16 pwszLeft, const char *pszRight)
     442static bool supHardViUtf16PathStartsWithAscii(PCRTUTF16 pwszLeft, const char *pszRight)
    443443{
    444444    for (;;)
     
    472472
    473473/**
     474 * Simple case insensitive UNICODE_STRING starts-with path predicate.
     475 *
     476 * @returns true if starts with given string, false if not.
     477 * @param   pwszLeft            The path to check.
     478 * @param   cwcLeft             The length of @a pwszLeft
     479 * @param   pwszRight           The starts-with path.
     480 * @param   cwcRight            The length of @a pwszRight.
     481 * @param   fCheckSlash         Check for a slash following the prefix.
     482 */
     483DECLHIDDEN(bool) supHardViUtf16PathStartsWithEx(PCRTUTF16 pwszLeft, uint32_t cwcLeft,
     484                                                PCRTUTF16 pwszRight, uint32_t cwcRight, bool fCheckSlash)
     485{
     486    if (cwcLeft < cwcRight)
     487        return false;
     488
     489    /* See if we can get away with a case sensitive compare first. */
     490    if (memcmp(pwszLeft, pwszRight, cwcRight) == 0)
     491        pwszLeft += cwcRight;
     492    else
     493    {
     494        /* No luck, do a slow case insensitive comapre.  */
     495        uint32_t cLeft = cwcRight;
     496        while (cLeft-- > 0)
     497        {
     498            RTUTF16 wcLeft  = *pwszLeft++;
     499            RTUTF16 wcRight = *pwszRight++;
     500            if (wcLeft != wcRight)
     501            {
     502                wcLeft  = wcLeft < 0x80  ? wcLeft  == '/' ? '\\' : RT_C_TO_LOWER(wcLeft)  : wcLeft;
     503                wcRight = wcRight < 0x80 ? wcRight == '/' ? '\\' : RT_C_TO_LOWER(wcRight) : wcRight;
     504                if (wcLeft != wcRight)
     505                    return false;
     506            }
     507        }
     508    }
     509
     510    /* Check for slash following the prefix, if request. */
     511    if (   !fCheckSlash
     512        || *pwszLeft == '\\'
     513        || *pwszLeft == '/')
     514        return true;
     515    return false;
     516}
     517
     518
     519/**
     520 * Simple case insensitive UNICODE_STRING starts-with path predicate.
     521 *
     522 * @returns true if starts with given string, false if not.
     523 * @param   pUniStrLeft         The path to check.
     524 * @param   pUniStrRight        The starts-with path.
     525 * @param   fCheckSlash         Check for a slash following the prefix.
     526 */
     527DECLHIDDEN(bool) supHardViUniStrPathStartsWithUniStr(UNICODE_STRING const *pUniStrLeft, UNICODE_STRING const *pUniStrRight,
     528                                                     bool fCheckSlash)
     529{
     530    return supHardViUtf16PathStartsWithEx(pUniStrLeft->Buffer, pUniStrLeft->Length / sizeof(WCHAR),
     531                                          pUniStrRight->Buffer, pUniStrRight->Length / sizeof(WCHAR), fCheckSlash);
     532}
     533
     534
     535
     536/**
    474537 * Counts slashes in the given UTF-8 path string.
    475538 *
     
    505568        return false;
    506569
    507     if (!supHardViUtf16PathStartsWith(&pwszPath[cwcWinDir], "\\AppPatch\\"))
     570    if (!supHardViUtf16PathStartsWithAscii(&pwszPath[cwcWinDir], "\\AppPatch\\"))
    508571        return false;
    509572
     
    559622    uint32_t cwcName = (uint32_t)RTUtf16Len(pwszName);
    560623    uint32_t cwcOther = g_System32NtPath.UniStr.Length / sizeof(WCHAR);
    561     if (   cwcName > cwcOther
    562         && RTPATH_IS_SLASH(pwszName[cwcOther])
    563         && memcmp(pwszName, g_System32NtPath.UniStr.Buffer, g_System32NtPath.UniStr.Length) == 0)
     624    if (supHardViUtf16PathStartsWithEx(pwszName, cwcName, g_System32NtPath.UniStr.Buffer, cwcOther, true /*fCheckSlash*/))
    564625    {
    565626        pwsz = pwszName + cwcOther + 1;
     
    596657        {
    597658            if (   cSlashes == 1
    598                 && supHardViUtf16PathStartsWith(pwsz, "drivers\\ati")
     659                && supHardViUtf16PathStartsWithAscii(pwsz, "drivers\\ati")
    599660                && (   supHardViUtf16PathEndsWith(pwsz, ".sys")
    600661                    || supHardViUtf16PathEndsWith(pwsz, ".dll") ) )
     
    626687     */
    627688    cwcOther = g_WinSxSNtPath.UniStr.Length / sizeof(WCHAR);
    628     if (   cwcName > cwcOther
    629         && RTPATH_IS_SLASH(pwszName[cwcOther])
    630         && memcmp(pwszName, g_WinSxSNtPath.UniStr.Buffer, g_WinSxSNtPath.UniStr.Length) == 0)
     689    if (supHardViUtf16PathStartsWithEx(pwszName, cwcName, g_WinSxSNtPath.UniStr.Buffer, cwcOther, true /*fCheckSlash*/))
    631690    {
    632691        pwsz = pwszName + cwcOther + 1;
     
    641700        /* The common controls mess. */
    642701# ifdef RT_ARCH_AMD64
    643         if (supHardViUtf16PathStartsWith(pwsz, "amd64_microsoft.windows.common-controls_"))
     702        if (supHardViUtf16PathStartsWithAscii(pwsz, "amd64_microsoft.windows.common-controls_"))
    644703# elif defined(RT_ARCH_X86)
    645         if (supHardViUtf16PathStartsWith(pwsz, "x86_microsoft.windows.common-controls_"))
     704        if (supHardViUtf16PathStartsWithAscii(pwsz, "x86_microsoft.windows.common-controls_"))
    646705# else
    647706#  error "Unsupported architecture"
     
    655714        /* Allow anything slightly microsoftish from WinSxS. W2K3 wanted winhttp.dll early on... */
    656715# ifdef RT_ARCH_AMD64
    657         if (supHardViUtf16PathStartsWith(pwsz, "amd64_microsoft."))
     716        if (supHardViUtf16PathStartsWithAscii(pwsz, "amd64_microsoft."))
    658717# elif defined(RT_ARCH_X86)
    659         if (supHardViUtf16PathStartsWith(pwsz, "x86_microsoft."))
     718        if (supHardViUtf16PathStartsWithAscii(pwsz, "x86_microsoft."))
    660719# else
    661720#  error "Unsupported architecture"
     
    9411000#ifdef IN_RING3
    9421001     /*
    943       * Call the windows verify trust API if we've resolved it.
     1002      * Call the windows verify trust API if we've resolved it and aren't in
     1003      * some obvious recursion.  Assumes the loader semaphore will reduce the
     1004      * risk of concurrency here, so no TLS, only a single static variable.
    9441005      */
    945      if (   g_pfnWinVerifyTrust
    946          && supR3HardNtViCanCallWinVerifyTrust(pNtViRdr->hFile, pwszName))
    947      {
    948          if (pfCacheable)
    949              *pfCacheable = g_pfnWinVerifyTrust != NULL;
    950          if (rc != VERR_LDRVI_NOT_SIGNED)
    951          {
    952              if (rc == VINF_LDRVI_NOT_SIGNED)
    953              {
    954                  if (pNtViRdr->fFlags & SUPHNTVI_F_ALLOW_CAT_FILE_VERIFICATION)
    955                  {
    956                      int rc2 = supR3HardNtViCallWinVerifyTrustCatFile(pNtViRdr->hFile, pwszName, pNtViRdr->fFlags, pErrInfo,
    957                                                                       g_pfnWinVerifyTrust);
    958                      SUP_DPRINTF(("supR3HardNtViCallWinVerifyTrustCatFile -> %d (org %d)\n", rc2, rc));
    959                      rc = rc2;
    960                  }
    961                  else
    962                  {
    963                      AssertFailed();
    964                      rc = VERR_LDRVI_NOT_SIGNED;
    965                  }
    966              }
    967              else if (RT_SUCCESS(rc))
    968                  rc = supR3HardNtViCallWinVerifyTrust(pNtViRdr->hFile, pwszName, pNtViRdr->fFlags, pErrInfo,
    969                                                       g_pfnWinVerifyTrust);
    970              else
    971              {
    972                  int rc2 = supR3HardNtViCallWinVerifyTrust(pNtViRdr->hFile, pwszName, pNtViRdr->fFlags, pErrInfo,
    973                                                            g_pfnWinVerifyTrust);
    974                  AssertMsg(RT_FAILURE_NP(rc2),
    975                            ("rc=%Rrc, rc2=%Rrc %s", rc, rc2, pErrInfo ? pErrInfo->pszMsg : "<no-err-info>"));
    976              }
    977          }
    978      }
     1006    if (g_pfnWinVerifyTrust)
     1007    {
     1008        static uint32_t volatile s_idActiveThread = UINT32_MAX;
     1009        uint32_t const idCurrentThread = GetCurrentThreadId();
     1010        if (   s_idActiveThread != idCurrentThread
     1011            && supR3HardNtViCanCallWinVerifyTrust(pNtViRdr->hFile, pwszName) )
     1012        {
     1013            ASMAtomicCmpXchgU32(&s_idActiveThread, idCurrentThread, UINT32_MAX);
     1014
     1015            if (pfCacheable)
     1016                *pfCacheable = g_pfnWinVerifyTrust != NULL;
     1017            if (rc != VERR_LDRVI_NOT_SIGNED)
     1018            {
     1019                if (rc == VINF_LDRVI_NOT_SIGNED)
     1020                {
     1021                    if (pNtViRdr->fFlags & SUPHNTVI_F_ALLOW_CAT_FILE_VERIFICATION)
     1022                    {
     1023                        int rc2 = supR3HardNtViCallWinVerifyTrustCatFile(pNtViRdr->hFile, pwszName, pNtViRdr->fFlags, pErrInfo,
     1024                                                                         g_pfnWinVerifyTrust);
     1025                        SUP_DPRINTF(("supR3HardNtViCallWinVerifyTrustCatFile -> %d (org %d)\n", rc2, rc));
     1026                        rc = rc2;
     1027                    }
     1028                    else
     1029                    {
     1030                        AssertFailed();
     1031                        rc = VERR_LDRVI_NOT_SIGNED;
     1032                    }
     1033                }
     1034                else if (RT_SUCCESS(rc))
     1035                    rc = supR3HardNtViCallWinVerifyTrust(pNtViRdr->hFile, pwszName, pNtViRdr->fFlags, pErrInfo,
     1036                                                         g_pfnWinVerifyTrust);
     1037                else
     1038                {
     1039                    int rc2 = supR3HardNtViCallWinVerifyTrust(pNtViRdr->hFile, pwszName, pNtViRdr->fFlags, pErrInfo,
     1040                                                              g_pfnWinVerifyTrust);
     1041                    AssertMsg(RT_FAILURE_NP(rc2),
     1042                              ("rc=%Rrc, rc2=%Rrc %s", rc, rc2, pErrInfo ? pErrInfo->pszMsg : "<no-err-info>"));
     1043                }
     1044            }
     1045
     1046            ASMAtomicCmpXchgU32(&s_idActiveThread, UINT32_MAX, idCurrentThread);
     1047        }
     1048        else
     1049            SUP_DPRINTF(("Detected WinVerifyTrust recursion: rc=%Rrc '%ls'.\n", rc, pwszName));
     1050    }
    9791051#else  /* !IN_RING3 */
    980      if (pfCacheable)
    981          *pfCacheable = true;
     1052    if (pfCacheable)
     1053        *pfCacheable = true;
    9821054#endif /* !IN_RING3 */
    9831055
    984      return rc;
     1056    return rc;
    9851057}
    9861058
     
    15021574 * and we require all VBox extensions to have it set as well.  In effect, the
    15031575 * authenticode signature will be checked two or three times.
    1504  */
    1505 DECLHIDDEN(void) supR3HardenedWinResolveVerifyTrustApiAndHookThreadCreation(void)
     1576 *
     1577 * @param   pszProgName     The program name.
     1578 */
     1579DECLHIDDEN(void) supR3HardenedWinResolveVerifyTrustApiAndHookThreadCreation(const char *pszProgName)
    15061580{
    15071581# ifdef IN_SUP_HARDENED_R3
     
    15721646                                             &ErrInfoStatic.Core, pfnWinVerifyTrust);
    15731647    if (RT_FAILURE(rc))
    1574         supR3HardenedFatal("WinVerifyTrust failed on stub executable: %s", ErrInfoStatic.szMsg);
     1648        supR3HardenedFatalMsg(pszProgName, kSupInitOp_Integrity, rc,
     1649                              "WinVerifyTrust failed on stub executable: %s", ErrInfoStatic.szMsg);
    15751650# endif
    15761651
     
    15801655
    15811656    g_pfnWinVerifyTrust = pfnWinVerifyTrust;
     1657    SUP_DPRINTF(("g_pfnWinVerifyTrust=%p\n", pfnWinVerifyTrust));
    15821658
    15831659    /*
     
    16871763            case TRUST_E_EXPLICIT_DISTRUST:        pszErrConst = "TRUST_E_EXPLICIT_DISTRUST";     break;
    16881764            case CERT_E_CHAINING:                  pszErrConst = "CERT_E_CHAINING";               break;
     1765            case CERT_E_REVOCATION_FAILURE:        pszErrConst = "CERT_E_REVOCATION_FAILURE";     break;
    16891766        }
    16901767        if (pszErrConst)
  • trunk/src/VBox/HostDrivers/Support/win/SUPLib-win.cpp

    r52000 r52356  
    9595        if (RT_FAILURE(rc))
    9696            return rc;
    97         supR3HardenedWinResolveVerifyTrustApiAndHookThreadCreation();
     97        supR3HardenedWinResolveVerifyTrustApiAndHookThreadCreation(NULL);
    9898#endif
    9999        g_fHardenedVerifyInited = true;
  • trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp

    r52204 r52356  
    6363 * This just needs to be unique enough to avoid most confusion with real
    6464 * executable names,  there are other checks in place to make sure we've respanwed. */
    65 #define SUPR3_RESPAWN_1_ARG0  "0384ad8f-4f0c-d002-e3ae-5597cd55af98-suplib-2ndchild"
     65#define SUPR3_RESPAWN_1_ARG0  "5cb9562b-4b8c-d13f-6bc4-3da9b0f37da6-suplib-2ndchild"
    6666
    6767/** The first argument of a respawed stub when respawned for the second time.
    6868 * This just needs to be unique enough to avoid most confusion with real
    6969 * executable names,  there are other checks in place to make sure we've respanwed. */
    70 #define SUPR3_RESPAWN_2_ARG0  "0384ad8f-4f0c-d002-e3ae-5597cd55af98-suplib-3rdchild"
     70#define SUPR3_RESPAWN_2_ARG0  "5cb9562b-4b8c-d13f-6bc4-3da9b0f37da6-suplib-3rdchild"
    7171
    7272/** Unconditional assertion. */
     
    616616    }
    617617}
    618 
    619618
    620619
     
    771770            Assert(g_SupLibHardenedExeNtPath.UniStr.Buffer[g_offSupLibHardenedExeNtName - 1] == '\\');
    772771            uint32_t fFlags = 0;
    773             if (   uBuf.UniStr.Length > g_System32NtPath.UniStr.Length
    774                 && memcmp(uBuf.UniStr.Buffer, g_System32NtPath.UniStr.Buffer, g_System32NtPath.UniStr.Length) == 0
    775                 && uBuf.UniStr.Buffer[g_System32NtPath.UniStr.Length / sizeof(WCHAR)] == '\\')
     772            if (supHardViUniStrPathStartsWithUniStr(&uBuf.UniStr, &g_System32NtPath.UniStr, true /*fCheckSlash*/))
    776773            {
    777774                fSystem32 = true;
    778775                fFlags |= SUPHNTVI_F_ALLOW_CAT_FILE_VERIFICATION;
    779776            }
    780             else if (   uBuf.UniStr.Length > g_WinSxSNtPath.UniStr.Length
    781                      && memcmp(uBuf.UniStr.Buffer, g_WinSxSNtPath.UniStr.Buffer, g_WinSxSNtPath.UniStr.Length) == 0
    782                      && uBuf.UniStr.Buffer[g_WinSxSNtPath.UniStr.Length / sizeof(WCHAR)] == '\\')
     777            else if (supHardViUniStrPathStartsWithUniStr(&uBuf.UniStr, &g_WinSxSNtPath.UniStr, true /*fCheckSlash*/))
    783778                fFlags |= SUPHNTVI_F_ALLOW_CAT_FILE_VERIFICATION;
    784             else if (   uBuf.UniStr.Length > g_offSupLibHardenedExeNtName
    785                      && memcmp(uBuf.UniStr.Buffer, g_SupLibHardenedExeNtPath.UniStr.Buffer,
    786                                g_offSupLibHardenedExeNtName * sizeof(WCHAR)) == 0)
     779            else if (supHardViUtf16PathStartsWithEx(uBuf.UniStr.Buffer, uBuf.UniStr.Length / sizeof(WCHAR),
     780                                                   g_SupLibHardenedExeNtPath.UniStr.Buffer,
     781                                                    g_offSupLibHardenedExeNtName, false /*fCheckSlash*/))
    787782                fFlags |= SUPHNTVI_F_REQUIRE_KERNEL_CODE_SIGNING | SUPHNTVI_F_REQUIRE_SIGNATURE_ENFORCEMENT;
    788783#ifdef VBOX_PERMIT_MORE
     
    804799            {
    805800                supR3HardenedError(VINF_SUCCESS, false,
    806                                    "supR3HardenedMonitor_NtCreateSection: Not a trusted location: '%ls' (fImage=%d fExecMap=%d fExecProt=%d)\n",
     801                                   "supR3HardenedMonitor_NtCreateSection: Not a trusted location: '%ls' (fImage=%d fExecMap=%d fExecProt=%d)",
    807802                                    uBuf.UniStr.Buffer, fImage, fExecMap, fExecProt);
    808803                if (hMyFile != hFile)
     
    18671862        rc = supR3HardNtPuChSanitizePeb(&This);
    18681863    if (RT_SUCCESS(rc))
     1864    {
    18691865        rc = supHardenedWinVerifyProcess(hProcess, hThread, SUPHARDNTVPKIND_CHILD_PURIFICATION, pErrInfo);
     1866        if (RT_FAILURE(rc))
     1867            Sleep(300000);
     1868    }
    18701869
    18711870    return rc;
     
    25322531
    25332532    /*
     2533     * Initialize the NTDLL API wrappers. This aims at bypassing patched NTDLL
     2534     * in all the processes leading up the VM process.
     2535     */
     2536    supR3HardenedWinInitImports();
     2537
     2538    /*
    25342539     * Init g_uNtVerCombined. (The code is shared with SUPR3.lib and lives in
    25352540     * SUPHardenedVerfiyImage-win.cpp.)
     
    25502555     * Get the executable name.
    25512556     */
    2552     DWORD cwcExecName = GetModuleFileNameW(GetModuleHandle(NULL), g_wszSupLibHardenedExePath,
     2557    DWORD cwcExecName = GetModuleFileNameW(GetModuleHandleW(NULL), g_wszSupLibHardenedExePath,
    25532558                                           RT_ELEMENTS(g_wszSupLibHardenedExePath));
    25542559    if (cwcExecName >= RT_ELEMENTS(g_wszSupLibHardenedExePath))
  • trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMainA-win.asm

    r51770 r52356  
    7575%endif
    7676
     77;;
     78; Composes a standard call name.
     79%ifdef RT_ARCH_X86
     80 %define SUPHNTIMP_STDCALL_NAME(a,b) _ %+ a %+ @ %+ b
     81%else
     82 %define SUPHNTIMP_STDCALL_NAME(a,b) NAME(a)
     83%endif
     84
     85
     86;;
     87; Import data and code for an API call.
     88;
     89; @param 1  The plain API name.
     90; @param 2  The parameter frame size on x86. Multiple of dword.
     91; @param 3  Non-zero expression if system call.
     92;
     93%define SUPHNTIMP_SYSCALL 1
     94%macro SupHardNtImport 3
     95        ;
     96        ; The data.
     97        ;
     98BEGINDATA
     99global __imp_ %+ %1                     ; The import name used via dllimport.
     100__imp_ %+ %1:
     101GLOBALNAME g_pfn %+ %1                  ; The name we like to refer to.
     102        RTCCPTR_DEF 0
     103%if %3
     104GLOBALNAME g_uApiNo %+ %1                  ; The name we like to refer to.
     105        RTCCPTR_DEF 0
     106%endif
     107
     108        ;
     109        ; The code: First a call stub.
     110        ;
     111BEGINCODE
     112global SUPHNTIMP_STDCALL_NAME(%1, %2)
     113SUPHNTIMP_STDCALL_NAME(%1, %2):
     114        jmp     RTCCPTR_PRE [NAME(g_pfn %+ %1) xWrtRIP]
     115
     116%if %3
     117        ;
     118        ; Make system calls.
     119        ;
     120 %ifdef RT_ARCH_AMD64
     121BEGINPROC %1 %+ _SyscallType1
     122        mov     eax, [NAME(g_uApiNo %+ %1) xWrtRIP]
     123        mov     r10, rcx
     124        syscall
     125        ret
     126ENDPROC %1 %+ _SyscallType1
     127 %else
     128BEGINPROC %1 %+ _SyscallType1
     129        mov     edx, 07ffe0300h         ; SharedUserData!SystemCallStub
     130        mov     eax, [NAME(g_uApiNo %+ %1) xWrtRIP]
     131        call    edx
     132        ret     %2
     133ENDPROC %1 %+ _SyscallType1
     134BEGINPROC %1 %+ _SyscallType2
     135        push    .return
     136        mov     edx, esp
     137        mov     eax, [NAME(g_uApiNo %+ %1) xWrtRIP]
     138        sysenter
     139        add     esp, 4
     140.return:
     141        ret     %2
     142ENDPROC %1 %+ _SyscallType2
     143  %endif
     144%endif
     145%endmacro
     146
     147%define SUPHARNT_COMMENT(a_Comment)
     148%define SUPHARNT_IMPORT_SYSCALL(a_Name, a_cbParamsX86) SupHardNtImport a_Name, a_cbParamsX86, SUPHNTIMP_SYSCALL
     149%define SUPHARNT_IMPORT_STDCALL(a_Name, a_cbParamsX86) SupHardNtImport a_Name, a_cbParamsX86, 0
     150%include "import-template-ntdll.h"
     151%include "import-template-kernel32.h"
     152
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