Changeset 52356 in vbox for trunk/src/VBox/HostDrivers
- Timestamp:
- Aug 11, 2014 7:24:00 PM (10 years ago)
- Location:
- trunk/src/VBox/HostDrivers/Support
- Files:
-
- 3 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/Makefile.kmk
r52337 r52356 198 198 win/SUPR3HardenedMain-win.cpp \ 199 199 win/SUPR3HardenedMainA-win.asm \ 200 win/SUPR3HardenedMainImports-win.cpp \ 200 201 win/SUPHardenedVerifyProcess-win.cpp \ 201 202 win/SUPHardenedVerifyImage-win.cpp \ … … 381 382 $(KBUILD_TARGET)/VBoxSupLib-$(KBUILD_TARGET).cpp 382 383 VBoxSupLib_LIBS.win = \ 384 kernel32.lib \ 383 385 $(SUPR3HardenedStatic_1_TARGET) 384 386 -
trunk/src/VBox/HostDrivers/Support/SUPLibInternal.h
r52169 r52356 436 436 DECLHIDDEN(void) supR3HardenedWinInit(uint32_t fFlags); 437 437 DECLHIDDEN(void) supR3HardenedWinInitVersion(void); 438 DECLHIDDEN(void) supR3HardenedWinInitImports(void); 438 439 DECLHIDDEN(void) supR3HardenedWinVerifyProcess(void); 439 DECLHIDDEN(void) supR3HardenedWinResolveVerifyTrustApiAndHookThreadCreation( void);440 DECLHIDDEN(void) supR3HardenedWinResolveVerifyTrustApiAndHookThreadCreation(const char *pszProgName); 440 441 DECLHIDDEN(bool) supR3HardenedWinIsReSpawnNeeded(int iWhich, int cArgs, char **papszArgs); 441 442 DECLHIDDEN(int) supR3HardenedWinReSpawn(int iWhich); -
trunk/src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp
r52204 r52356 1031 1031 static void suplibHardenedPrintPrefix(void) 1032 1032 { 1033 if ( !g_pszSupLibHardenedProgName)1033 if (g_pszSupLibHardenedProgName) 1034 1034 suplibHardenedPrintStr(g_pszSupLibHardenedProgName); 1035 1035 suplibHardenedPrintStr(": "); … … 1738 1738 * Windows: Enable the use of windows APIs to verify images at load time. 1739 1739 */ 1740 supR3HardenedWinResolveVerifyTrustApiAndHookThreadCreation( );1740 supR3HardenedWinResolveVerifyTrustApiAndHookThreadCreation(g_pszSupLibHardenedProgName); 1741 1741 g_enmSupR3HardenedMainState = SUPR3HARDENEDMAINSTATE_VERIFY_TRUST_READY; 1742 1742 #endif -
trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerify-win.h
r52204 r52356 41 41 #ifndef SUP_CERTIFICATES_ONLY 42 42 # ifdef RT_OS_WINDOWS 43 DECLHIDDEN(int) 44 DECLHIDDEN(void) 43 DECLHIDDEN(int) supHardenedWinInitImageVerifier(PRTERRINFO pErrInfo); 44 DECLHIDDEN(void) supHardenedWinTermImageVerifier(void); 45 45 46 46 typedef enum SUPHARDNTVPKIND … … 51 51 SUPHARDNTVPKIND_32BIT_HACK = 0x7fffffff 52 52 } SUPHARDNTVPKIND; 53 DECLHIDDEN(int) 53 DECLHIDDEN(int) supHardenedWinVerifyProcess(HANDLE hProcess, HANDLE hThread, SUPHARDNTVPKIND enmKind, PRTERRINFO pErrInfo); 54 54 55 DECLHIDDEN(bool) supHardViIsAppPatchDir(PCRTUTF16 pwszPath, uint32_t cwcName); 55 DECLHIDDEN(bool) supHardViUniStrPathStartsWithUniStr(UNICODE_STRING const *pUniStrLeft, 56 UNICODE_STRING const *pUniStrRight, bool fCheckSlash); 57 DECLHIDDEN(bool) supHardViUtf16PathStartsWithEx(PCRTUTF16 pwszLeft, uint32_t cwcLeft, 58 PCRTUTF16 pwszRight, uint32_t cwcRight, bool fCheckSlash); 59 DECLHIDDEN(bool) supHardViIsAppPatchDir(PCRTUTF16 pwszPath, uint32_t cwcName); 56 60 57 61 /** … … 121 125 extern uint32_t g_offSupLibHardenedExeNtName; 122 126 127 # ifdef IN_RING0 123 128 /** Pointer to NtQueryVirtualMemory. */ 124 129 typedef NTSTATUS (NTAPI *PFNNTQUERYVIRTUALMEMORY)(HANDLE, void const *, MEMORY_INFORMATION_CLASS, PVOID, SIZE_T, PSIZE_T); 125 130 extern PFNNTQUERYVIRTUALMEMORY g_pfnNtQueryVirtualMemory; 131 # endif 126 132 127 133 # endif /* SUPHNTVI_NO_NT_STUFF */ -
trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyImage-win.cpp
r52213 r52356 440 440 * @param pszPrefix The ascii prefix string. 441 441 */ 442 static bool supHardViUtf16PathStartsWith (PCRTUTF16 pwszLeft, const char *pszRight)442 static bool supHardViUtf16PathStartsWithAscii(PCRTUTF16 pwszLeft, const char *pszRight) 443 443 { 444 444 for (;;) … … 472 472 473 473 /** 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 */ 483 DECLHIDDEN(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 */ 527 DECLHIDDEN(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 /** 474 537 * Counts slashes in the given UTF-8 path string. 475 538 * … … 505 568 return false; 506 569 507 if (!supHardViUtf16PathStartsWith (&pwszPath[cwcWinDir], "\\AppPatch\\"))570 if (!supHardViUtf16PathStartsWithAscii(&pwszPath[cwcWinDir], "\\AppPatch\\")) 508 571 return false; 509 572 … … 559 622 uint32_t cwcName = (uint32_t)RTUtf16Len(pwszName); 560 623 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*/)) 564 625 { 565 626 pwsz = pwszName + cwcOther + 1; … … 596 657 { 597 658 if ( cSlashes == 1 598 && supHardViUtf16PathStartsWith (pwsz, "drivers\\ati")659 && supHardViUtf16PathStartsWithAscii(pwsz, "drivers\\ati") 599 660 && ( supHardViUtf16PathEndsWith(pwsz, ".sys") 600 661 || supHardViUtf16PathEndsWith(pwsz, ".dll") ) ) … … 626 687 */ 627 688 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*/)) 631 690 { 632 691 pwsz = pwszName + cwcOther + 1; … … 641 700 /* The common controls mess. */ 642 701 # ifdef RT_ARCH_AMD64 643 if (supHardViUtf16PathStartsWith (pwsz, "amd64_microsoft.windows.common-controls_"))702 if (supHardViUtf16PathStartsWithAscii(pwsz, "amd64_microsoft.windows.common-controls_")) 644 703 # elif defined(RT_ARCH_X86) 645 if (supHardViUtf16PathStartsWith (pwsz, "x86_microsoft.windows.common-controls_"))704 if (supHardViUtf16PathStartsWithAscii(pwsz, "x86_microsoft.windows.common-controls_")) 646 705 # else 647 706 # error "Unsupported architecture" … … 655 714 /* Allow anything slightly microsoftish from WinSxS. W2K3 wanted winhttp.dll early on... */ 656 715 # ifdef RT_ARCH_AMD64 657 if (supHardViUtf16PathStartsWith (pwsz, "amd64_microsoft."))716 if (supHardViUtf16PathStartsWithAscii(pwsz, "amd64_microsoft.")) 658 717 # elif defined(RT_ARCH_X86) 659 if (supHardViUtf16PathStartsWith (pwsz, "x86_microsoft."))718 if (supHardViUtf16PathStartsWithAscii(pwsz, "x86_microsoft.")) 660 719 # else 661 720 # error "Unsupported architecture" … … 941 1000 #ifdef IN_RING3 942 1001 /* 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. 944 1005 */ 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 } 979 1051 #else /* !IN_RING3 */ 980 981 1052 if (pfCacheable) 1053 *pfCacheable = true; 982 1054 #endif /* !IN_RING3 */ 983 1055 984 1056 return rc; 985 1057 } 986 1058 … … 1502 1574 * and we require all VBox extensions to have it set as well. In effect, the 1503 1575 * authenticode signature will be checked two or three times. 1504 */ 1505 DECLHIDDEN(void) supR3HardenedWinResolveVerifyTrustApiAndHookThreadCreation(void) 1576 * 1577 * @param pszProgName The program name. 1578 */ 1579 DECLHIDDEN(void) supR3HardenedWinResolveVerifyTrustApiAndHookThreadCreation(const char *pszProgName) 1506 1580 { 1507 1581 # ifdef IN_SUP_HARDENED_R3 … … 1572 1646 &ErrInfoStatic.Core, pfnWinVerifyTrust); 1573 1647 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); 1575 1650 # endif 1576 1651 … … 1580 1655 1581 1656 g_pfnWinVerifyTrust = pfnWinVerifyTrust; 1657 SUP_DPRINTF(("g_pfnWinVerifyTrust=%p\n", pfnWinVerifyTrust)); 1582 1658 1583 1659 /* … … 1687 1763 case TRUST_E_EXPLICIT_DISTRUST: pszErrConst = "TRUST_E_EXPLICIT_DISTRUST"; break; 1688 1764 case CERT_E_CHAINING: pszErrConst = "CERT_E_CHAINING"; break; 1765 case CERT_E_REVOCATION_FAILURE: pszErrConst = "CERT_E_REVOCATION_FAILURE"; break; 1689 1766 } 1690 1767 if (pszErrConst) -
trunk/src/VBox/HostDrivers/Support/win/SUPLib-win.cpp
r52000 r52356 95 95 if (RT_FAILURE(rc)) 96 96 return rc; 97 supR3HardenedWinResolveVerifyTrustApiAndHookThreadCreation( );97 supR3HardenedWinResolveVerifyTrustApiAndHookThreadCreation(NULL); 98 98 #endif 99 99 g_fHardenedVerifyInited = true; -
trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp
r52204 r52356 63 63 * This just needs to be unique enough to avoid most confusion with real 64 64 * 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" 66 66 67 67 /** The first argument of a respawed stub when respawned for the second time. 68 68 * This just needs to be unique enough to avoid most confusion with real 69 69 * 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" 71 71 72 72 /** Unconditional assertion. */ … … 616 616 } 617 617 } 618 619 618 620 619 … … 771 770 Assert(g_SupLibHardenedExeNtPath.UniStr.Buffer[g_offSupLibHardenedExeNtName - 1] == '\\'); 772 771 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*/)) 776 773 { 777 774 fSystem32 = true; 778 775 fFlags |= SUPHNTVI_F_ALLOW_CAT_FILE_VERIFICATION; 779 776 } 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*/)) 783 778 fFlags |= SUPHNTVI_F_ALLOW_CAT_FILE_VERIFICATION; 784 else if ( uBuf.UniStr.Length > g_offSupLibHardenedExeNtName785 && 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*/)) 787 782 fFlags |= SUPHNTVI_F_REQUIRE_KERNEL_CODE_SIGNING | SUPHNTVI_F_REQUIRE_SIGNATURE_ENFORCEMENT; 788 783 #ifdef VBOX_PERMIT_MORE … … 804 799 { 805 800 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)", 807 802 uBuf.UniStr.Buffer, fImage, fExecMap, fExecProt); 808 803 if (hMyFile != hFile) … … 1867 1862 rc = supR3HardNtPuChSanitizePeb(&This); 1868 1863 if (RT_SUCCESS(rc)) 1864 { 1869 1865 rc = supHardenedWinVerifyProcess(hProcess, hThread, SUPHARDNTVPKIND_CHILD_PURIFICATION, pErrInfo); 1866 if (RT_FAILURE(rc)) 1867 Sleep(300000); 1868 } 1870 1869 1871 1870 return rc; … … 2532 2531 2533 2532 /* 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 /* 2534 2539 * Init g_uNtVerCombined. (The code is shared with SUPR3.lib and lives in 2535 2540 * SUPHardenedVerfiyImage-win.cpp.) … … 2550 2555 * Get the executable name. 2551 2556 */ 2552 DWORD cwcExecName = GetModuleFileNameW(GetModuleHandle (NULL), g_wszSupLibHardenedExePath,2557 DWORD cwcExecName = GetModuleFileNameW(GetModuleHandleW(NULL), g_wszSupLibHardenedExePath, 2553 2558 RT_ELEMENTS(g_wszSupLibHardenedExePath)); 2554 2559 if (cwcExecName >= RT_ELEMENTS(g_wszSupLibHardenedExePath)) -
trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMainA-win.asm
r51770 r52356 75 75 %endif 76 76 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 ; 98 BEGINDATA 99 global __imp_ %+ %1 ; The import name used via dllimport. 100 __imp_ %+ %1: 101 GLOBALNAME g_pfn %+ %1 ; The name we like to refer to. 102 RTCCPTR_DEF 0 103 %if %3 104 GLOBALNAME 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 ; 111 BEGINCODE 112 global SUPHNTIMP_STDCALL_NAME(%1, %2) 113 SUPHNTIMP_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 121 BEGINPROC %1 %+ _SyscallType1 122 mov eax, [NAME(g_uApiNo %+ %1) xWrtRIP] 123 mov r10, rcx 124 syscall 125 ret 126 ENDPROC %1 %+ _SyscallType1 127 %else 128 BEGINPROC %1 %+ _SyscallType1 129 mov edx, 07ffe0300h ; SharedUserData!SystemCallStub 130 mov eax, [NAME(g_uApiNo %+ %1) xWrtRIP] 131 call edx 132 ret %2 133 ENDPROC %1 %+ _SyscallType1 134 BEGINPROC %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 142 ENDPROC %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.