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.

881 lines
19 KiB

  1. #include "acBrowser.h"
  2. #include <wchar.h>
  3. #include <commctrl.h>
  4. #include <psapi.h>
  5. #include "shimdb.h"
  6. #define SHIM_LOG_FILE "shimlog.txt"
  7. #define Alloc(cb) \
  8. HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cb)
  9. #define Free(p) \
  10. HeapFree(GetProcessHeap(), 0, p)
  11. PDBENTRY g_pEntries;
  12. PFIX g_pFixes;
  13. #define MAX_DATA_SIZE 1024
  14. #define MAX_NAME 256
  15. #define MAX_DESCRIPTION 1024
  16. WCHAR g_wszData[MAX_DATA_SIZE];
  17. char g_szName[MAX_NAME];
  18. char g_szDescription[MAX_DESCRIPTION];
  19. #define APPCOMPAT_DISABLED 0x03
  20. //
  21. // REGISTRY STUFF. Needs to be revised
  22. //
  23. #define APPCOMPAT_KEY "Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags"
  24. BOOL
  25. CheckRegistry(
  26. HKEY hkeyRoot,
  27. char* pszGUID
  28. )
  29. {
  30. LONG status;
  31. HKEY hkey = NULL;
  32. BOOL bDisabled = FALSE;
  33. DWORD dwFlags;
  34. DWORD type;
  35. DWORD cbSize = sizeof(DWORD);
  36. status = RegOpenKey(hkeyRoot, APPCOMPAT_KEY, &hkey);
  37. if (status != ERROR_SUCCESS) {
  38. return FALSE;
  39. }
  40. status = RegQueryValueEx(hkey, pszGUID, NULL, &type, (LPBYTE)&dwFlags, &cbSize);
  41. if (status == ERROR_SUCCESS && type == REG_DWORD && (dwFlags & APPCOMPAT_DISABLED)) {
  42. bDisabled = TRUE;
  43. }
  44. RegCloseKey(hkey);
  45. return bDisabled;
  46. }
  47. BOOL
  48. WriteRegistry(
  49. HKEY hkeyRoot,
  50. char* pszKeyName
  51. )
  52. {
  53. LONG status;
  54. HKEY hkey;
  55. DWORD dwValue = 0x03;
  56. DWORD dwDisposition = 0;
  57. BOOL bDisabled = FALSE;
  58. status = RegCreateKeyEx(hkeyRoot,
  59. APPCOMPAT_KEY,
  60. 0,
  61. NULL,
  62. REG_OPTION_NON_VOLATILE,
  63. KEY_ALL_ACCESS,
  64. NULL,
  65. &hkey,
  66. &dwDisposition);
  67. if (status != ERROR_SUCCESS) {
  68. LogMsg("Failed to set the value for \"%s\"\n", pszKeyName);
  69. return FALSE;
  70. }
  71. status = RegSetValueEx(hkey, pszKeyName, 0, REG_DWORD, (LPBYTE)&dwValue, sizeof(DWORD));
  72. RegCloseKey(hkey);
  73. if (status != ERROR_SUCCESS) {
  74. LogMsg("Failed to set the value for \"%s\"\n", pszKeyName);
  75. return FALSE;
  76. }
  77. return TRUE;
  78. }
  79. BOOL
  80. DeleteRegistry(
  81. HKEY hkeyRoot,
  82. char* pszKeyName
  83. )
  84. {
  85. LONG status;
  86. HKEY hkey = NULL;
  87. DWORD dwValue = 0;
  88. DWORD dwDisposition = 0;
  89. BOOL bDisabled = FALSE;
  90. status = RegOpenKey(hkeyRoot, APPCOMPAT_KEY, &hkey);
  91. if (status != ERROR_SUCCESS) {
  92. return TRUE;
  93. }
  94. status = RegDeleteValue(hkey, pszKeyName);
  95. RegCloseKey(hkey);
  96. return TRUE;
  97. }
  98. typedef void (*PFNFLUSHCACHE)(HWND, HINSTANCE, LPSTR, int);
  99. void
  100. FlushTheCache(
  101. void
  102. )
  103. {
  104. HINSTANCE hmod;
  105. PFNFLUSHCACHE pfnFlushCache;
  106. char szPath[MAX_PATH];
  107. GetSystemDirectory(szPath, MAX_PATH);
  108. lstrcat(szPath, "\\apphelp.dll");
  109. hmod = LoadLibrary(szPath);
  110. if (hmod != NULL) {
  111. pfnFlushCache = (PFNFLUSHCACHE)GetProcAddress(hmod, "ShimFlushCache");
  112. if (pfnFlushCache != NULL) {
  113. (*pfnFlushCache)(0, 0, NULL, 0);
  114. }
  115. }
  116. }
  117. void
  118. UpdateFixStatus(
  119. char* pszGUID,
  120. BOOL bPerUser,
  121. BOOL bPerMachine
  122. )
  123. {
  124. if (bPerUser) {
  125. WriteRegistry(HKEY_CURRENT_USER, pszGUID);
  126. } else {
  127. DeleteRegistry(HKEY_CURRENT_USER, pszGUID);
  128. }
  129. if (bPerMachine) {
  130. WriteRegistry(HKEY_LOCAL_MACHINE, pszGUID);
  131. } else {
  132. DeleteRegistry(HKEY_LOCAL_MACHINE, pszGUID);
  133. }
  134. FlushTheCache();
  135. }
  136. PFIX
  137. AllocFix(
  138. char* pszFixName,
  139. char* pszFixDescription,
  140. FIXTYPE type
  141. )
  142. {
  143. PFIX pFix;
  144. char* pszAlloc;
  145. pFix = (PFIX)Alloc(sizeof(FIX));
  146. if (pFix == NULL) {
  147. LogMsg("Cannot allocate %d bytes\n", sizeof(FIX));
  148. return NULL;
  149. }
  150. if (pszFixName == NULL || *pszFixName == 0) {
  151. pFix->pszName = NULL;
  152. } else {
  153. pszAlloc = (char*)Alloc(lstrlen(pszFixName) + 1);
  154. pFix->pszName = pszAlloc;
  155. if (pszAlloc != NULL) {
  156. lstrcpy(pszAlloc, pszFixName);
  157. } else {
  158. LogMsg("Cannot allocate %d bytes\n", lstrlen(pszFixName) + 1);
  159. goto Error;
  160. }
  161. }
  162. if (pszFixDescription == NULL || *pszFixDescription == 0) {
  163. pFix->pszDescription = NULL;
  164. } else {
  165. pszAlloc = (char*)Alloc(lstrlen(pszFixDescription) + 1);
  166. pFix->pszDescription = pszAlloc;
  167. if (pszAlloc != NULL) {
  168. lstrcpy(pszAlloc, pszFixDescription);
  169. } else {
  170. LogMsg("Cannot allocate %d bytes\n", lstrlen(pszFixDescription) + 1);
  171. goto Error;
  172. }
  173. }
  174. pFix->fixType = type;
  175. pFix->pNext = NULL;
  176. return pFix;
  177. Error:
  178. if (pFix->pszName != NULL) {
  179. Free(pFix->pszName);
  180. }
  181. if (pFix->pszDescription != NULL) {
  182. Free(pFix->pszDescription);
  183. }
  184. Free(pFix);
  185. return NULL;
  186. }
  187. void
  188. ReadFix(
  189. PDB pdb,
  190. TAGID tiFix,
  191. FIXTYPE type
  192. )
  193. {
  194. TAGID tiInfo;
  195. TAG tWhich;
  196. PFIX pFix;
  197. ULONGLONG ullUser = 0;
  198. ULONGLONG ullKernel = 0;
  199. tiInfo = SdbGetFirstChild(pdb, tiFix);
  200. g_szName[0] = 0;
  201. g_szDescription[0] = 0;
  202. while (tiInfo != 0) {
  203. tWhich = SdbGetTagFromTagID(pdb, tiInfo);
  204. switch (tWhich) {
  205. case TAG_NAME:
  206. if (SdbReadStringTag(pdb, tiInfo, g_wszData, MAX_NAME * sizeof(WCHAR))) {
  207. wsprintf(g_szName, "%ws", g_wszData);
  208. }
  209. break;
  210. case TAG_DESCRIPTION:
  211. if (SdbReadStringTag(pdb, tiInfo, g_wszData, MAX_DESCRIPTION * sizeof(WCHAR))) {
  212. wsprintf(g_szDescription, "%ws", g_wszData);
  213. }
  214. break;
  215. case TAG_FLAG_MASK_USER:
  216. ullUser = SdbReadQWORDTag(pdb, tiInfo, 0);
  217. break;
  218. case TAG_FLAG_MASK_KERNEL:
  219. ullKernel = SdbReadQWORDTag(pdb, tiInfo, 0);
  220. break;
  221. default:
  222. break;
  223. }
  224. tiInfo = SdbGetNextChild(pdb, tiFix, tiInfo);
  225. }
  226. pFix = AllocFix(g_szName, g_szDescription, type);
  227. if (pFix != NULL) {
  228. if (type == FIX_FLAG) {
  229. if (ullKernel == 0) {
  230. pFix->flagType = FLAG_USER;
  231. pFix->ullMask = ullUser;
  232. } else {
  233. pFix->flagType = FLAG_KERNEL;
  234. pFix->ullMask = ullKernel;
  235. }
  236. }
  237. pFix->pNext = g_pFixes;
  238. g_pFixes = pFix;
  239. }
  240. }
  241. void
  242. ReadFixes(
  243. PDB pdb,
  244. TAGID tiDatabase,
  245. TAGID tiLibrary
  246. )
  247. {
  248. TAGID tiFix;
  249. tiFix = SdbFindFirstTag(pdb, tiLibrary, TAG_SHIM);
  250. while (tiFix != 0) {
  251. ReadFix(pdb, tiFix, FIX_SHIM);
  252. tiFix = SdbFindNextTag(pdb, tiLibrary, tiFix);
  253. }
  254. tiFix = SdbFindFirstTag(pdb, tiLibrary, TAG_PATCH);
  255. while (tiFix != 0) {
  256. ReadFix(pdb, tiFix, FIX_PATCH);
  257. tiFix = SdbFindNextTag(pdb, tiLibrary, tiFix);
  258. }
  259. tiFix = SdbFindFirstTag(pdb, tiLibrary, TAG_FLAG);
  260. while (tiFix != 0) {
  261. ReadFix(pdb, tiFix, FIX_FLAG);
  262. tiFix = SdbFindNextTag(pdb, tiLibrary, tiFix);
  263. }
  264. //
  265. // The LAYERs are under the DATABASE tag instead of LIBRARY :-(
  266. //
  267. tiFix = SdbFindFirstTag(pdb, tiDatabase, TAG_LAYER);
  268. while (tiFix != 0) {
  269. ReadFix(pdb, tiFix, FIX_LAYER);
  270. tiFix = SdbFindNextTag(pdb, tiDatabase, tiFix);
  271. }
  272. }
  273. PFIX
  274. FindFix(
  275. char* pszFixName,
  276. FIXTYPE fixType
  277. )
  278. {
  279. PFIX pFix = g_pFixes;
  280. while (pFix != NULL) {
  281. if (pFix->pszName && lstrcmpi(pszFixName, pFix->pszName) == 0) {
  282. return pFix;
  283. }
  284. pFix = pFix->pNext;
  285. }
  286. return NULL;
  287. }
  288. PFIX
  289. FindFlagFix(
  290. ULONGLONG ullMask,
  291. FLAGTYPE flagType
  292. )
  293. {
  294. PFIX pFix = g_pFixes;
  295. while (pFix != NULL) {
  296. if (pFix->fixType == FIX_FLAG &&
  297. pFix->flagType == flagType &&
  298. pFix->ullMask == ullMask) {
  299. return pFix;
  300. }
  301. pFix = pFix->pNext;
  302. }
  303. return NULL;
  304. }
  305. BOOL
  306. AddFlags(
  307. PDB pdb,
  308. TAGID tiFlags,
  309. PDBENTRY pEntry,
  310. FLAGTYPE flagType
  311. )
  312. {
  313. ULONGLONG ullFlags;
  314. ULONGLONG ullMask = 1;
  315. PFIX pFix;
  316. PFIXLIST pFixList;
  317. int i;
  318. ullFlags = SdbReadQWORDTag(pdb, tiFlags, 0);
  319. for (i = 0; i < sizeof(ULONGLONG) * 8; i++) {
  320. if (ullFlags & ullMask) {
  321. pFix = FindFlagFix(ullMask, flagType);
  322. if (pFix == NULL) {
  323. LogMsg("Cannot find flag fix ref\n");
  324. }
  325. pFixList = (PFIXLIST)Alloc(sizeof(FIXLIST));
  326. if (pFixList == NULL) {
  327. LogMsg("Cannot allocate %d bytes\n", sizeof(FIXLIST));
  328. return FALSE;
  329. }
  330. pFixList->pFix = pFix;
  331. pFixList->pNext = pEntry->pFirstFlag;
  332. pEntry->pFirstFlag = pFixList;
  333. }
  334. ullMask <<= 1;
  335. }
  336. return TRUE;
  337. }
  338. BOOL
  339. AddFix(
  340. PDB pdb,
  341. TAGID tiFix,
  342. PDBENTRY pEntry,
  343. FIXTYPE fixType
  344. )
  345. {
  346. TAGID tiName;
  347. char szFixName[MAX_NAME];
  348. PFIX pFix;
  349. PFIXLIST* ppHead;
  350. PFIXLIST pFixList;
  351. tiName = SdbFindFirstTag(pdb, tiFix, TAG_NAME);
  352. if (!SdbReadStringTag(pdb, tiName, g_wszData, MAX_NAME * sizeof(WCHAR))) {
  353. LogMsg("Cannot read the name of the fix\n");
  354. return FALSE;
  355. }
  356. wsprintf(szFixName, "%ws", g_wszData);
  357. pFix = FindFix(szFixName, fixType);
  358. if (pFix == NULL) {
  359. LogMsg("Cannot find fix ref for: \"%s\" type %d\n", szFixName, fixType);
  360. return FALSE;
  361. }
  362. switch (fixType) {
  363. case FIX_SHIM:
  364. ppHead = &pEntry->pFirstShim;
  365. break;
  366. case FIX_PATCH:
  367. ppHead = &pEntry->pFirstPatch;
  368. break;
  369. case FIX_FLAG:
  370. ppHead = &pEntry->pFirstFlag;
  371. break;
  372. case FIX_LAYER:
  373. ppHead = &pEntry->pFirstLayer;
  374. break;
  375. }
  376. pFixList = (PFIXLIST)Alloc(sizeof(FIXLIST));
  377. if (pFixList == NULL) {
  378. LogMsg("Cannot allocate %d bytes\n", sizeof(FIXLIST));
  379. return FALSE;
  380. }
  381. pFixList->pFix = pFix;
  382. pFixList->pNext = *ppHead;
  383. *ppHead = pFixList;
  384. return TRUE;
  385. }
  386. void
  387. AddAttr(
  388. char* pszAttr,
  389. PMATCHINGFILE pMatch
  390. )
  391. {
  392. PATTRIBUTE pAttr;
  393. pAttr = (PATTRIBUTE)Alloc(sizeof(ATTRIBUTE));
  394. if (pAttr) {
  395. pAttr->pszText = (char*)Alloc(lstrlen(pszAttr) + 1);
  396. if (pAttr->pszText) {
  397. lstrcpy(pAttr->pszText, pszAttr);
  398. pAttr->pNext = pMatch->pFirstAttribute;
  399. pMatch->pFirstAttribute = pAttr;
  400. } else {
  401. Free(pAttr);
  402. }
  403. }
  404. }
  405. VOID
  406. PrintBinVer(
  407. char* pszText,
  408. LARGE_INTEGER* pliBinVer
  409. )
  410. {
  411. wsprintf(pszText, "%d", HIWORD(pliBinVer->HighPart));
  412. pszText += lstrlen(pszText);
  413. if (LOWORD(pliBinVer->HighPart) == 0xFFFF) {
  414. return;
  415. }
  416. wsprintf(pszText, ".%d", LOWORD(pliBinVer->HighPart));
  417. pszText += lstrlen(pszText);
  418. if (HIWORD(pliBinVer->LowPart) == 0xFFFF) {
  419. return;
  420. }
  421. wsprintf(pszText, ".%d", HIWORD(pliBinVer->LowPart));
  422. pszText += lstrlen(pszText);
  423. if (LOWORD(pliBinVer->LowPart) == 0xFFFF) {
  424. return;
  425. }
  426. wsprintf(pszText, ".%d", LOWORD(pliBinVer->LowPart));
  427. pszText += lstrlen(pszText);
  428. }
  429. BOOL
  430. AddMatchingFile(
  431. PDB pdb,
  432. TAGID tiMatch,
  433. PDBENTRY pEntry
  434. )
  435. {
  436. TAGID tiMatchInfo;
  437. TAG tWhich;
  438. DWORD dw;
  439. LARGE_INTEGER li;
  440. PMATCHINGFILE pMatch;
  441. char szStr[128];
  442. char szAttr[256];
  443. pMatch = (PMATCHINGFILE)Alloc(sizeof(MATCHINGFILE));
  444. if (pMatch == NULL) {
  445. return FALSE;
  446. }
  447. tiMatchInfo = SdbGetFirstChild(pdb, tiMatch);
  448. while (tiMatchInfo != 0) {
  449. tWhich = SdbGetTagFromTagID(pdb, tiMatchInfo);
  450. switch (tWhich) {
  451. case TAG_NAME:
  452. if (SdbReadStringTag(pdb, tiMatchInfo, g_wszData, MAX_NAME * sizeof(WCHAR))) {
  453. wsprintf(szAttr, "%ws", g_wszData);
  454. pMatch->pszName = (char*)Alloc(lstrlen(szAttr) + 1);
  455. if (pMatch->pszName) {
  456. lstrcpy(pMatch->pszName, szAttr);
  457. }
  458. }
  459. break;
  460. case TAG_SIZE:
  461. dw = SdbReadDWORDTag(pdb, tiMatchInfo, 0);
  462. if (dw != 0) {
  463. wsprintf(szAttr, "File Size: 0x%X", dw);
  464. AddAttr(szAttr, pMatch);
  465. }
  466. break;
  467. case TAG_CHECKSUM:
  468. dw = SdbReadDWORDTag(pdb, tiMatchInfo, 0);
  469. if (dw != 0) {
  470. wsprintf(szAttr, "File CheckSum: 0x%X", dw);
  471. AddAttr(szAttr, pMatch);
  472. }
  473. break;
  474. case TAG_COMPANY_NAME:
  475. if (SdbReadStringTag(pdb, tiMatchInfo, g_wszData, MAX_DATA_SIZE * sizeof(WCHAR))) {
  476. wsprintf(szStr, "%ws", g_wszData);
  477. wsprintf(szAttr, "Company Name: %s", szStr);
  478. AddAttr(szAttr, pMatch);
  479. }
  480. break;
  481. case TAG_PRODUCT_NAME:
  482. if (SdbReadStringTag(pdb, tiMatchInfo, g_wszData, MAX_DATA_SIZE * sizeof(WCHAR))) {
  483. wsprintf(szStr, "%ws", g_wszData);
  484. wsprintf(szAttr, "Product Name: %s", szStr);
  485. AddAttr(szAttr, pMatch);
  486. }
  487. break;
  488. case TAG_PRODUCT_VERSION:
  489. if (SdbReadStringTag(pdb, tiMatchInfo, g_wszData, MAX_DATA_SIZE * sizeof(WCHAR))) {
  490. wsprintf(szStr, "%ws", g_wszData);
  491. wsprintf(szAttr, "Product Version: %s", szStr);
  492. AddAttr(szAttr, pMatch);
  493. }
  494. break;
  495. case TAG_FILE_DESCRIPTION:
  496. if (SdbReadStringTag(pdb, tiMatchInfo, g_wszData, MAX_DATA_SIZE * sizeof(WCHAR))) {
  497. wsprintf(szStr, "%ws", g_wszData);
  498. wsprintf(szAttr, "File Description: %s", szStr);
  499. AddAttr(szAttr, pMatch);
  500. }
  501. break;
  502. case TAG_BIN_FILE_VERSION:
  503. li.QuadPart = SdbReadQWORDTag(pdb, tiMatchInfo, 0);
  504. if (li.HighPart != 0 || li.LowPart != 0) {
  505. PrintBinVer(szStr, &li);
  506. wsprintf(szAttr, "Binary File Version: %s", szStr);
  507. AddAttr(szAttr, pMatch);
  508. }
  509. break;
  510. case TAG_BIN_PRODUCT_VERSION:
  511. li.QuadPart = SdbReadQWORDTag(pdb, tiMatchInfo, 0);
  512. if (li.HighPart != 0 || li.LowPart != 0) {
  513. PrintBinVer(szStr, &li);
  514. wsprintf(szAttr, "Binary Product Version: %s", szStr);
  515. AddAttr(szAttr, pMatch);
  516. }
  517. break;
  518. default:
  519. break;
  520. }
  521. tiMatchInfo = SdbGetNextChild(pdb, tiMatch, tiMatchInfo);
  522. }
  523. pMatch->pNext = pEntry->pFirstMatchingFile;
  524. pEntry->pFirstMatchingFile = pMatch;
  525. (pEntry->nMatchingFiles)++;
  526. return TRUE;
  527. }
  528. void
  529. AddEntry(
  530. PDB pdb,
  531. TAGID tiExe
  532. )
  533. {
  534. TAGID tiExeInfo;
  535. TAGID tiSeverity, tiHelpId;
  536. char szStr[MAX_NAME];
  537. TAG tWhich;
  538. PDBENTRY pEntry;
  539. tiExeInfo = SdbGetFirstChild(pdb, tiExe);
  540. pEntry = (PDBENTRY)Alloc(sizeof(DBENTRY));
  541. if (pEntry == NULL) {
  542. LogMsg("Cannot allocate %d bytes\n", sizeof(DBENTRY));
  543. return;
  544. }
  545. pEntry->pNext = g_pEntries;
  546. g_pEntries = pEntry;
  547. while (tiExeInfo != 0) {
  548. tWhich = SdbGetTagFromTagID(pdb, tiExeInfo);
  549. switch (tWhich) {
  550. case TAG_NAME:
  551. if (SdbReadStringTag(pdb, tiExeInfo, g_wszData, MAX_NAME * sizeof(WCHAR))) {
  552. wsprintf(szStr, "%ws", g_wszData);
  553. pEntry->pszExeName = (char*)Alloc(lstrlen(szStr) + 1);
  554. if (pEntry->pszExeName) {
  555. lstrcpy(pEntry->pszExeName, szStr);
  556. }
  557. }
  558. break;
  559. case TAG_APP_NAME:
  560. if (SdbReadStringTag(pdb, tiExeInfo, g_wszData, MAX_NAME * sizeof(WCHAR))) {
  561. wsprintf(szStr, "%ws", g_wszData);
  562. pEntry->pszAppName = (char*)Alloc(lstrlen(szStr) + 1);
  563. if (pEntry->pszAppName) {
  564. lstrcpy(pEntry->pszAppName, szStr);
  565. }
  566. }
  567. break;
  568. case TAG_MATCHING_FILE:
  569. AddMatchingFile(pdb, tiExeInfo, pEntry);
  570. break;
  571. case TAG_APPHELP:
  572. pEntry->appHelp.bPresent = TRUE;
  573. tiSeverity = SdbFindFirstTag(pdb, tiExeInfo, TAG_PROBLEMSEVERITY);
  574. pEntry->appHelp.severity = (SEVERITY)SdbReadDWORDTag(pdb, tiSeverity, 0);
  575. tiHelpId = SdbFindFirstTag(pdb, tiExeInfo, TAG_HTMLHELPID);
  576. pEntry->appHelp.htmlHelpId = SdbReadDWORDTag(pdb, tiHelpId, 0);
  577. break;
  578. case TAG_SHIM_REF:
  579. AddFix(pdb, tiExeInfo, pEntry, FIX_SHIM);
  580. break;
  581. case TAG_PATCH_REF:
  582. AddFix(pdb, tiExeInfo, pEntry, FIX_PATCH);
  583. break;
  584. case TAG_LAYER:
  585. AddFix(pdb, tiExeInfo, pEntry, FIX_LAYER);
  586. break;
  587. case TAG_FLAG_MASK_USER:
  588. AddFlags(pdb, tiExeInfo, pEntry, FLAG_USER);
  589. break;
  590. case TAG_FLAG_MASK_KERNEL:
  591. AddFlags(pdb, tiExeInfo, pEntry, FLAG_KERNEL);
  592. break;
  593. case TAG_EXE_ID:
  594. {
  595. GUID guid;
  596. PVOID p;
  597. p = SdbGetBinaryTagData(pdb, tiExeInfo);
  598. if (p != NULL) {
  599. memcpy(&guid, p, sizeof(GUID));
  600. wsprintf(pEntry->szGUID,
  601. "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
  602. guid.Data1,
  603. guid.Data2,
  604. guid.Data3,
  605. guid.Data4[0],
  606. guid.Data4[1],
  607. guid.Data4[2],
  608. guid.Data4[3],
  609. guid.Data4[4],
  610. guid.Data4[5],
  611. guid.Data4[6],
  612. guid.Data4[7]);
  613. }
  614. break;
  615. }
  616. default:
  617. break;
  618. }
  619. tiExeInfo = SdbGetNextChild(pdb, tiExe, tiExeInfo);
  620. }
  621. pEntry->bDisablePerMachine = CheckRegistry(HKEY_LOCAL_MACHINE, pEntry->szGUID);
  622. pEntry->bDisablePerUser = CheckRegistry(HKEY_CURRENT_USER, pEntry->szGUID);
  623. }
  624. PDBENTRY
  625. GetDatabaseEntries(
  626. void
  627. )
  628. {
  629. WCHAR wszShimDB[MAX_PATH] = L"";
  630. PDB pdb;
  631. TAGID tiDatabase, tiLibrary, tiExe;
  632. GetSystemWindowsDirectoryW(wszShimDB, MAX_PATH);
  633. wcscat(wszShimDB, L"\\AppPatch\\sysmain.sdb");
  634. //
  635. // Open sysmain.sdb shim database
  636. //
  637. pdb = SdbOpenDatabase(wszShimDB, DOS_PATH);
  638. if (pdb == NULL) {
  639. LogMsg("Cannot open shim DB \"%ws\"\n", wszShimDB);
  640. goto Cleanup;
  641. }
  642. tiDatabase = SdbFindFirstTag(pdb, TAGID_ROOT, TAG_DATABASE);
  643. if (tiDatabase == 0) {
  644. LogMsg("Cannot find TAG_DATABASE\n");
  645. goto Cleanup;
  646. }
  647. tiLibrary = SdbFindFirstTag(pdb, tiDatabase, TAG_LIBRARY);
  648. if (tiLibrary == 0) {
  649. LogMsg("Cannot find TAG_LIBRARY\n");
  650. goto Cleanup;
  651. }
  652. ReadFixes(pdb, tiDatabase, tiLibrary);
  653. //
  654. // Loop through the EXEs.
  655. //
  656. tiExe = SdbFindFirstTag(pdb, tiDatabase, TAG_EXE);
  657. while (tiExe != 0) {
  658. AddEntry(pdb, tiExe);
  659. tiExe = SdbFindNextTag(pdb, tiDatabase, tiExe);
  660. }
  661. Cleanup:
  662. if (pdb != NULL) {
  663. SdbCloseDatabase(pdb);
  664. }
  665. return g_pEntries;
  666. }