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.

972 lines
39 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. etm.c
  5. Abstract:
  6. Implements the code for the ETM part of the script module
  7. Author:
  8. Calin Negreanu (calinn) 13-Sep-2000
  9. Revision History:
  10. <alias> <date> <comments>
  11. --*/
  12. //
  13. // Includes
  14. //
  15. #include "pch.h"
  16. #include "v1p.h"
  17. #define DBG_V1 "v1"
  18. //
  19. // Strings
  20. //
  21. // None
  22. //
  23. // Constants
  24. //
  25. // None
  26. //
  27. // Macros
  28. //
  29. // None
  30. //
  31. // Types
  32. //
  33. // None
  34. //
  35. // Globals
  36. //
  37. HASHTABLE g_ObjectsTable;
  38. //
  39. // Macro expansion list
  40. //
  41. // None
  42. //
  43. // Private function prototypes
  44. //
  45. BOOL
  46. pAddObjectToTable (
  47. IN MIG_OBJECTTYPEID ObjectTypeId,
  48. IN MIG_OBJECTSTRINGHANDLE ObjectName,
  49. IN PMIG_CONTENT ObjectContent
  50. );
  51. //
  52. // Macro expansion definition
  53. //
  54. // None
  55. //
  56. // Code
  57. //
  58. #define S_LOCATIONS TEXT("HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Telephony\\Locations")
  59. BOOL
  60. pTranslateLocations (
  61. VOID
  62. )
  63. {
  64. INFSTRUCT context = INITINFSTRUCT_PMHANDLE;
  65. HINF hInf = NULL;
  66. TCHAR windir [MAX_PATH] = TEXT("");
  67. TCHAR locationStr [] = TEXT("Location9999999999");
  68. PCTSTR infPath = NULL;
  69. INT totalLocations = 0;
  70. INT currentLocation = 0;
  71. INT currLocInt = 0;
  72. PCTSTR currLocStr = NULL;
  73. PCTSTR currLocReg = NULL;
  74. MIG_OBJECTTYPEID objectTypeId;
  75. MIG_CONTENT objectContent;
  76. MIG_OBJECTSTRINGHANDLE objectName;
  77. GetWindowsDirectory (windir, MAX_PATH);
  78. infPath = JoinPaths (windir, TEXT("TELEPHON.INI"));
  79. if (infPath) {
  80. hInf = InfOpenInfFile (infPath);
  81. if (hInf != INVALID_HANDLE_VALUE) {
  82. if (InfFindFirstLine (hInf, TEXT("Locations"), TEXT("Locations"), &context)) {
  83. if (InfGetIntField (&context, 1, &totalLocations)) {
  84. if (totalLocations > 0) {
  85. objectTypeId = MIG_REGISTRY_TYPE;
  86. ZeroMemory (&objectContent, sizeof (MIG_CONTENT));
  87. objectContent.ObjectTypeId = objectTypeId;
  88. objectContent.ContentInFile = FALSE;
  89. objectName = IsmCreateObjectHandle (S_LOCATIONS, TEXT("DisableCallWaiting"));
  90. objectContent.Details.DetailsData = IsmGetMemory (sizeof (DWORD));
  91. if (objectContent.Details.DetailsData) {
  92. objectContent.Details.DetailsSize = sizeof (DWORD);
  93. *((PDWORD)objectContent.Details.DetailsData) = REG_BINARY;
  94. objectContent.MemoryContent.ContentBytes = IsmGetMemory (sizeof (DWORD));
  95. if (objectContent.MemoryContent.ContentBytes) {
  96. objectContent.MemoryContent.ContentSize = sizeof (DWORD);
  97. *((PDWORD)objectContent.MemoryContent.ContentBytes) = 3;
  98. pAddObjectToTable (objectTypeId, objectName, &objectContent);
  99. }
  100. }
  101. objectName = IsmCreateObjectHandle (S_LOCATIONS, TEXT("DisableCallWaiting0"));
  102. objectContent.Details.DetailsData = IsmGetMemory (sizeof (DWORD));
  103. if (objectContent.Details.DetailsData) {
  104. objectContent.Details.DetailsSize = sizeof (DWORD);
  105. *((PDWORD)objectContent.Details.DetailsData) = REG_SZ;
  106. objectContent.MemoryContent.ContentBytes = IsmGetMemory (SizeOfString (TEXT("*70,")));
  107. if (objectContent.MemoryContent.ContentBytes) {
  108. objectContent.MemoryContent.ContentSize = SizeOfString (TEXT("*70,"));
  109. CopyMemory ((PTSTR)objectContent.MemoryContent.ContentBytes, TEXT("*70,"), objectContent.MemoryContent.ContentSize);
  110. pAddObjectToTable (objectTypeId, objectName, &objectContent);
  111. }
  112. }
  113. objectName = IsmCreateObjectHandle (S_LOCATIONS, TEXT("DisableCallWaiting1"));
  114. objectContent.Details.DetailsData = IsmGetMemory (sizeof (DWORD));
  115. if (objectContent.Details.DetailsData) {
  116. objectContent.Details.DetailsSize = sizeof (DWORD);
  117. *((PDWORD)objectContent.Details.DetailsData) = REG_SZ;
  118. objectContent.MemoryContent.ContentBytes = IsmGetMemory (SizeOfString (TEXT("70#,")));
  119. if (objectContent.MemoryContent.ContentBytes) {
  120. objectContent.MemoryContent.ContentSize = SizeOfString (TEXT("70#,"));
  121. CopyMemory ((PTSTR)objectContent.MemoryContent.ContentBytes, TEXT("70#,"), objectContent.MemoryContent.ContentSize);
  122. pAddObjectToTable (objectTypeId, objectName, &objectContent);
  123. }
  124. }
  125. objectName = IsmCreateObjectHandle (S_LOCATIONS, TEXT("DisableCallWaiting2"));
  126. objectContent.Details.DetailsData = IsmGetMemory (sizeof (DWORD));
  127. if (objectContent.Details.DetailsData) {
  128. objectContent.Details.DetailsSize = sizeof (DWORD);
  129. *((PDWORD)objectContent.Details.DetailsData) = REG_SZ;
  130. objectContent.MemoryContent.ContentBytes = IsmGetMemory (SizeOfString (TEXT("1170,")));
  131. if (objectContent.MemoryContent.ContentBytes) {
  132. objectContent.MemoryContent.ContentSize = SizeOfString (TEXT("1170,"));
  133. CopyMemory ((PTSTR)objectContent.MemoryContent.ContentBytes, TEXT("1170,"), objectContent.MemoryContent.ContentSize);
  134. pAddObjectToTable (objectTypeId, objectName, &objectContent);
  135. }
  136. }
  137. objectName = IsmCreateObjectHandle (S_LOCATIONS, TEXT("NextID"));
  138. objectContent.Details.DetailsData = IsmGetMemory (sizeof (DWORD));
  139. if (objectContent.Details.DetailsData) {
  140. objectContent.Details.DetailsSize = sizeof (DWORD);
  141. *((PDWORD)objectContent.Details.DetailsData) = REG_DWORD;
  142. objectContent.MemoryContent.ContentBytes = IsmGetMemory (sizeof (DWORD));
  143. if (objectContent.MemoryContent.ContentBytes) {
  144. objectContent.MemoryContent.ContentSize = sizeof (DWORD);
  145. *((PDWORD)objectContent.MemoryContent.ContentBytes) = totalLocations + 1;
  146. pAddObjectToTable (objectTypeId, objectName, &objectContent);
  147. }
  148. }
  149. objectName = IsmCreateObjectHandle (S_LOCATIONS, TEXT("NumEntries"));
  150. objectContent.Details.DetailsData = IsmGetMemory (sizeof (DWORD));
  151. if (objectContent.Details.DetailsData) {
  152. objectContent.Details.DetailsSize = sizeof (DWORD);
  153. *((PDWORD)objectContent.Details.DetailsData) = REG_DWORD;
  154. objectContent.MemoryContent.ContentBytes = IsmGetMemory (sizeof (DWORD));
  155. if (objectContent.MemoryContent.ContentBytes) {
  156. objectContent.MemoryContent.ContentSize = sizeof (DWORD);
  157. *((PDWORD)objectContent.MemoryContent.ContentBytes) = totalLocations;
  158. pAddObjectToTable (objectTypeId, objectName, &objectContent);
  159. }
  160. }
  161. currentLocation = 0;
  162. if (InfFindFirstLine (hInf, TEXT("Locations"), TEXT("CurrentLocation"), &context)) {
  163. if (InfGetIntField (&context, 1, &currentLocation)) {
  164. }
  165. }
  166. while (totalLocations) {
  167. wsprintf (locationStr, TEXT("Location%d"), totalLocations - 1);
  168. if (InfFindFirstLine (hInf, TEXT("Locations"), locationStr, &context)) {
  169. wsprintf (locationStr, TEXT("Location%d"), totalLocations);
  170. // let's read all the items for this location
  171. currLocInt = 0;
  172. InfGetIntField (&context, 1, &currLocInt);
  173. if (currLocInt == currentLocation) {
  174. // this is the current location, let's write that
  175. objectName = IsmCreateObjectHandle (S_LOCATIONS, TEXT("CurrentID"));
  176. objectContent.Details.DetailsData = IsmGetMemory (sizeof (DWORD));
  177. if (objectContent.Details.DetailsData) {
  178. objectContent.Details.DetailsSize = sizeof (DWORD);
  179. *((PDWORD)objectContent.Details.DetailsData) = REG_DWORD;
  180. objectContent.MemoryContent.ContentBytes = IsmGetMemory (sizeof (DWORD));
  181. if (objectContent.MemoryContent.ContentBytes) {
  182. objectContent.MemoryContent.ContentSize = sizeof (DWORD);
  183. *((PDWORD)objectContent.MemoryContent.ContentBytes) = currLocInt + 1;
  184. pAddObjectToTable (objectTypeId, objectName, &objectContent);
  185. }
  186. }
  187. }
  188. currLocReg = JoinPaths (S_LOCATIONS, locationStr);
  189. objectName = IsmCreateObjectHandle (currLocReg, NULL);
  190. objectContent.Details.DetailsData = NULL;
  191. objectContent.Details.DetailsSize = 0;
  192. objectContent.MemoryContent.ContentBytes = NULL;
  193. objectContent.MemoryContent.ContentSize = 0;
  194. pAddObjectToTable (objectTypeId, objectName, &objectContent);
  195. /*
  196. objectName = IsmCreateObjectHandle (currLocReg, TEXT("ID"));
  197. objectContent.Details.DetailsData = IsmGetMemory (sizeof (DWORD));
  198. if (objectContent.Details.DetailsData) {
  199. objectContent.Details.DetailsSize = sizeof (DWORD);
  200. *((PDWORD)objectContent.Details.DetailsData) = REG_DWORD;
  201. objectContent.MemoryContent.ContentBytes = IsmGetMemory (sizeof (DWORD));
  202. if (objectContent.MemoryContent.ContentBytes) {
  203. objectContent.MemoryContent.ContentSize = sizeof (DWORD);
  204. *((PDWORD)objectContent.MemoryContent.ContentBytes) = currLocInt;
  205. pAddObjectToTable (objectTypeId, objectName, &objectContent);
  206. }
  207. }
  208. */
  209. currLocStr = InfGetStringField (&context, 2);
  210. if (!currLocStr) {
  211. currLocStr = locationStr;
  212. }
  213. objectName = IsmCreateObjectHandle (currLocReg, TEXT("Name"));
  214. objectContent.Details.DetailsData = IsmGetMemory (sizeof (DWORD));
  215. if (objectContent.Details.DetailsData) {
  216. objectContent.Details.DetailsSize = sizeof (DWORD);
  217. *((PDWORD)objectContent.Details.DetailsData) = REG_SZ;
  218. objectContent.MemoryContent.ContentBytes = IsmGetMemory (SizeOfString (currLocStr));
  219. if (objectContent.MemoryContent.ContentBytes) {
  220. objectContent.MemoryContent.ContentSize = SizeOfString (currLocStr);
  221. CopyMemory ((PTSTR)objectContent.MemoryContent.ContentBytes, currLocStr, objectContent.MemoryContent.ContentSize);
  222. pAddObjectToTable (objectTypeId, objectName, &objectContent);
  223. }
  224. }
  225. currLocStr = InfGetStringField (&context, 3);
  226. if (currLocStr) {
  227. objectName = IsmCreateObjectHandle (currLocReg, TEXT("OutsideAccess"));
  228. objectContent.Details.DetailsData = IsmGetMemory (sizeof (DWORD));
  229. if (objectContent.Details.DetailsData) {
  230. objectContent.Details.DetailsSize = sizeof (DWORD);
  231. *((PDWORD)objectContent.Details.DetailsData) = REG_SZ;
  232. objectContent.MemoryContent.ContentBytes = IsmGetMemory (SizeOfString (currLocStr));
  233. if (objectContent.MemoryContent.ContentBytes) {
  234. objectContent.MemoryContent.ContentSize = SizeOfString (currLocStr);
  235. CopyMemory ((PTSTR)objectContent.MemoryContent.ContentBytes, currLocStr, objectContent.MemoryContent.ContentSize);
  236. pAddObjectToTable (objectTypeId, objectName, &objectContent);
  237. }
  238. }
  239. }
  240. currLocStr = InfGetStringField (&context, 4);
  241. if (currLocStr) {
  242. objectName = IsmCreateObjectHandle (currLocReg, TEXT("LongDistanceAccess"));
  243. objectContent.Details.DetailsData = IsmGetMemory (sizeof (DWORD));
  244. if (objectContent.Details.DetailsData) {
  245. objectContent.Details.DetailsSize = sizeof (DWORD);
  246. *((PDWORD)objectContent.Details.DetailsData) = REG_SZ;
  247. objectContent.MemoryContent.ContentBytes = IsmGetMemory (SizeOfString (currLocStr));
  248. if (objectContent.MemoryContent.ContentBytes) {
  249. objectContent.MemoryContent.ContentSize = SizeOfString (currLocStr);
  250. CopyMemory ((PTSTR)objectContent.MemoryContent.ContentBytes, currLocStr, objectContent.MemoryContent.ContentSize);
  251. pAddObjectToTable (objectTypeId, objectName, &objectContent);
  252. }
  253. }
  254. }
  255. currLocStr = InfGetStringField (&context, 5);
  256. if (currLocStr) {
  257. objectName = IsmCreateObjectHandle (currLocReg, TEXT("AreaCode"));
  258. objectContent.Details.DetailsData = IsmGetMemory (sizeof (DWORD));
  259. if (objectContent.Details.DetailsData) {
  260. objectContent.Details.DetailsSize = sizeof (DWORD);
  261. *((PDWORD)objectContent.Details.DetailsData) = REG_SZ;
  262. objectContent.MemoryContent.ContentBytes = IsmGetMemory (SizeOfString (currLocStr));
  263. if (objectContent.MemoryContent.ContentBytes) {
  264. objectContent.MemoryContent.ContentSize = SizeOfString (currLocStr);
  265. CopyMemory ((PTSTR)objectContent.MemoryContent.ContentBytes, currLocStr, objectContent.MemoryContent.ContentSize);
  266. pAddObjectToTable (objectTypeId, objectName, &objectContent);
  267. }
  268. }
  269. }
  270. currLocInt = 1;
  271. InfGetIntField (&context, 6, &currLocInt);
  272. objectName = IsmCreateObjectHandle (currLocReg, TEXT("Country"));
  273. objectContent.Details.DetailsData = IsmGetMemory (sizeof (DWORD));
  274. if (objectContent.Details.DetailsData) {
  275. objectContent.Details.DetailsSize = sizeof (DWORD);
  276. *((PDWORD)objectContent.Details.DetailsData) = REG_DWORD;
  277. objectContent.MemoryContent.ContentBytes = IsmGetMemory (sizeof (DWORD));
  278. if (objectContent.MemoryContent.ContentBytes) {
  279. objectContent.MemoryContent.ContentSize = sizeof (DWORD);
  280. *((PDWORD)objectContent.MemoryContent.ContentBytes) = currLocInt;
  281. pAddObjectToTable (objectTypeId, objectName, &objectContent);
  282. }
  283. }
  284. currLocInt = 1;
  285. InfGetIntField (&context, 11, &currLocInt);
  286. objectName = IsmCreateObjectHandle (currLocReg, TEXT("Flags"));
  287. objectContent.Details.DetailsData = IsmGetMemory (sizeof (DWORD));
  288. if (objectContent.Details.DetailsData) {
  289. objectContent.Details.DetailsSize = sizeof (DWORD);
  290. *((PDWORD)objectContent.Details.DetailsData) = REG_DWORD;
  291. objectContent.MemoryContent.ContentBytes = IsmGetMemory (sizeof (DWORD));
  292. if (objectContent.MemoryContent.ContentBytes) {
  293. objectContent.MemoryContent.ContentSize = sizeof (DWORD);
  294. *((PDWORD)objectContent.MemoryContent.ContentBytes) = (!currLocInt)?0x00000005:0x00000004;
  295. pAddObjectToTable (objectTypeId, objectName, &objectContent);
  296. }
  297. }
  298. currLocStr = InfGetStringField (&context, 12);
  299. if (currLocStr) {
  300. objectName = IsmCreateObjectHandle (currLocReg, TEXT("DisableCallWaiting"));
  301. objectContent.Details.DetailsData = IsmGetMemory (sizeof (DWORD));
  302. if (objectContent.Details.DetailsData) {
  303. objectContent.Details.DetailsSize = sizeof (DWORD);
  304. *((PDWORD)objectContent.Details.DetailsData) = REG_SZ;
  305. objectContent.MemoryContent.ContentBytes = IsmGetMemory (SizeOfString (currLocStr));
  306. if (objectContent.MemoryContent.ContentBytes) {
  307. objectContent.MemoryContent.ContentSize = SizeOfString (currLocStr);
  308. CopyMemory ((PTSTR)objectContent.MemoryContent.ContentBytes, currLocStr, objectContent.MemoryContent.ContentSize);
  309. pAddObjectToTable (objectTypeId, objectName, &objectContent);
  310. }
  311. }
  312. }
  313. FreePathString (currLocReg);
  314. currLocReg = NULL;
  315. }
  316. totalLocations --;
  317. }
  318. }
  319. }
  320. }
  321. }
  322. }
  323. return TRUE;
  324. }
  325. BOOL
  326. WINAPI
  327. ScriptEtmInitialize (
  328. IN MIG_PLATFORMTYPEID Platform,
  329. IN PMIG_LOGCALLBACK LogCallback,
  330. IN PVOID Reserved
  331. )
  332. {
  333. MIG_OSVERSIONINFO versionInfo;
  334. LogReInit (NULL, NULL, NULL, (PLOGCALLBACK) LogCallback);
  335. g_ObjectsTable = HtAllocWithData (sizeof (MIG_CONTENT));
  336. if (!g_ObjectsTable) {
  337. return FALSE;
  338. }
  339. // Now let's look if we need to translate the Telephony locations settings.
  340. // On Win95 these settings are in %windir%\TELEPHONY.INI and they need to be
  341. // moved in HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Telephony\\Locations key.
  342. if (IsmGetRealPlatform () == PLATFORM_SOURCE) {
  343. ZeroMemory (&versionInfo, sizeof (MIG_OSVERSIONINFO));
  344. if (IsmGetOsVersionInfo (PLATFORM_SOURCE, &versionInfo)) {
  345. if ((versionInfo.OsType == OSTYPE_WINDOWS9X) &&
  346. ((versionInfo.OsMajorVersion == OSMAJOR_WIN95) ||
  347. (versionInfo.OsMajorVersion == OSMAJOR_WIN95OSR2)
  348. )
  349. ) {
  350. // we are on a Win95 Gold system
  351. pTranslateLocations ();
  352. }
  353. }
  354. }
  355. return TRUE;
  356. }
  357. BOOL
  358. WINAPI
  359. AcquireScriptObject (
  360. IN MIG_OBJECTSTRINGHANDLE ObjectName,
  361. IN PMIG_CONTENT ObjectContent,
  362. IN MIG_CONTENTTYPE ContentType,
  363. IN UINT MemoryContentLimit,
  364. OUT PMIG_CONTENT *NewObjectContent, CALLER_INITIALIZED OPTIONAL
  365. IN BOOL ReleaseContent,
  366. IN ULONG_PTR Arg
  367. )
  368. {
  369. PMIG_CONTENT objectContent;
  370. BOOL result = FALSE;
  371. __try {
  372. objectContent = IsmGetMemory (sizeof (MIG_CONTENT));
  373. if (HtFindStringEx (g_ObjectsTable, ObjectName, objectContent, FALSE)) {
  374. if ((ContentType == CONTENTTYPE_FILE) &&
  375. (!objectContent->ContentInFile)
  376. ) {
  377. DEBUGMSG ((DBG_ERROR, "Script added object content cannot be saved to a file: %s", ObjectName));
  378. __leave;
  379. }
  380. if ((ContentType == CONTENTTYPE_MEMORY) &&
  381. (objectContent->ContentInFile)
  382. ) {
  383. DEBUGMSG ((DBG_ERROR, "Script added object content cannot be saved to memory: %s", ObjectName));
  384. __leave;
  385. }
  386. *NewObjectContent = objectContent;
  387. objectContent->EtmHandle = objectContent;
  388. result = TRUE;
  389. }
  390. }
  391. __finally {
  392. if (!result && objectContent) {
  393. IsmReleaseMemory (objectContent);
  394. objectContent = NULL;
  395. }
  396. }
  397. return result;
  398. }
  399. VOID
  400. WINAPI
  401. ReleaseScriptObject (
  402. IN PMIG_CONTENT ObjectContent
  403. )
  404. {
  405. if (ObjectContent) {
  406. IsmReleaseMemory (ObjectContent->EtmHandle);
  407. }
  408. }
  409. BOOL
  410. WINAPI
  411. ScriptAddObject (
  412. IN OUT PMIG_TYPEOBJECTENUM ObjectEnum,
  413. IN MIG_OBJECTSTRINGHANDLE Pattern, // NULL if Abort is TRUE
  414. IN MIG_PARSEDPATTERN ParsedPattern, // NULL if Abort is TRUE
  415. IN ULONG_PTR Arg,
  416. IN BOOL Abort
  417. )
  418. {
  419. MIG_OBJECTSTRINGHANDLE objectName;
  420. MIG_CONTENT objectContent;
  421. BOOL enumDone = FALSE;
  422. PCTSTR p;
  423. BOOL result = FALSE;
  424. if (Abort) {
  425. IsmDestroyObjectString (ObjectEnum->ObjectNode);
  426. ObjectEnum->ObjectNode = NULL;
  427. IsmDestroyObjectString (ObjectEnum->ObjectLeaf);
  428. ObjectEnum->ObjectLeaf = NULL;
  429. IsmReleaseMemory (ObjectEnum->NativeObjectName);
  430. ObjectEnum->NativeObjectName = NULL;
  431. result = TRUE;
  432. } else {
  433. enumDone = (ObjectEnum->EtmHandle == 1);
  434. if (enumDone) {
  435. IsmDestroyObjectString (ObjectEnum->ObjectNode);
  436. ObjectEnum->ObjectNode = NULL;
  437. IsmDestroyObjectString (ObjectEnum->ObjectLeaf);
  438. ObjectEnum->ObjectLeaf = NULL;
  439. IsmReleaseMemory (ObjectEnum->NativeObjectName);
  440. ObjectEnum->NativeObjectName = NULL;
  441. ObjectEnum->EtmHandle = 0;
  442. result = FALSE;
  443. } else {
  444. objectName = (MIG_OBJECTSTRINGHANDLE) Arg;
  445. if (HtFindStringEx (g_ObjectsTable, objectName, &objectContent, FALSE)) {
  446. if (IsmParsedPatternMatch (ParsedPattern, objectContent.ObjectTypeId, objectName)) {
  447. ObjectEnum->ObjectName = objectName;
  448. //
  449. // Fill in node, leaf and details
  450. //
  451. IsmDestroyObjectString (ObjectEnum->ObjectNode);
  452. IsmDestroyObjectString (ObjectEnum->ObjectLeaf);
  453. IsmReleaseMemory (ObjectEnum->NativeObjectName);
  454. IsmCreateObjectStringsFromHandle (
  455. ObjectEnum->ObjectName,
  456. &ObjectEnum->ObjectNode,
  457. &ObjectEnum->ObjectLeaf
  458. );
  459. ObjectEnum->Level = 0;
  460. if (ObjectEnum->ObjectNode) {
  461. p = _tcschr (ObjectEnum->ObjectNode, TEXT('\\'));
  462. while (p) {
  463. ObjectEnum->Level++;
  464. p = _tcschr (p + 1, TEXT('\\'));
  465. }
  466. }
  467. if (ObjectEnum->ObjectLeaf) {
  468. ObjectEnum->Level ++;
  469. }
  470. ObjectEnum->SubLevel = 0;
  471. if (ObjectEnum->ObjectLeaf) {
  472. ObjectEnum->IsNode = FALSE;
  473. ObjectEnum->IsLeaf = TRUE;
  474. } else {
  475. ObjectEnum->IsNode = TRUE;
  476. ObjectEnum->IsLeaf = FALSE;
  477. }
  478. ObjectEnum->Details.DetailsSize = objectContent.Details.DetailsSize;
  479. ObjectEnum->Details.DetailsData = objectContent.Details.DetailsData;
  480. //
  481. // Rely on base type to get the native object name
  482. //
  483. ObjectEnum->NativeObjectName = IsmGetNativeObjectName (
  484. ObjectEnum->ObjectTypeId,
  485. ObjectEnum->ObjectName
  486. );
  487. result = TRUE;
  488. ObjectEnum->EtmHandle = 1;
  489. }
  490. }
  491. }
  492. }
  493. return result;
  494. }
  495. BOOL
  496. pAddObjectToTable (
  497. IN MIG_OBJECTTYPEID ObjectTypeId,
  498. IN MIG_OBJECTSTRINGHANDLE ObjectName,
  499. IN PMIG_CONTENT ObjectContent
  500. )
  501. {
  502. BOOL b = TRUE;
  503. HtAddStringEx (g_ObjectsTable, ObjectName, ObjectContent, FALSE);
  504. b = b && IsmProhibitPhysicalEnum (
  505. ObjectTypeId,
  506. ObjectName,
  507. NULL,
  508. 0,
  509. NULL
  510. );
  511. b = b && IsmAddToPhysicalEnum (
  512. ObjectTypeId,
  513. ObjectName,
  514. ScriptAddObject,
  515. (ULONG_PTR)ObjectName
  516. );
  517. b = b && IsmRegisterPhysicalAcquireHook (
  518. ObjectTypeId,
  519. ObjectName,
  520. AcquireScriptObject,
  521. ReleaseScriptObject,
  522. 0,
  523. NULL
  524. );
  525. return b;
  526. }
  527. BOOL
  528. pDoesObjectExist (
  529. IN MIG_OBJECTTYPEID ObjectTypeId,
  530. IN MIG_OBJECTSTRINGHANDLE ObjectName
  531. )
  532. {
  533. MIG_CONTENT objectContent;
  534. BOOL result = FALSE;
  535. if (IsmAcquireObject (ObjectTypeId, ObjectName, &objectContent)) {
  536. IsmReleaseObject (&objectContent);
  537. result = TRUE;
  538. }
  539. return result;
  540. }
  541. BOOL
  542. pParseEtmInfSection (
  543. IN PINFSTRUCT InfStruct,
  544. IN HINF InfHandle,
  545. IN PCTSTR Section
  546. )
  547. {
  548. PCTSTR objectTypeName;
  549. MIG_OBJECTTYPEID objectTypeId;
  550. PCTSTR objectMultiSz;
  551. MIG_CONTENT objectContent;
  552. MIG_OBJECTSTRINGHANDLE objectName;
  553. BOOL result = TRUE;
  554. BOOL b = TRUE;
  555. UINT force = 0;
  556. if (InfHandle == INVALID_HANDLE_VALUE) {
  557. return FALSE;
  558. }
  559. __try {
  560. if (InfFindFirstLine (InfHandle, Section, NULL, InfStruct)) {
  561. do {
  562. if (IsmCheckCancel()) {
  563. __leave;
  564. }
  565. InfResetInfStruct (InfStruct);
  566. objectTypeName = InfGetStringField (InfStruct, 1);
  567. if (objectTypeName) {
  568. objectTypeId = IsmGetObjectTypeId (objectTypeName);
  569. if (objectTypeId) {
  570. if (!InfGetIntField (InfStruct, 2, &force)) {
  571. force = 0;
  572. }
  573. // let's read the object multi-sz
  574. objectMultiSz = InfGetMultiSzField (InfStruct, 3);
  575. if (objectMultiSz) {
  576. if (IsmConvertMultiSzToObject (
  577. objectTypeId,
  578. objectMultiSz,
  579. &objectName,
  580. &objectContent
  581. )) {
  582. // finally we have an object
  583. // if force==0 we need to see if this object already exists
  584. if ((force == 1) || (!pDoesObjectExist (objectTypeId, objectName))) {
  585. // save it in our hash table and
  586. // call the appropriate hooks
  587. pAddObjectToTable (objectTypeId, objectName, &objectContent);
  588. } else {
  589. if ((objectContent.Details.DetailsSize) &&
  590. (objectContent.Details.DetailsData)
  591. ) {
  592. IsmReleaseMemory (objectContent.Details.DetailsData);
  593. }
  594. if (objectContent.ContentInFile) {
  595. if (objectContent.FileContent.ContentPath) {
  596. IsmReleaseMemory (objectContent.FileContent.ContentPath);
  597. }
  598. } else {
  599. if ((objectContent.MemoryContent.ContentSize) &&
  600. (objectContent.MemoryContent.ContentBytes)
  601. ) {
  602. IsmReleaseMemory (objectContent.MemoryContent.ContentBytes);
  603. }
  604. }
  605. }
  606. }
  607. }
  608. }
  609. }
  610. } while (InfFindNextLine (InfStruct));
  611. }
  612. result = TRUE;
  613. }
  614. __finally {
  615. InfCleanUpInfStruct (InfStruct);
  616. }
  617. return result;
  618. }
  619. BOOL
  620. pParseEtmIniInfSection (
  621. IN PINFSTRUCT InfStruct,
  622. IN HINF InfHandle,
  623. IN PCTSTR Section
  624. )
  625. {
  626. PCTSTR iniFile;
  627. PCTSTR iniFileExp = NULL;
  628. PCTSTR iniSection;
  629. PCTSTR iniValue;
  630. PCTSTR iniRegKey;
  631. PCTSTR iniRegValue;
  632. TCHAR iniItem [MAX_TCHAR_PATH];
  633. MIG_OBJECTTYPEID objectTypeId;
  634. MIG_CONTENT objectContent;
  635. MIG_OBJECTSTRINGHANDLE objectName;
  636. BOOL result = TRUE;
  637. BOOL b = TRUE;
  638. if (InfHandle == INVALID_HANDLE_VALUE) {
  639. return FALSE;
  640. }
  641. __try {
  642. if (InfFindFirstLine (InfHandle, Section, NULL, InfStruct)) {
  643. do {
  644. if (IsmCheckCancel()) {
  645. __leave;
  646. }
  647. InfResetInfStruct (InfStruct);
  648. iniFile = InfGetStringField (InfStruct, 1);
  649. if (!iniFile || !iniFile[0]) {
  650. __leave;
  651. }
  652. iniFileExp = IsmExpandEnvironmentString (PLATFORM_SOURCE, S_SYSENVVAR_GROUP, iniFile, NULL);
  653. if (!iniFileExp || !iniFileExp[0]) {
  654. __leave;
  655. }
  656. iniSection = InfGetStringField (InfStruct, 2);
  657. if (!iniSection || !iniSection[0]) {
  658. __leave;
  659. }
  660. iniValue = InfGetStringField (InfStruct, 3);
  661. if (!iniValue || !iniValue[0]) {
  662. __leave;
  663. }
  664. iniRegKey = InfGetStringField (InfStruct, 4);
  665. if (!iniRegKey || !iniRegKey[0]) {
  666. __leave;
  667. }
  668. iniRegValue = InfGetStringField (InfStruct, 5);
  669. if (!iniRegValue || !iniRegValue[0]) {
  670. __leave;
  671. }
  672. // let's get the INI item
  673. GetPrivateProfileString (iniSection, iniValue, TEXT(""), iniItem, MAX_TCHAR_PATH, iniFileExp);
  674. if (!iniItem[0]) {
  675. __leave;
  676. }
  677. objectTypeId = MIG_REGISTRY_TYPE;
  678. objectName = IsmCreateObjectHandle (iniRegKey, iniRegValue);
  679. ZeroMemory (&objectContent, sizeof (MIG_CONTENT));
  680. objectContent.ObjectTypeId = objectTypeId;
  681. objectContent.ContentInFile = FALSE;
  682. objectContent.MemoryContent.ContentSize = SizeOfString (iniItem);
  683. objectContent.MemoryContent.ContentBytes = IsmGetMemory (objectContent.MemoryContent.ContentSize);
  684. CopyMemory ((PBYTE)objectContent.MemoryContent.ContentBytes, iniItem, objectContent.MemoryContent.ContentSize);
  685. objectContent.Details.DetailsSize = sizeof (DWORD);
  686. objectContent.Details.DetailsData = IsmGetMemory (sizeof (DWORD));
  687. *((PDWORD)objectContent.Details.DetailsData) = REG_SZ;
  688. // finally we have an object
  689. // save it in our hash table and
  690. // call the appropriate hooks
  691. b = b && pAddObjectToTable (objectTypeId, objectName, &objectContent);
  692. if (iniFileExp) {
  693. IsmReleaseMemory (iniFileExp);
  694. iniFileExp = NULL;
  695. }
  696. } while (InfFindNextLine (InfStruct));
  697. }
  698. result = TRUE;
  699. }
  700. __finally {
  701. if (iniFileExp) {
  702. IsmReleaseMemory (iniFileExp);
  703. iniFileExp = NULL;
  704. }
  705. InfCleanUpInfStruct (InfStruct);
  706. }
  707. return result;
  708. }
  709. BOOL
  710. pParseEtmInf (
  711. IN HINF InfHandle
  712. )
  713. {
  714. PCTSTR osSpecificSection;
  715. BOOL b;
  716. INFSTRUCT is = INITINFSTRUCT_PMHANDLE;
  717. b = pParseEtmInfSection (&is, InfHandle, TEXT("AddObject"));
  718. if (b) {
  719. osSpecificSection = GetMostSpecificSection (&is, InfHandle, TEXT("AddObject"));
  720. if (osSpecificSection) {
  721. b = pParseEtmInfSection (&is, InfHandle, osSpecificSection);
  722. FreeText (osSpecificSection);
  723. }
  724. }
  725. b = pParseEtmIniInfSection (&is, InfHandle, TEXT("AddIniRegObject"));
  726. if (b) {
  727. osSpecificSection = GetMostSpecificSection (&is, InfHandle, TEXT("AddIniRegObject"));
  728. if (osSpecificSection) {
  729. b = pParseEtmIniInfSection (&is, InfHandle, osSpecificSection);
  730. FreeText (osSpecificSection);
  731. }
  732. }
  733. return b;
  734. }
  735. BOOL
  736. WINAPI
  737. ScriptEtmParse (
  738. IN PVOID Reserved
  739. )
  740. {
  741. PTSTR multiSz = NULL;
  742. MULTISZ_ENUM e;
  743. UINT sizeNeeded;
  744. HINF infHandle = INVALID_HANDLE_VALUE;
  745. ENVENTRY_TYPE dataType;
  746. BOOL result = FALSE;
  747. if (IsmGetEnvironmentValue (
  748. IsmGetRealPlatform (),
  749. NULL,
  750. S_GLOBAL_INF_HANDLE,
  751. (PBYTE)(&infHandle),
  752. sizeof (HINF),
  753. &sizeNeeded,
  754. &dataType
  755. ) &&
  756. (sizeNeeded == sizeof (HINF)) &&
  757. (dataType == ENVENTRY_BINARY)
  758. ) {
  759. if (pParseEtmInf (infHandle)) {
  760. result = TRUE;
  761. }
  762. InfNameHandle (infHandle, NULL, FALSE);
  763. } else {
  764. if (!IsmGetEnvironmentValue (IsmGetRealPlatform (), NULL, S_INF_FILE_MULTISZ, NULL, 0, &sizeNeeded, NULL)) {
  765. return TRUE; // no INF files specified
  766. }
  767. __try {
  768. multiSz = AllocText (sizeNeeded);
  769. if (!multiSz) {
  770. __leave;
  771. }
  772. if (!IsmGetEnvironmentValue (IsmGetRealPlatform (), NULL, S_INF_FILE_MULTISZ, (PBYTE) multiSz, sizeNeeded, NULL, NULL)) {
  773. __leave;
  774. }
  775. if (EnumFirstMultiSz (&e, multiSz)) {
  776. do {
  777. infHandle = InfOpenInfFile (e.CurrentString);
  778. if (infHandle != INVALID_HANDLE_VALUE) {
  779. if (!pParseEtmInf (infHandle)) {
  780. InfCloseInfFile (infHandle);
  781. infHandle = INVALID_HANDLE_VALUE;
  782. __leave;
  783. }
  784. } else {
  785. LOG ((LOG_ERROR, (PCSTR) MSG_CANT_OPEN_INF, e.CurrentString));
  786. }
  787. InfCloseInfFile (infHandle);
  788. infHandle = INVALID_HANDLE_VALUE;
  789. } while (EnumNextMultiSz (&e));
  790. }
  791. result = TRUE;
  792. }
  793. __finally {
  794. if (multiSz) {
  795. FreeText (multiSz);
  796. multiSz = NULL;
  797. }
  798. }
  799. }
  800. return result;
  801. }
  802. VOID
  803. WINAPI
  804. ScriptEtmTerminate (
  805. VOID
  806. )
  807. {
  808. HASHTABLE_ENUM e;
  809. PMIG_CONTENT objectContent;
  810. if (g_ObjectsTable) {
  811. // enumerate the table and release all memory
  812. if (EnumFirstHashTableString (&e, g_ObjectsTable)) {
  813. do {
  814. objectContent = (PMIG_CONTENT) e.ExtraData;
  815. if ((objectContent->Details.DetailsSize) &&
  816. (objectContent->Details.DetailsData)
  817. ) {
  818. IsmReleaseMemory (objectContent->Details.DetailsData);
  819. }
  820. if (objectContent->ContentInFile) {
  821. if (objectContent->FileContent.ContentPath) {
  822. IsmReleaseMemory (objectContent->FileContent.ContentPath);
  823. }
  824. } else {
  825. if ((objectContent->MemoryContent.ContentSize) &&
  826. (objectContent->MemoryContent.ContentBytes)
  827. ) {
  828. IsmReleaseMemory (objectContent->MemoryContent.ContentBytes);
  829. }
  830. }
  831. } while (EnumNextHashTableString (&e));
  832. }
  833. HtFree (g_ObjectsTable);
  834. g_ObjectsTable = NULL;
  835. }
  836. }