Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1476 lines
50 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. SecurityChecks.cpp
  5. Abstract:
  6. This AppVerifier shim hooks CreateProcess, CreateProcessAsUser,
  7. and WinExec and checks to see if some conditions exist that
  8. might allow trojan horse behavior to occur.
  9. Notes:
  10. This is a general purpose shim.
  11. History:
  12. 12/13/2001 rparsons Created
  13. --*/
  14. #include "precomp.h"
  15. IMPLEMENT_SHIM_BEGIN(SecurityChecks)
  16. #include "ShimHookMacro.h"
  17. //
  18. // verifier log entries
  19. //
  20. BEGIN_DEFINE_VERIFIER_LOG(SecurityChecks)
  21. VERIFIER_LOG_ENTRY(VLOG_SECURITYCHECKS_BADARGUMENTS)
  22. VERIFIER_LOG_ENTRY(VLOG_SECURITYCHECKS_WINEXEC)
  23. VERIFIER_LOG_ENTRY(VLOG_SECURITYCHECKS_NULL_DACL)
  24. VERIFIER_LOG_ENTRY(VLOG_SECURITYCHECKS_WORLDWRITE_DACL)
  25. END_DEFINE_VERIFIER_LOG(SecurityChecks)
  26. INIT_VERIFIER_LOG(SecurityChecks);
  27. APIHOOK_ENUM_BEGIN
  28. APIHOOK_ENUM_ENTRY(CreateProcessA)
  29. APIHOOK_ENUM_ENTRY(CreateProcessW)
  30. APIHOOK_ENUM_ENTRY(CreateProcessAsUserA)
  31. APIHOOK_ENUM_ENTRY(CreateProcessAsUserW)
  32. APIHOOK_ENUM_ENTRY(WinExec)
  33. APIHOOK_ENUM_ENTRY(CreateFileA)
  34. APIHOOK_ENUM_ENTRY(CreateFileW)
  35. APIHOOK_ENUM_ENTRY(CreateDesktopA)
  36. APIHOOK_ENUM_ENTRY(CreateDesktopW)
  37. APIHOOK_ENUM_ENTRY(CreateWindowStationA)
  38. APIHOOK_ENUM_ENTRY(CreateWindowStationW)
  39. APIHOOK_ENUM_ENTRY(RegCreateKeyExA)
  40. APIHOOK_ENUM_ENTRY(RegCreateKeyExW)
  41. APIHOOK_ENUM_ENTRY(RegSaveKeyA)
  42. APIHOOK_ENUM_ENTRY(RegSaveKeyW)
  43. APIHOOK_ENUM_ENTRY(RegSaveKeyExA)
  44. APIHOOK_ENUM_ENTRY(RegSaveKeyExW)
  45. APIHOOK_ENUM_ENTRY(CreateFileMappingA)
  46. APIHOOK_ENUM_ENTRY(CreateFileMappingW)
  47. APIHOOK_ENUM_ENTRY(CreateJobObjectA)
  48. APIHOOK_ENUM_ENTRY(CreateJobObjectW)
  49. APIHOOK_ENUM_ENTRY(CreateThread)
  50. APIHOOK_ENUM_ENTRY(CreateRemoteThread)
  51. APIHOOK_ENUM_ENTRY(CreateDirectoryA)
  52. APIHOOK_ENUM_ENTRY(CreateDirectoryW)
  53. APIHOOK_ENUM_ENTRY(CreateDirectoryExA)
  54. APIHOOK_ENUM_ENTRY(CreateDirectoryExW)
  55. APIHOOK_ENUM_ENTRY(CreateHardLinkA)
  56. APIHOOK_ENUM_ENTRY(CreateHardLinkW)
  57. APIHOOK_ENUM_ENTRY(CreateMailslotA)
  58. APIHOOK_ENUM_ENTRY(CreateMailslotW)
  59. APIHOOK_ENUM_ENTRY(CreateNamedPipeA)
  60. APIHOOK_ENUM_ENTRY(CreateNamedPipeW)
  61. APIHOOK_ENUM_ENTRY(CreatePipe)
  62. APIHOOK_ENUM_ENTRY(CreateMutexA)
  63. APIHOOK_ENUM_ENTRY(CreateMutexW)
  64. APIHOOK_ENUM_ENTRY(CreateSemaphoreA)
  65. APIHOOK_ENUM_ENTRY(CreateSemaphoreW)
  66. APIHOOK_ENUM_ENTRY(CreateWaitableTimerA)
  67. APIHOOK_ENUM_ENTRY(CreateWaitableTimerW)
  68. //APIHOOK_ENUM_ENTRY(ClusterRegCreateKey)
  69. //APIHOOK_ENUM_ENTRY(CreateNtmsMediaPoolA)
  70. //APIHOOK_ENUM_ENTRY(CreateNtmsMediaPoolW)
  71. APIHOOK_ENUM_END
  72. BYTE g_ajSidBuffer[SECURITY_MAX_SID_SIZE];
  73. PSID g_pWorldSid = NULL;
  74. WCHAR g_wszWinDir[MAX_PATH];
  75. DWORD g_dwWinDirLen = 0;
  76. void
  77. InitWorldSid(
  78. void
  79. )
  80. {
  81. DWORD dwSidSize = sizeof(g_ajSidBuffer);
  82. if (CreateWellKnownSid(WinWorldSid, NULL, g_ajSidBuffer, &dwSidSize)) {
  83. g_pWorldSid = g_ajSidBuffer;
  84. } else {
  85. g_pWorldSid = NULL;
  86. }
  87. }
  88. void
  89. CheckSecurityDescriptor(
  90. PSECURITY_DESCRIPTOR pSecurityDescriptor,
  91. LPCWSTR szCaller,
  92. LPCWSTR szParam,
  93. LPCWSTR szName
  94. )
  95. {
  96. BOOL bDaclPresent = FALSE;
  97. BOOL bDaclDefaulted = FALSE;
  98. PACL pDacl = NULL;
  99. if (!pSecurityDescriptor || !szName || !szName[0]) {
  100. //
  101. // there's no attributes, so they get the default, which is fine,
  102. // or the object doesn't have a name, so it can't be highjacked
  103. //
  104. return;
  105. }
  106. if (GetSecurityDescriptorDacl(pSecurityDescriptor, &bDaclPresent, &pDacl, &bDaclDefaulted)) {
  107. if (bDaclPresent) {
  108. if (!pDacl) {
  109. //
  110. // we have a NULL dacl -- log a problem
  111. //
  112. VLOG(VLOG_LEVEL_ERROR,
  113. VLOG_SECURITYCHECKS_NULL_DACL,
  114. "Called %ls, and specified a NULL DACL in %ls for object '%ls.'",
  115. szCaller,
  116. szParam,
  117. szName);
  118. return;
  119. }
  120. if (!g_pWorldSid) {
  121. //
  122. // we never were able to get the world Sid
  123. //
  124. return;
  125. }
  126. for (DWORD i = 0; i < pDacl->AceCount; ++i) {
  127. PACE_HEADER pAceHeader = NULL;
  128. PSID pSID;
  129. ACCESS_MASK dwAccessMask;
  130. if (!GetAce(pDacl, i, (LPVOID*)&pAceHeader)) {
  131. continue;
  132. }
  133. //
  134. // if it's not some form of ACCESS_ALLOWED ACE, we aren't interested
  135. //
  136. if (pAceHeader->AceType == ACCESS_ALLOWED_ACE_TYPE) {
  137. pSID = &(((PACCESS_ALLOWED_ACE)pAceHeader)->SidStart);
  138. dwAccessMask = ((PACCESS_ALLOWED_ACE)pAceHeader)->Mask;
  139. } else if (pAceHeader->AceType == ACCESS_ALLOWED_OBJECT_ACE_TYPE) {
  140. PACCESS_ALLOWED_OBJECT_ACE pAAOAce = (PACCESS_ALLOWED_OBJECT_ACE)pAceHeader;
  141. //
  142. // who the heck came up with this system? The Sid starts at a different place
  143. // depending on the flags. Anyone ever heard of multiple structs? Sigh.
  144. //
  145. if ((pAAOAce->Flags & ACE_OBJECT_TYPE_PRESENT) && (pAAOAce->Flags & ACE_INHERITED_OBJECT_TYPE_PRESENT)) {
  146. pSID = &(pAAOAce->SidStart);
  147. } else if ((pAAOAce->Flags & ACE_OBJECT_TYPE_PRESENT) || (pAAOAce->Flags & ACE_INHERITED_OBJECT_TYPE_PRESENT)){
  148. pSID = (PSID)&(pAAOAce->InheritedObjectType);
  149. } else {
  150. pSID = (PSID)&(pAAOAce->ObjectType);
  151. }
  152. dwAccessMask = ((PACCESS_ALLOWED_OBJECT_ACE)pAceHeader)->Mask;
  153. } else {
  154. continue;
  155. }
  156. //
  157. // check the validity of the SID, just to be safe
  158. //
  159. if (!IsValidSid(pSID)) {
  160. continue;
  161. }
  162. //
  163. // if the SID is the world, and the access mask allows WRITE_DAC and WRITE_OWNER, we have a problem
  164. //
  165. if ((dwAccessMask & (WRITE_DAC | WRITE_OWNER)) && EqualSid(pSID, g_pWorldSid)) {
  166. VLOG(VLOG_LEVEL_ERROR,
  167. VLOG_SECURITYCHECKS_WORLDWRITE_DACL,
  168. "Called %ls, and specified a DACL with WRITE_DAC and/or WRITE_OWNER for WORLD in %ls for object '%ls.'",
  169. szCaller,
  170. szParam,
  171. szName);
  172. return;
  173. }
  174. }
  175. }
  176. }
  177. }
  178. void
  179. CheckSecurityAttributes(
  180. LPSECURITY_ATTRIBUTES pSecurityAttrib,
  181. LPCWSTR szCaller,
  182. LPCWSTR szParam,
  183. LPCWSTR szName
  184. )
  185. {
  186. PSECURITY_DESCRIPTOR pSecurityDescriptor = NULL;
  187. if (!pSecurityAttrib) {
  188. //
  189. // there's no attributes, so they get the default, which is fine
  190. //
  191. return;
  192. }
  193. pSecurityDescriptor = (PSECURITY_DESCRIPTOR)pSecurityAttrib->lpSecurityDescriptor;
  194. CheckSecurityDescriptor(pSecurityDescriptor, szCaller, szParam, szName);
  195. }
  196. void
  197. CheckCreateProcess(
  198. LPCWSTR pwszApplicationName,
  199. LPCWSTR pwszCommandLine,
  200. LPCWSTR pwszCaller
  201. )
  202. {
  203. //
  204. // if applicationname is non-null, there's no problem
  205. //
  206. if (pwszApplicationName) {
  207. return;
  208. }
  209. //
  210. // if there's no command line, there's a problem, but not one we want to solve
  211. //
  212. if (!pwszCommandLine) {
  213. return;
  214. }
  215. //
  216. // if there are no spaces, no problem
  217. //
  218. LPWSTR pSpaceLoc = wcschr(pwszCommandLine, L' ');
  219. if (!pSpaceLoc) {
  220. return;
  221. }
  222. //
  223. // if the beginning of the command line is quoted, no problem
  224. //
  225. if (pwszCommandLine[0] == L'\"') {
  226. return;
  227. }
  228. //
  229. // if the phrase '.exe ' appears before the first space, we'll call that good
  230. //
  231. LPWSTR pExeLoc = wcsistr(pwszCommandLine, L".exe ");
  232. if (pExeLoc && pExeLoc < pSpaceLoc) {
  233. return;
  234. }
  235. //
  236. // if the first part of the command line is windir, we'll call that good
  237. //
  238. if (g_dwWinDirLen && _wcsnicmp(pwszCommandLine, g_wszWinDir, g_dwWinDirLen) == 0) {
  239. return;
  240. }
  241. if (_wcsicmp(pwszCaller, L"winexec") == 0) {
  242. VLOG(VLOG_LEVEL_ERROR,
  243. VLOG_SECURITYCHECKS_BADARGUMENTS,
  244. "Called %ls with command line '%ls'. The command line has spaces, and the exe name is not in quotes.",
  245. pwszCaller,
  246. pwszCommandLine);
  247. } else {
  248. VLOG(VLOG_LEVEL_ERROR,
  249. VLOG_SECURITYCHECKS_BADARGUMENTS,
  250. "Called %ls with command line '%ls'. The lpApplicationName argument is NULL, lpCommandLine has spaces, and the exe name is not in quotes.",
  251. pwszCaller,
  252. pwszCommandLine);
  253. }
  254. }
  255. void
  256. CheckForNoPathInFileName(
  257. LPCWSTR pwszFilePath,
  258. LPCWSTR pwszCaller
  259. )
  260. {
  261. if (!pwszFilePath || !pwszCaller) {
  262. return;
  263. }
  264. //
  265. // skip quotes and space if necessary
  266. //
  267. DWORD dwBegin = 0;
  268. while (pwszFilePath[dwBegin] == L'\"' || pwszFilePath[dwBegin] == L' ') {
  269. dwBegin++;
  270. }
  271. //
  272. // if there's nothing left of the string, get out
  273. //
  274. if (!pwszFilePath[dwBegin] || !pwszFilePath[dwBegin + 1]) {
  275. return;
  276. }
  277. //
  278. // check for DOS (x:...) and UNC (\\...) full paths
  279. //
  280. if (pwszFilePath[dwBegin + 1] == L':' || (pwszFilePath[dwBegin] == L'\\' && pwszFilePath[dwBegin + 1] == L'\\')) {
  281. //
  282. // full path
  283. //
  284. return;
  285. }
  286. VLOG(VLOG_LEVEL_ERROR,
  287. VLOG_SECURITYCHECKS_BADARGUMENTS,
  288. "Called '%ls' with '%ls' specified. Use a full path to the file to ensure that you get the executable you want, and not a malicious exe with the same name.",
  289. pwszCaller,
  290. pwszFilePath);
  291. }
  292. BOOL
  293. APIHOOK(CreateProcessA)(
  294. LPCSTR lpApplicationName,
  295. LPSTR lpCommandLine,
  296. LPSECURITY_ATTRIBUTES lpProcessAttributes,
  297. LPSECURITY_ATTRIBUTES lpThreadAttributes,
  298. BOOL bInheritHandles,
  299. DWORD dwCreationFlags,
  300. LPVOID lpEnvironment,
  301. LPCSTR lpCurrentDirectory,
  302. LPSTARTUPINFOA lpStartupInfo,
  303. LPPROCESS_INFORMATION lpProcessInformation
  304. )
  305. {
  306. LPWSTR pwszApplicationName = ToUnicode(lpApplicationName);
  307. LPWSTR pwszCommandLine = ToUnicode(lpCommandLine);
  308. CheckCreateProcess(pwszApplicationName, pwszCommandLine, L"CreateProcess");
  309. if (pwszApplicationName) {
  310. CheckForNoPathInFileName(pwszApplicationName, L"CreateProcess");
  311. CheckSecurityAttributes(lpProcessAttributes, L"CreateProcess", L"lpProcessAttributes", pwszApplicationName);
  312. CheckSecurityAttributes(lpThreadAttributes, L"CreateProcess", L"lpThreadAttributes", pwszApplicationName);
  313. } else {
  314. CheckForNoPathInFileName(pwszCommandLine, L"CreateProcess");
  315. CheckSecurityAttributes(lpProcessAttributes, L"CreateProcess", L"lpProcessAttributes", pwszCommandLine);
  316. CheckSecurityAttributes(lpThreadAttributes, L"CreateProcess", L"lpThreadAttributes", pwszCommandLine);
  317. }
  318. if (pwszApplicationName) {
  319. free(pwszApplicationName);
  320. pwszApplicationName = NULL;
  321. }
  322. if (pwszCommandLine) {
  323. free(pwszCommandLine);
  324. pwszCommandLine = NULL;
  325. }
  326. return ORIGINAL_API(CreateProcessA)(lpApplicationName,
  327. lpCommandLine,
  328. lpProcessAttributes,
  329. lpThreadAttributes,
  330. bInheritHandles,
  331. dwCreationFlags,
  332. lpEnvironment,
  333. lpCurrentDirectory,
  334. lpStartupInfo,
  335. lpProcessInformation);
  336. }
  337. BOOL
  338. APIHOOK(CreateProcessW)(
  339. LPCWSTR lpApplicationName,
  340. LPWSTR lpCommandLine,
  341. LPSECURITY_ATTRIBUTES lpProcessAttributes,
  342. LPSECURITY_ATTRIBUTES lpThreadAttributes,
  343. BOOL bInheritHandles,
  344. DWORD dwCreationFlags,
  345. LPVOID lpEnvironment,
  346. LPWSTR lpCurrentDirectory,
  347. LPSTARTUPINFOW lpStartupInfo,
  348. LPPROCESS_INFORMATION lpProcessInformation
  349. )
  350. {
  351. CheckCreateProcess(lpApplicationName, lpCommandLine, L"CreateProcess");
  352. if (lpApplicationName) {
  353. CheckForNoPathInFileName(lpApplicationName, L"CreateProcess");
  354. CheckSecurityAttributes(lpProcessAttributes, L"CreateProcess", L"lpProcessAttributes", lpApplicationName);
  355. CheckSecurityAttributes(lpThreadAttributes, L"CreateProcess", L"lpThreadAttributes", lpApplicationName);
  356. } else {
  357. CheckForNoPathInFileName(lpCommandLine, L"CreateProcess");
  358. CheckSecurityAttributes(lpProcessAttributes, L"CreateProcess", L"lpProcessAttributes", lpCommandLine);
  359. CheckSecurityAttributes(lpThreadAttributes, L"CreateProcess", L"lpThreadAttributes", lpCommandLine);
  360. }
  361. return ORIGINAL_API(CreateProcessW)(lpApplicationName,
  362. lpCommandLine,
  363. lpProcessAttributes,
  364. lpThreadAttributes,
  365. bInheritHandles,
  366. dwCreationFlags,
  367. lpEnvironment,
  368. lpCurrentDirectory,
  369. lpStartupInfo,
  370. lpProcessInformation);
  371. }
  372. BOOL
  373. APIHOOK(CreateProcessAsUserA)(
  374. HANDLE hToken,
  375. LPCSTR lpApplicationName,
  376. LPSTR lpCommandLine,
  377. LPSECURITY_ATTRIBUTES lpProcessAttributes,
  378. LPSECURITY_ATTRIBUTES lpThreadAttributes,
  379. BOOL bInheritHandles,
  380. DWORD dwCreationFlags,
  381. LPVOID lpEnvironment,
  382. LPCSTR lpCurrentDirectory,
  383. LPSTARTUPINFOA lpStartupInfo,
  384. LPPROCESS_INFORMATION lpProcessInformation
  385. )
  386. {
  387. LPWSTR pwszApplicationName = ToUnicode(lpApplicationName);
  388. LPWSTR pwszCommandLine = ToUnicode(lpCommandLine);
  389. CheckCreateProcess(pwszApplicationName, pwszCommandLine, L"CreateProcessAsUser");
  390. if (pwszApplicationName) {
  391. CheckForNoPathInFileName(pwszApplicationName, L"CreateProcessAsUser");
  392. CheckSecurityAttributes(lpProcessAttributes, L"CreateProcessAsUser", L"lpProcessAttributes", pwszApplicationName);
  393. CheckSecurityAttributes(lpThreadAttributes, L"CreateProcessAsUser", L"lpThreadAttributes", pwszApplicationName);
  394. } else {
  395. CheckForNoPathInFileName(pwszCommandLine, L"CreateProcessAsUser");
  396. CheckSecurityAttributes(lpProcessAttributes, L"CreateProcessAsUser", L"lpProcessAttributes", pwszCommandLine);
  397. CheckSecurityAttributes(lpThreadAttributes, L"CreateProcessAsUser", L"lpThreadAttributes", pwszCommandLine);
  398. }
  399. if (pwszApplicationName) {
  400. free(pwszApplicationName);
  401. pwszApplicationName = NULL;
  402. }
  403. if (pwszCommandLine) {
  404. free(pwszCommandLine);
  405. pwszCommandLine = NULL;
  406. }
  407. return ORIGINAL_API(CreateProcessAsUserA)(hToken,
  408. lpApplicationName,
  409. lpCommandLine,
  410. lpProcessAttributes,
  411. lpThreadAttributes,
  412. bInheritHandles,
  413. dwCreationFlags,
  414. lpEnvironment,
  415. lpCurrentDirectory,
  416. lpStartupInfo,
  417. lpProcessInformation);
  418. }
  419. BOOL
  420. APIHOOK(CreateProcessAsUserW)(
  421. HANDLE hToken,
  422. LPCWSTR lpApplicationName,
  423. LPWSTR lpCommandLine,
  424. LPSECURITY_ATTRIBUTES lpProcessAttributes,
  425. LPSECURITY_ATTRIBUTES lpThreadAttributes,
  426. BOOL bInheritHandles,
  427. DWORD dwCreationFlags,
  428. LPVOID lpEnvironment,
  429. LPWSTR lpCurrentDirectory,
  430. LPSTARTUPINFOW lpStartupInfo,
  431. LPPROCESS_INFORMATION lpProcessInformation
  432. )
  433. {
  434. CheckCreateProcess(lpApplicationName, lpCommandLine, L"CreateProcessAsUser");
  435. if (lpApplicationName) {
  436. CheckForNoPathInFileName(lpApplicationName, L"CreateProcessAsUser");
  437. CheckSecurityAttributes(lpProcessAttributes, L"CreateProcessAsUser", L"lpProcessAttributes", lpApplicationName);
  438. CheckSecurityAttributes(lpThreadAttributes, L"CreateProcessAsUser", L"lpThreadAttributes", lpApplicationName);
  439. } else {
  440. CheckForNoPathInFileName(lpCommandLine, L"CreateProcessAsUser");
  441. CheckSecurityAttributes(lpProcessAttributes, L"CreateProcessAsUser", L"lpProcessAttributes", lpCommandLine);
  442. CheckSecurityAttributes(lpThreadAttributes, L"CreateProcessAsUser", L"lpThreadAttributes", lpCommandLine);
  443. }
  444. return ORIGINAL_API(CreateProcessAsUserW)(hToken,
  445. lpApplicationName,
  446. lpCommandLine,
  447. lpProcessAttributes,
  448. lpThreadAttributes,
  449. bInheritHandles,
  450. dwCreationFlags,
  451. lpEnvironment,
  452. lpCurrentDirectory,
  453. lpStartupInfo,
  454. lpProcessInformation);
  455. }
  456. UINT
  457. APIHOOK(WinExec)(
  458. LPCSTR lpCmdLine,
  459. UINT uCmdShow
  460. )
  461. {
  462. LPWSTR pwszCmdLine = ToUnicode(lpCmdLine);
  463. VLOG(VLOG_LEVEL_ERROR, VLOG_SECURITYCHECKS_WINEXEC, "Called WinExec.");
  464. CheckForNoPathInFileName(pwszCmdLine, L"WinExec");
  465. CheckCreateProcess(NULL, pwszCmdLine, L"WinExec");
  466. if (pwszCmdLine) {
  467. free(pwszCmdLine);
  468. pwszCmdLine = NULL;
  469. }
  470. return ORIGINAL_API(WinExec)(lpCmdLine, uCmdShow);
  471. }
  472. HANDLE
  473. APIHOOK(CreateFileA)(
  474. LPCSTR lpFileName, // file name
  475. DWORD dwDesiredAccess, // access mode
  476. DWORD dwShareMode, // share mode
  477. LPSECURITY_ATTRIBUTES lpSecurityAttributes, // SD
  478. DWORD dwCreationDisposition, // how to create
  479. DWORD dwFlagsAndAttributes, // file attributes
  480. HANDLE hTemplateFile // handle to template file
  481. )
  482. {
  483. LPWSTR pwszName = ToUnicode(lpFileName);
  484. CheckSecurityAttributes(lpSecurityAttributes, L"CreateFile", L"lpSecurityAttributes", pwszName);
  485. if (pwszName) {
  486. free(pwszName);
  487. pwszName = NULL;
  488. }
  489. return ORIGINAL_API(CreateFileA)(lpFileName,
  490. dwDesiredAccess,
  491. dwShareMode,
  492. lpSecurityAttributes,
  493. dwCreationDisposition,
  494. dwFlagsAndAttributes,
  495. hTemplateFile);
  496. }
  497. HANDLE
  498. APIHOOK(CreateFileW)(
  499. LPCWSTR lpFileName, // file name
  500. DWORD dwDesiredAccess, // access mode
  501. DWORD dwShareMode, // share mode
  502. LPSECURITY_ATTRIBUTES lpSecurityAttributes, // SD
  503. DWORD dwCreationDisposition, // how to create
  504. DWORD dwFlagsAndAttributes, // file attributes
  505. HANDLE hTemplateFile // handle to template file
  506. )
  507. {
  508. CheckSecurityAttributes(lpSecurityAttributes, L"CreateFile", L"lpSecurityAttributes", lpFileName);
  509. return ORIGINAL_API(CreateFileW)(lpFileName,
  510. dwDesiredAccess,
  511. dwShareMode,
  512. lpSecurityAttributes,
  513. dwCreationDisposition,
  514. dwFlagsAndAttributes,
  515. hTemplateFile);
  516. }
  517. HDESK
  518. APIHOOK(CreateDesktopA)(
  519. LPCSTR lpszDesktop, // name of new desktop
  520. LPCSTR lpszDevice, // reserved; must be NULL
  521. LPDEVMODEA pDevmode, // reserved; must be NULL
  522. DWORD dwFlags, // desktop interaction
  523. ACCESS_MASK dwDesiredAccess, // access of returned handle
  524. LPSECURITY_ATTRIBUTES lpsa // security attributes
  525. )
  526. {
  527. LPWSTR pwszName = ToUnicode(lpszDesktop);
  528. CheckSecurityAttributes(lpsa, L"CreateDesktop", L"lpsa", pwszName);
  529. if (pwszName) {
  530. free(pwszName);
  531. pwszName = NULL;
  532. }
  533. return ORIGINAL_API(CreateDesktopA)(lpszDesktop,
  534. lpszDevice,
  535. pDevmode,
  536. dwFlags,
  537. dwDesiredAccess,
  538. lpsa);
  539. }
  540. HDESK
  541. APIHOOK(CreateDesktopW)(
  542. LPCWSTR lpszDesktop, // name of new desktop
  543. LPCWSTR lpszDevice, // reserved; must be NULL
  544. LPDEVMODEW pDevmode, // reserved; must be NULL
  545. DWORD dwFlags, // desktop interaction
  546. ACCESS_MASK dwDesiredAccess, // access of returned handle
  547. LPSECURITY_ATTRIBUTES lpsa // security attributes
  548. )
  549. {
  550. CheckSecurityAttributes(lpsa, L"CreateDesktop", L"lpsa", lpszDesktop);
  551. return ORIGINAL_API(CreateDesktopW)(lpszDesktop,
  552. lpszDevice,
  553. pDevmode,
  554. dwFlags,
  555. dwDesiredAccess,
  556. lpsa);
  557. }
  558. HWINSTA
  559. APIHOOK(CreateWindowStationA)(
  560. LPSTR lpwinsta, // new window station name
  561. DWORD dwReserved, // reserved; must be zero
  562. ACCESS_MASK dwDesiredAccess, // requested access
  563. LPSECURITY_ATTRIBUTES lpsa // security attributes
  564. )
  565. {
  566. LPWSTR pwszName = ToUnicode(lpwinsta);
  567. CheckSecurityAttributes(lpsa, L"CreateWindowStation", L"lpsa", pwszName);
  568. if (pwszName) {
  569. free(pwszName);
  570. pwszName = NULL;
  571. }
  572. return ORIGINAL_API(CreateWindowStationA)(lpwinsta,
  573. dwReserved,
  574. dwDesiredAccess,
  575. lpsa);
  576. }
  577. HWINSTA
  578. APIHOOK(CreateWindowStationW)(
  579. LPWSTR lpwinsta, // new window station name
  580. DWORD dwReserved, // reserved; must be zero
  581. ACCESS_MASK dwDesiredAccess, // requested access
  582. LPSECURITY_ATTRIBUTES lpsa // security attributes
  583. )
  584. {
  585. CheckSecurityAttributes(lpsa, L"CreateWindowStation", L"lpsa", lpwinsta);
  586. return ORIGINAL_API(CreateWindowStationW)(lpwinsta,
  587. dwReserved,
  588. dwDesiredAccess,
  589. lpsa);
  590. }
  591. LONG
  592. APIHOOK(RegCreateKeyExA)(
  593. HKEY hKey,
  594. LPCSTR lpSubKey,
  595. DWORD Reserved,
  596. LPSTR lpClass,
  597. DWORD dwOptions,
  598. REGSAM samDesired,
  599. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  600. PHKEY phkResult,
  601. LPDWORD lpdwDisposition
  602. )
  603. {
  604. LPWSTR pwszName = ToUnicode(lpSubKey);
  605. CheckSecurityAttributes(lpSecurityAttributes, L"RegCreateKeyEx", L"lpSecurityAttributes", pwszName);
  606. if (pwszName) {
  607. free(pwszName);
  608. pwszName = NULL;
  609. }
  610. return ORIGINAL_API(RegCreateKeyExA)(hKey,
  611. lpSubKey,
  612. Reserved,
  613. lpClass,
  614. dwOptions,
  615. samDesired,
  616. lpSecurityAttributes,
  617. phkResult,
  618. lpdwDisposition);
  619. }
  620. LONG
  621. APIHOOK(RegCreateKeyExW)(
  622. HKEY hKey,
  623. LPCWSTR lpSubKey,
  624. DWORD Reserved,
  625. LPWSTR lpClass,
  626. DWORD dwOptions,
  627. REGSAM samDesired,
  628. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  629. PHKEY phkResult,
  630. LPDWORD lpdwDisposition
  631. )
  632. {
  633. CheckSecurityAttributes(lpSecurityAttributes, L"RegCreateKeyEx", L"lpSecurityAttributes", lpSubKey);
  634. return ORIGINAL_API(RegCreateKeyExW)(hKey,
  635. lpSubKey,
  636. Reserved,
  637. lpClass,
  638. dwOptions,
  639. samDesired,
  640. lpSecurityAttributes,
  641. phkResult,
  642. lpdwDisposition);
  643. }
  644. LONG
  645. APIHOOK(RegSaveKeyA)(
  646. HKEY hKey, // handle to key
  647. LPCSTR lpFile, // data file
  648. LPSECURITY_ATTRIBUTES lpSecurityAttributes // SD
  649. )
  650. {
  651. LPWSTR pwszName = ToUnicode(lpFile);
  652. CheckSecurityAttributes(lpSecurityAttributes, L"RegSaveKey", L"lpSecurityAttributes", pwszName);
  653. if (pwszName) {
  654. free(pwszName);
  655. pwszName = NULL;
  656. }
  657. return ORIGINAL_API(RegSaveKeyA)(hKey,
  658. lpFile,
  659. lpSecurityAttributes);
  660. }
  661. LONG
  662. APIHOOK(RegSaveKeyW)(
  663. HKEY hKey, // handle to key
  664. LPCWSTR lpFile, // data file
  665. LPSECURITY_ATTRIBUTES lpSecurityAttributes // SD
  666. )
  667. {
  668. CheckSecurityAttributes(lpSecurityAttributes, L"RegSaveKey", L"lpSecurityAttributes", lpFile);
  669. return ORIGINAL_API(RegSaveKeyW)(hKey,
  670. lpFile,
  671. lpSecurityAttributes);
  672. }
  673. LONG
  674. APIHOOK(RegSaveKeyExA)(
  675. HKEY hKey, // handle to key
  676. LPCSTR lpFile, // data file
  677. LPSECURITY_ATTRIBUTES lpSecurityAttributes, // SD
  678. DWORD Flags
  679. )
  680. {
  681. LPWSTR pwszName = ToUnicode(lpFile);
  682. CheckSecurityAttributes(lpSecurityAttributes, L"RegSaveKeyEx", L"lpSecurityAttributes", pwszName);
  683. if (pwszName) {
  684. free(pwszName);
  685. pwszName = NULL;
  686. }
  687. return ORIGINAL_API(RegSaveKeyExA)(hKey,
  688. lpFile,
  689. lpSecurityAttributes,
  690. Flags);
  691. }
  692. LONG
  693. APIHOOK(RegSaveKeyExW)(
  694. HKEY hKey, // handle to key
  695. LPCWSTR lpFile, // data file
  696. LPSECURITY_ATTRIBUTES lpSecurityAttributes, // SD
  697. DWORD Flags
  698. )
  699. {
  700. CheckSecurityAttributes(lpSecurityAttributes, L"RegSaveKeyEx", L"lpSecurityAttributes", lpFile);
  701. return ORIGINAL_API(RegSaveKeyExW)(hKey,
  702. lpFile,
  703. lpSecurityAttributes,
  704. Flags);
  705. }
  706. HANDLE
  707. APIHOOK(CreateFileMappingA)(
  708. HANDLE hFile,
  709. LPSECURITY_ATTRIBUTES lpAttributes,
  710. DWORD flProtect,
  711. DWORD dwMaximumSizeHigh,
  712. DWORD dwMaximumSizeLow,
  713. LPCSTR lpName
  714. )
  715. {
  716. LPWSTR pwszName = ToUnicode(lpName);
  717. CheckSecurityAttributes(lpAttributes, L"CreateFileMapping", L"lpAttributes", pwszName);
  718. if (pwszName) {
  719. free(pwszName);
  720. pwszName = NULL;
  721. }
  722. return ORIGINAL_API(CreateFileMappingA)(hFile,
  723. lpAttributes,
  724. flProtect,
  725. dwMaximumSizeHigh,
  726. dwMaximumSizeLow,
  727. lpName);
  728. }
  729. HANDLE
  730. APIHOOK(CreateFileMappingW)(
  731. HANDLE hFile,
  732. LPSECURITY_ATTRIBUTES lpAttributes,
  733. DWORD flProtect,
  734. DWORD dwMaximumSizeHigh,
  735. DWORD dwMaximumSizeLow,
  736. LPCWSTR lpName
  737. )
  738. {
  739. CheckSecurityAttributes(lpAttributes, L"CreateFileMapping", L"lpAttributes", lpName);
  740. return ORIGINAL_API(CreateFileMappingW)(hFile,
  741. lpAttributes,
  742. flProtect,
  743. dwMaximumSizeHigh,
  744. dwMaximumSizeLow,
  745. lpName);
  746. }
  747. HANDLE
  748. APIHOOK(CreateJobObjectA)(
  749. LPSECURITY_ATTRIBUTES lpJobAttributes, // SD
  750. LPCSTR lpName // job name
  751. )
  752. {
  753. LPWSTR pwszName = ToUnicode(lpName);
  754. CheckSecurityAttributes(lpJobAttributes, L"CreateJobObject", L"lpJobAttributes", pwszName);
  755. if (pwszName) {
  756. free(pwszName);
  757. pwszName = NULL;
  758. }
  759. return ORIGINAL_API(CreateJobObjectA)(lpJobAttributes,
  760. lpName);
  761. }
  762. HANDLE
  763. APIHOOK(CreateJobObjectW)(
  764. LPSECURITY_ATTRIBUTES lpJobAttributes, // SD
  765. LPCWSTR lpName // job name
  766. )
  767. {
  768. CheckSecurityAttributes(lpJobAttributes, L"CreateJobObject", L"lpJobAttributes", lpName);
  769. return ORIGINAL_API(CreateJobObjectW)(lpJobAttributes,
  770. lpName);
  771. }
  772. HANDLE
  773. APIHOOK(CreateThread)(
  774. LPSECURITY_ATTRIBUTES lpThreadAttributes, // SD
  775. SIZE_T dwStackSize, // initial stack size
  776. LPTHREAD_START_ROUTINE lpStartAddress, // thread function
  777. LPVOID lpParameter, // thread argument
  778. DWORD dwCreationFlags, // creation option
  779. LPDWORD lpThreadId // thread identifier
  780. )
  781. {
  782. CheckSecurityAttributes(lpThreadAttributes, L"CreateThread", L"lpThreadAttributes", L"Unnamed thread");
  783. return ORIGINAL_API(CreateThread)(lpThreadAttributes,
  784. (DWORD)dwStackSize,
  785. lpStartAddress,
  786. lpParameter,
  787. dwCreationFlags,
  788. lpThreadId);
  789. }
  790. HANDLE
  791. APIHOOK(CreateRemoteThread)(
  792. HANDLE hProcess, // handle to process
  793. LPSECURITY_ATTRIBUTES lpThreadAttributes, // SD
  794. SIZE_T dwStackSize, // initial stack size
  795. LPTHREAD_START_ROUTINE lpStartAddress, // thread function
  796. LPVOID lpParameter, // thread argument
  797. DWORD dwCreationFlags, // creation option
  798. LPDWORD lpThreadId // thread identifier
  799. )
  800. {
  801. CheckSecurityAttributes(lpThreadAttributes, L"CreateRemoteThread", L"lpThreadAttributes", L"Unnamed thread");
  802. return ORIGINAL_API(CreateRemoteThread)(hProcess,
  803. lpThreadAttributes,
  804. dwStackSize,
  805. lpStartAddress,
  806. lpParameter,
  807. dwCreationFlags,
  808. lpThreadId);
  809. }
  810. BOOL
  811. APIHOOK(CreateDirectoryA)(
  812. LPCSTR lpPathName, // directory name
  813. LPSECURITY_ATTRIBUTES lpSecurityAttributes // SD
  814. )
  815. {
  816. LPWSTR pwszName = ToUnicode(lpPathName);
  817. CheckSecurityAttributes(lpSecurityAttributes, L"CreateDirectory", L"lpSecurityAttributes", pwszName);
  818. if (pwszName) {
  819. free(pwszName);
  820. pwszName = NULL;
  821. }
  822. return ORIGINAL_API(CreateDirectoryA)(lpPathName,
  823. lpSecurityAttributes);
  824. }
  825. BOOL
  826. APIHOOK(CreateDirectoryW)(
  827. LPCWSTR lpPathName, // directory name
  828. LPSECURITY_ATTRIBUTES lpSecurityAttributes // SD
  829. )
  830. {
  831. CheckSecurityAttributes(lpSecurityAttributes, L"CreateDirectory", L"lpSecurityAttributes", lpPathName);
  832. return ORIGINAL_API(CreateDirectoryW)(lpPathName,
  833. lpSecurityAttributes);
  834. }
  835. BOOL
  836. APIHOOK(CreateDirectoryExA)(
  837. LPCSTR lpTemplateDirectory, // template directory
  838. LPCSTR lpNewDirectory, // directory name
  839. LPSECURITY_ATTRIBUTES lpSecurityAttributes // SD
  840. )
  841. {
  842. LPWSTR pwszName = ToUnicode(lpNewDirectory);
  843. CheckSecurityAttributes(lpSecurityAttributes, L"CreateDirectoryEx", L"lpSecurityAttributes", pwszName);
  844. if (pwszName) {
  845. free(pwszName);
  846. pwszName = NULL;
  847. }
  848. return ORIGINAL_API(CreateDirectoryExA)(lpTemplateDirectory,
  849. lpNewDirectory,
  850. lpSecurityAttributes);
  851. }
  852. BOOL
  853. APIHOOK(CreateDirectoryExW)(
  854. LPCWSTR lpTemplateDirectory, // template directory
  855. LPCWSTR lpNewDirectory, // directory name
  856. LPSECURITY_ATTRIBUTES lpSecurityAttributes // SD
  857. )
  858. {
  859. CheckSecurityAttributes(lpSecurityAttributes, L"CreateDirectoryEx", L"lpSecurityAttributes", lpNewDirectory);
  860. return ORIGINAL_API(CreateDirectoryExW)(lpTemplateDirectory,
  861. lpNewDirectory,
  862. lpSecurityAttributes);
  863. }
  864. BOOL
  865. APIHOOK(CreateHardLinkA)(
  866. LPCSTR lpFileName, // link name name
  867. LPCSTR lpExistingFileName, // target file name
  868. LPSECURITY_ATTRIBUTES lpSecurityAttributes
  869. )
  870. {
  871. LPWSTR pwszName = ToUnicode(lpFileName);
  872. CheckSecurityAttributes(lpSecurityAttributes, L"CreateHardLink", L"lpSecurityAttributes", pwszName);
  873. if (pwszName) {
  874. free(pwszName);
  875. pwszName = NULL;
  876. }
  877. return ORIGINAL_API(CreateHardLinkA)(lpFileName,
  878. lpExistingFileName,
  879. lpSecurityAttributes);
  880. }
  881. BOOL
  882. APIHOOK(CreateHardLinkW)(
  883. LPCWSTR lpFileName, // link name name
  884. LPCWSTR lpExistingFileName, // target file name
  885. LPSECURITY_ATTRIBUTES lpSecurityAttributes
  886. )
  887. {
  888. CheckSecurityAttributes(lpSecurityAttributes, L"CreateHardLink", L"lpSecurityAttributes", lpFileName);
  889. return ORIGINAL_API(CreateHardLinkW)(lpFileName,
  890. lpExistingFileName,
  891. lpSecurityAttributes);
  892. }
  893. HANDLE
  894. APIHOOK(CreateMailslotA)(
  895. LPCSTR lpName, // mailslot name
  896. DWORD nMaxMessageSize, // maximum message size
  897. DWORD lReadTimeout, // read time-out interval
  898. LPSECURITY_ATTRIBUTES lpSecurityAttributes // inheritance option
  899. )
  900. {
  901. LPWSTR pwszName = ToUnicode(lpName);
  902. CheckSecurityAttributes(lpSecurityAttributes, L"CreateMailslot", L"lpSecurityAttributes", pwszName);
  903. if (pwszName) {
  904. free(pwszName);
  905. pwszName = NULL;
  906. }
  907. return ORIGINAL_API(CreateMailslotA)(lpName,
  908. nMaxMessageSize,
  909. lReadTimeout,
  910. lpSecurityAttributes);
  911. }
  912. HANDLE
  913. APIHOOK(CreateMailslotW)(
  914. LPCWSTR lpName, // mailslot name
  915. DWORD nMaxMessageSize, // maximum message size
  916. DWORD lReadTimeout, // read time-out interval
  917. LPSECURITY_ATTRIBUTES lpSecurityAttributes // inheritance option
  918. )
  919. {
  920. CheckSecurityAttributes(lpSecurityAttributes, L"CreateMailslot", L"lpSecurityAttributes", lpName);
  921. return ORIGINAL_API(CreateMailslotW)(lpName,
  922. nMaxMessageSize,
  923. lReadTimeout,
  924. lpSecurityAttributes);
  925. }
  926. HANDLE
  927. APIHOOK(CreateNamedPipeA)(
  928. LPCSTR lpName, // pipe name
  929. DWORD dwOpenMode, // pipe open mode
  930. DWORD dwPipeMode, // pipe-specific modes
  931. DWORD nMaxInstances, // maximum number of instances
  932. DWORD nOutBufferSize, // output buffer size
  933. DWORD nInBufferSize, // input buffer size
  934. DWORD nDefaultTimeOut, // time-out interval
  935. LPSECURITY_ATTRIBUTES lpSecurityAttributes // SD
  936. )
  937. {
  938. LPWSTR pwszName = ToUnicode(lpName);
  939. CheckSecurityAttributes(lpSecurityAttributes, L"CreateNamedPipe", L"lpSecurityAttributes", pwszName);
  940. if (pwszName) {
  941. free(pwszName);
  942. pwszName = NULL;
  943. }
  944. return ORIGINAL_API(CreateNamedPipeA)(lpName,
  945. dwOpenMode,
  946. dwPipeMode,
  947. nMaxInstances,
  948. nOutBufferSize,
  949. nInBufferSize,
  950. nDefaultTimeOut,
  951. lpSecurityAttributes);
  952. }
  953. HANDLE
  954. APIHOOK(CreateNamedPipeW)(
  955. LPCWSTR lpName, // pipe name
  956. DWORD dwOpenMode, // pipe open mode
  957. DWORD dwPipeMode, // pipe-specific modes
  958. DWORD nMaxInstances, // maximum number of instances
  959. DWORD nOutBufferSize, // output buffer size
  960. DWORD nInBufferSize, // input buffer size
  961. DWORD nDefaultTimeOut, // time-out interval
  962. LPSECURITY_ATTRIBUTES lpSecurityAttributes // SD
  963. )
  964. {
  965. CheckSecurityAttributes(lpSecurityAttributes, L"CreateNamedPipe", L"lpSecurityAttributes", lpName);
  966. return ORIGINAL_API(CreateNamedPipeW)(lpName,
  967. dwOpenMode,
  968. dwPipeMode,
  969. nMaxInstances,
  970. nOutBufferSize,
  971. nInBufferSize,
  972. nDefaultTimeOut,
  973. lpSecurityAttributes);
  974. }
  975. BOOL
  976. APIHOOK(CreatePipe)(
  977. PHANDLE hReadPipe, // read handle
  978. PHANDLE hWritePipe, // write handle
  979. LPSECURITY_ATTRIBUTES lpPipeAttributes, // security attributes
  980. DWORD nSize // pipe size
  981. )
  982. {
  983. CheckSecurityAttributes(lpPipeAttributes, L"CreatePipe", L"lpPipeAttributes", L"Unnamed pipe");
  984. return ORIGINAL_API(CreatePipe)(hReadPipe,
  985. hWritePipe,
  986. lpPipeAttributes,
  987. nSize);
  988. }
  989. HANDLE
  990. APIHOOK(CreateMutexA)(
  991. LPSECURITY_ATTRIBUTES lpMutexAttributes, // SD
  992. BOOL bInitialOwner, // initial owner
  993. LPCSTR lpName // object name
  994. )
  995. {
  996. LPWSTR pwszName = ToUnicode(lpName);
  997. CheckSecurityAttributes(lpMutexAttributes, L"CreateMutex", L"lpMutexAttributes", pwszName);
  998. if (pwszName) {
  999. free(pwszName);
  1000. pwszName = NULL;
  1001. }
  1002. return ORIGINAL_API(CreateMutexA)(lpMutexAttributes,
  1003. bInitialOwner,
  1004. lpName);
  1005. }
  1006. HANDLE
  1007. APIHOOK(CreateMutexW)(
  1008. LPSECURITY_ATTRIBUTES lpMutexAttributes, // SD
  1009. BOOL bInitialOwner, // initial owner
  1010. LPCWSTR lpName // object name
  1011. )
  1012. {
  1013. CheckSecurityAttributes(lpMutexAttributes, L"CreateMutex", L"lpMutexAttributes", lpName);
  1014. return ORIGINAL_API(CreateMutexW)(lpMutexAttributes,
  1015. bInitialOwner,
  1016. lpName);
  1017. }
  1018. HANDLE
  1019. APIHOOK(CreateSemaphoreA)(
  1020. LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, // SD
  1021. LONG lInitialCount, // initial count
  1022. LONG lMaximumCount, // maximum count
  1023. LPCSTR lpName // object name
  1024. )
  1025. {
  1026. LPWSTR pwszName = ToUnicode(lpName);
  1027. CheckSecurityAttributes(lpSemaphoreAttributes, L"CreateSemaphore", L"lpSemaphoreAttributes", pwszName);
  1028. if (pwszName) {
  1029. free(pwszName);
  1030. pwszName = NULL;
  1031. }
  1032. return ORIGINAL_API(CreateSemaphoreA)(lpSemaphoreAttributes,
  1033. lInitialCount,
  1034. lMaximumCount,
  1035. lpName);
  1036. }
  1037. HANDLE
  1038. APIHOOK(CreateSemaphoreW)(
  1039. LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, // SD
  1040. LONG lInitialCount, // initial count
  1041. LONG lMaximumCount, // maximum count
  1042. LPCWSTR lpName // object name
  1043. )
  1044. {
  1045. CheckSecurityAttributes(lpSemaphoreAttributes, L"CreateSemaphore", L"lpSemaphoreAttributes", lpName);
  1046. return ORIGINAL_API(CreateSemaphoreW)(lpSemaphoreAttributes,
  1047. lInitialCount,
  1048. lMaximumCount,
  1049. lpName);
  1050. }
  1051. HANDLE
  1052. APIHOOK(CreateWaitableTimerA)(
  1053. IN LPSECURITY_ATTRIBUTES lpTimerAttributes,
  1054. IN BOOL bManualReset,
  1055. IN LPCSTR lpTimerName
  1056. )
  1057. {
  1058. LPWSTR pwszName = ToUnicode(lpTimerName);
  1059. CheckSecurityAttributes(lpTimerAttributes, L"CreateWaitableTimer", L"lpTimerAttributes", pwszName);
  1060. if (pwszName) {
  1061. free(pwszName);
  1062. pwszName = NULL;
  1063. }
  1064. return ORIGINAL_API(CreateWaitableTimerA)(lpTimerAttributes,
  1065. bManualReset,
  1066. lpTimerName);
  1067. }
  1068. HANDLE
  1069. APIHOOK(CreateWaitableTimerW)(
  1070. IN LPSECURITY_ATTRIBUTES lpTimerAttributes,
  1071. IN BOOL bManualReset,
  1072. IN LPCWSTR lpTimerName
  1073. )
  1074. {
  1075. CheckSecurityAttributes(lpTimerAttributes, L"CreateWaitableTimer", L"lpTimerAttributes", lpTimerName);
  1076. return ORIGINAL_API(CreateWaitableTimerW)(lpTimerAttributes,
  1077. bManualReset,
  1078. lpTimerName);
  1079. }
  1080. #if 0
  1081. LONG
  1082. WINAPI
  1083. APIHOOK(ClusterRegCreateKey)(
  1084. HKEY hKey,
  1085. LPCWSTR lpszSubKey,
  1086. DWORD dwOptions,
  1087. REGSAM samDesired,
  1088. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  1089. PHKEY phkResult,
  1090. LPDWORD lpdwDisposition
  1091. )
  1092. {
  1093. CheckSecurityAttributes(lpSecurityAttributes, L"ClusterRegCreateKey", L"lpSecurityAttributes");
  1094. return ORIGINAL_API(ClusterRegCreateKey)(hKey,
  1095. lpszSubKey,
  1096. dwOptions,
  1097. samDesired,
  1098. lpSecurityAttributes,
  1099. phkResult,
  1100. lpdwDisposition);
  1101. }
  1102. DWORD
  1103. WINAPI
  1104. APIHOOK(CreateNtmsMediaPoolA)(
  1105. HANDLE hSession,
  1106. LPCSTR lpPoolName,
  1107. LPNTMS_GUID lpMediaType,
  1108. DWORD dwAction,
  1109. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  1110. LPNTMS_GUID lpPoolId // OUT
  1111. )
  1112. {
  1113. CheckSecurityAttributes(lpSecurityAttributes, L"CreateNtmsMediaPool", L"lpSecurityAttributes");
  1114. return ORIGINAL_API(CreateNtmsMediaPoolA)(hSession,
  1115. lpPoolName,
  1116. lpMediaType,
  1117. dwAction,
  1118. lpSecurityAttributes,
  1119. lpPoolId);
  1120. }
  1121. DWORD WINAPI
  1122. APIHOOK(CreateNtmsMediaPoolW)(
  1123. HANDLE hSession,
  1124. LPCWSTR lpPoolName,
  1125. LPNTMS_GUID lpMediaType,
  1126. DWORD dwAction,
  1127. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  1128. LPNTMS_GUID lpPoolId // OUT
  1129. )
  1130. {
  1131. CheckSecurityAttributes(lpSecurityAttributes, L"CreateNtmsMediaPool", L"lpSecurityAttributes");
  1132. return ORIGINAL_API(CreateNtmsMediaPoolW)(hSession,
  1133. lpPoolName,
  1134. lpMediaType,
  1135. dwAction,
  1136. lpSecurityAttributes,
  1137. lpPoolId);
  1138. }
  1139. #endif
  1140. SHIM_INFO_BEGIN()
  1141. SHIM_INFO_DESCRIPTION(AVS_SECURITYCHECKS_DESC)
  1142. SHIM_INFO_FRIENDLY_NAME(AVS_SECURITYCHECKS_FRIENDLY)
  1143. SHIM_INFO_FLAGS(0)
  1144. SHIM_INFO_GROUPS(0)
  1145. SHIM_INFO_VERSION(2, 3)
  1146. SHIM_INFO_INCLUDE_EXCLUDE("I:*")
  1147. SHIM_INFO_END()
  1148. /*++
  1149. Register hooked functions.
  1150. --*/
  1151. HOOK_BEGIN
  1152. if (fdwReason == DLL_PROCESS_ATTACH) {
  1153. DWORD dwSize;
  1154. InitWorldSid();
  1155. dwSize = GetSystemWindowsDirectoryW(g_wszWinDir, ARRAYSIZE(g_wszWinDir));
  1156. if (dwSize == 0 || dwSize > ARRAYSIZE(g_wszWinDir)) {
  1157. g_wszWinDir[0] = 0;
  1158. }
  1159. g_dwWinDirLen = wcslen(g_wszWinDir);
  1160. }
  1161. DUMP_VERIFIER_LOG_ENTRY(VLOG_SECURITYCHECKS_BADARGUMENTS,
  1162. AVS_SECURITYCHECKS_BADARGUMENTS,
  1163. AVS_SECURITYCHECKS_BADARGUMENTS_R,
  1164. AVS_SECURITYCHECKS_BADARGUMENTS_URL)
  1165. DUMP_VERIFIER_LOG_ENTRY(VLOG_SECURITYCHECKS_WINEXEC,
  1166. AVS_SECURITYCHECKS_WINEXEC,
  1167. AVS_SECURITYCHECKS_WINEXEC_R,
  1168. AVS_SECURITYCHECKS_WINEXEC_URL)
  1169. DUMP_VERIFIER_LOG_ENTRY(VLOG_SECURITYCHECKS_NULL_DACL,
  1170. AVS_SECURITYCHECKS_NULL_DACL,
  1171. AVS_SECURITYCHECKS_NULL_DACL_R,
  1172. AVS_SECURITYCHECKS_NULL_DACL_URL)
  1173. DUMP_VERIFIER_LOG_ENTRY(VLOG_SECURITYCHECKS_WORLDWRITE_DACL,
  1174. AVS_SECURITYCHECKS_WORLDWRITE_DACL,
  1175. AVS_SECURITYCHECKS_WORLDWRITE_DACL_R,
  1176. AVS_SECURITYCHECKS_WORLDWRITE_DACL_URL)
  1177. APIHOOK_ENTRY(KERNEL32.DLL, CreateProcessA)
  1178. APIHOOK_ENTRY(KERNEL32.DLL, CreateProcessW)
  1179. APIHOOK_ENTRY(ADVAPI32.DLL, CreateProcessAsUserA)
  1180. APIHOOK_ENTRY(ADVAPI32.DLL, CreateProcessAsUserW)
  1181. APIHOOK_ENTRY(KERNEL32.DLL, WinExec)
  1182. APIHOOK_ENTRY(KERNEL32.DLL, CreateFileA)
  1183. APIHOOK_ENTRY(KERNEL32.DLL, CreateFileW)
  1184. APIHOOK_ENTRY(USER32.DLL, CreateDesktopA)
  1185. APIHOOK_ENTRY(USER32.DLL, CreateDesktopW)
  1186. APIHOOK_ENTRY(USER32.DLL, CreateWindowStationA)
  1187. APIHOOK_ENTRY(USER32.DLL, CreateWindowStationW)
  1188. APIHOOK_ENTRY(ADVAPI32.DLL, RegCreateKeyExA)
  1189. APIHOOK_ENTRY(ADVAPI32.DLL, RegCreateKeyExW)
  1190. APIHOOK_ENTRY(ADVAPI32.DLL, RegSaveKeyA)
  1191. APIHOOK_ENTRY(ADVAPI32.DLL, RegSaveKeyW)
  1192. APIHOOK_ENTRY(ADVAPI32.DLL, RegSaveKeyExA)
  1193. APIHOOK_ENTRY(ADVAPI32.DLL, RegSaveKeyExW)
  1194. APIHOOK_ENTRY(KERNEL32.DLL, CreateFileMappingA)
  1195. APIHOOK_ENTRY(KERNEL32.DLL, CreateFileMappingW)
  1196. APIHOOK_ENTRY(KERNEL32.DLL, CreateJobObjectA)
  1197. APIHOOK_ENTRY(KERNEL32.DLL, CreateJobObjectW)
  1198. APIHOOK_ENTRY(KERNEL32.DLL, CreateThread)
  1199. APIHOOK_ENTRY(KERNEL32.DLL, CreateRemoteThread)
  1200. APIHOOK_ENTRY(KERNEL32.DLL, CreateDirectoryA)
  1201. APIHOOK_ENTRY(KERNEL32.DLL, CreateDirectoryW)
  1202. APIHOOK_ENTRY(KERNEL32.DLL, CreateDirectoryExA)
  1203. APIHOOK_ENTRY(KERNEL32.DLL, CreateDirectoryExW)
  1204. APIHOOK_ENTRY(KERNEL32.DLL, CreateHardLinkA)
  1205. APIHOOK_ENTRY(KERNEL32.DLL, CreateHardLinkW)
  1206. APIHOOK_ENTRY(KERNEL32.DLL, CreateMailslotA)
  1207. APIHOOK_ENTRY(KERNEL32.DLL, CreateMailslotW)
  1208. APIHOOK_ENTRY(KERNEL32.DLL, CreateNamedPipeA)
  1209. APIHOOK_ENTRY(KERNEL32.DLL, CreateNamedPipeW)
  1210. APIHOOK_ENTRY(KERNEL32.DLL, CreatePipe)
  1211. APIHOOK_ENTRY(KERNEL32.DLL, CreateMutexA)
  1212. APIHOOK_ENTRY(KERNEL32.DLL, CreateMutexW)
  1213. APIHOOK_ENTRY(KERNEL32.DLL, CreateSemaphoreA)
  1214. APIHOOK_ENTRY(KERNEL32.DLL, CreateSemaphoreW)
  1215. APIHOOK_ENTRY(KERNEL32.DLL, CreateWaitableTimerA)
  1216. APIHOOK_ENTRY(KERNEL32.DLL, CreateWaitableTimerW)
  1217. HOOK_END
  1218. IMPLEMENT_SHIM_END