Leaked source code of windows server 2003
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.

764 lines
14 KiB

  1. /*++ BUILD Version: 0001 // Increment this if a change has global effects
  2. Copyright (c) 1990-1997 Microsoft Corporation
  3. Module Name:
  4. acpintsd.c
  5. Abstract:
  6. ACPI-Specific NTSD Extensions
  7. Environment:
  8. Win32
  9. Revision History:
  10. --*/
  11. #include "acpintsd.h"
  12. NTSD_EXTENSION_APIS ExtensionApis;
  13. HANDLE ExtensionCurrentProcess;
  14. PUCHAR ScTableName[] = {
  15. "ParseFunctionHandler",
  16. "ParseArgument",
  17. "ParseArgumentObject",
  18. "ParseBuffer",
  19. "ParseByte",
  20. "ParseCodeObject",
  21. "ParseConstObject",
  22. "ParseData",
  23. "ParseDelimiter",
  24. "ParseDword",
  25. "ParseField",
  26. "ParseLocalObject",
  27. "ParseName",
  28. "ParseNameObject",
  29. "ParseOpcode",
  30. "ParsePackage",
  31. "ParsePop",
  32. "ParsePush",
  33. "ParseSuperName",
  34. "ParseTrailingArgument",
  35. "ParseTrailingBuffer",
  36. "ParseTrailingPackage",
  37. "ParseVariableObject",
  38. "ParseWord"
  39. };
  40. VOID
  41. dumpParseStack(
  42. DWORD AddrStack
  43. )
  44. /*++
  45. Routine Description:
  46. This dumps the parse stack
  47. Arguments:
  48. AddrStack: Address of the stack to dump
  49. Return Value:
  50. None
  51. --*/
  52. {
  53. BOOL b;
  54. STRING_STACK tempStack;
  55. PSTRING_STACK stack;
  56. ULONG index;
  57. //
  58. // Read the stack header into memory
  59. //
  60. b = ReadMemory(
  61. (LPVOID) AddrStack,
  62. &tempStack,
  63. sizeof(STRING_STACK),
  64. NULL
  65. );
  66. if (!b) {
  67. return;
  68. }
  69. //
  70. // Allocate memory for the entire stack
  71. //
  72. stack = (PSTRING_STACK) LocalAlloc(
  73. LMEM_ZEROINIT,
  74. sizeof(STRING_STACK) + tempStack.StackSize - 1
  75. );
  76. if (!stack) {
  77. return;
  78. }
  79. //
  80. // Read the entire stack
  81. //
  82. b = ReadMemory(
  83. (LPVOID) AddrStack,
  84. stack,
  85. sizeof(STRING_STACK) + tempStack.StackSize - 1,
  86. NULL
  87. );
  88. if (!b) {
  89. LocalFree( stack );
  90. return;
  91. }
  92. //
  93. // Show the user something
  94. //
  95. dprintf(
  96. "ParseStack: Size 0x%x Top: 0x%x\n",
  97. tempStack.StackSize,
  98. tempStack.TopOfStack
  99. );
  100. if (tempStack.TopOfStack == 0) {
  101. dprintf("Stack is empty\n");
  102. return;
  103. }
  104. //
  105. // Walk the stack
  106. //
  107. for (index = tempStack.TopOfStack - 1; ; index--) {
  108. dprintf("[%2d] %s\n", index, ScTableName[ stack->Stack[index] ] );
  109. if (index == 0) {
  110. break;
  111. }
  112. }
  113. //
  114. // Free the stack
  115. //
  116. LocalFree( stack );
  117. }
  118. VOID
  119. dumpStringStack(
  120. DWORD AddrStack
  121. )
  122. /*++
  123. Routine Description:
  124. This dumps the parse stack
  125. Arguments:
  126. AddrStack: Address of the stack to dump
  127. Return Value:
  128. None
  129. --*/
  130. {
  131. BOOL b;
  132. STRING_STACK tempStack;
  133. PSTRING_STACK stack;
  134. ULONG index;
  135. //
  136. // Read the stack header into memory
  137. //
  138. b = ReadMemory(
  139. (LPVOID) AddrStack,
  140. &tempStack,
  141. sizeof(STRING_STACK),
  142. NULL
  143. );
  144. if (!b) {
  145. return;
  146. }
  147. //
  148. // Allocate memory for the entire stack
  149. //
  150. stack = (PSTRING_STACK) LocalAlloc(
  151. LMEM_ZEROINIT,
  152. sizeof(STRING_STACK) + tempStack.StackSize
  153. );
  154. if (!stack) {
  155. return;
  156. }
  157. //
  158. // Read the entire stack
  159. //
  160. b = ReadMemory(
  161. (LPVOID) AddrStack,
  162. stack,
  163. sizeof(STRING_STACK) + tempStack.StackSize - 1,
  164. NULL
  165. );
  166. if (!b) {
  167. LocalFree( stack );
  168. return;
  169. }
  170. //
  171. // Show the user something
  172. //
  173. dprintf(
  174. "StringStack: Size 0x%x Top: 0x%x\nString: '%s'\n",
  175. tempStack.StackSize,
  176. tempStack.TopOfStack,
  177. stack->Stack
  178. );
  179. //
  180. // Free the stack
  181. //
  182. LocalFree( stack );
  183. }
  184. VOID
  185. dumpScope(
  186. PSCOPE Scope
  187. )
  188. /*++
  189. Routine Description:
  190. Dumps a scope, as used in the ACPI unasm.lib
  191. Arguments:
  192. Scope - LocalCopy of the scope
  193. Return Value:
  194. None
  195. --*/
  196. {
  197. BOOL b;
  198. AMLTERM amlTerm;
  199. UCHAR buffer[64];
  200. dprintf("%8x %8x %8x %8x %2x %2x %2x %1d %8x",
  201. Scope->CurrentByte,
  202. Scope->TermByte,
  203. Scope->LastByte,
  204. Scope->StringStack,
  205. Scope->Context1,
  206. Scope->Context2,
  207. Scope->Flags,
  208. Scope->IndentLevel,
  209. Scope->AmlTerm
  210. );
  211. b = ReadMemory(
  212. Scope->AmlTerm,
  213. &amlTerm,
  214. sizeof(AMLTERM),
  215. NULL
  216. );
  217. if (!b) {
  218. dprintf("\n");
  219. return;
  220. } else {
  221. dprintf(" %4x %4x\n",
  222. amlTerm.OpCode,
  223. amlTerm.OpCodeFlags
  224. );
  225. b = ReadMemory(
  226. amlTerm.TermName,
  227. buffer,
  228. 64,
  229. NULL
  230. );
  231. if (b) {
  232. dprintf(" %-60s\n", buffer );
  233. }
  234. }
  235. }
  236. VOID
  237. dumpScopeHeader(
  238. BOOL Verbose
  239. )
  240. /*++
  241. Routine Description:
  242. Dumps the header for a scope stack dump
  243. Arguments:
  244. Verbose: wether or not to include the field for stack level
  245. Return Value:
  246. None
  247. --*/
  248. {
  249. if (Verbose) {
  250. dprintf("Level ");
  251. }
  252. dprintf(" Current First Last S.Stack C1 C2 Fl I AML Term OpCd Flag\n" );
  253. }
  254. DECLARE_API( sscope )
  255. /*++
  256. Routine Description:
  257. Dumps one of the stacks used by the ACPI Unassembler
  258. Arguments:
  259. hCurrentProcess - Supplies a handle to the current process (at the
  260. time the extension was called).
  261. hCurrentThread - Supplies a handle to the current thread (at the
  262. time the extension was called).
  263. CurrentPc - Supplies the current pc at the time the extension is
  264. called.
  265. lpExtensionApis - Supplies the address of the functions callable
  266. by this extension.
  267. lpArgumentString - Supplies the asciiz string that describes the
  268. ansi string to be dumped.
  269. Return Value:
  270. None
  271. --*/
  272. {
  273. BOOL b;
  274. DWORD addrStack;
  275. DWORD i;
  276. DWORD offset;
  277. DWORD top;
  278. STACK tempStack;
  279. PSTACK stack;
  280. PSCOPE scope;
  281. INIT_API();
  282. //
  283. // Evaluate the argument string to get the address of the
  284. // stack to dump
  285. //
  286. addrStack = GetExpression( lpArgumentString );
  287. if ( !addrStack) {
  288. return;
  289. }
  290. //
  291. // Read the stack header into memory
  292. //
  293. b = ReadMemory(
  294. (LPVOID) addrStack,
  295. &tempStack,
  296. sizeof(STACK),
  297. NULL
  298. );
  299. if (!b) {
  300. return;
  301. }
  302. //
  303. // Allocate memory for the entire stack
  304. //
  305. stack = (PSTACK) LocalAlloc(
  306. LMEM_ZEROINIT,
  307. sizeof(STACK) + tempStack.StackSize - 1
  308. );
  309. if (!stack) {
  310. return;
  311. }
  312. //
  313. // Read the entire stack
  314. //
  315. b = ReadMemory(
  316. (LPVOID) addrStack,
  317. stack,
  318. sizeof(STACK) + tempStack.StackSize - 1,
  319. NULL
  320. );
  321. if (!b) {
  322. LocalFree( stack );
  323. return;
  324. }
  325. //
  326. // Show the user something
  327. //
  328. dumpScopeHeader( TRUE );
  329. //
  330. // Loop on each of the scopes
  331. //
  332. for (top = (stack->TopOfStack / stack->StackElementSize) - 1;;top--) {
  333. scope = (PSCOPE) &(stack->Stack[ top * stack->StackElementSize ] );
  334. dprintf("[%2d]: ", top );
  335. dumpScope(scope);
  336. if (top == 0) {
  337. dumpParseStack( (DWORD) scope->ParseStack );
  338. dumpStringStack( (DWORD) scope->StringStack );
  339. break;
  340. }
  341. }
  342. //
  343. // Done
  344. //
  345. LocalFree( stack );
  346. }
  347. DECLARE_API( amlterm )
  348. {
  349. BOOL b;
  350. DWORD addrTerm;
  351. DWORD offset;
  352. AMLTERM amlTerm;
  353. UCHAR nameBuff[17];
  354. UCHAR symbolBuff[128];
  355. INIT_API();
  356. //
  357. // Evaluate the argument string to get the address of the
  358. // term to dump
  359. //
  360. addrTerm = GetExpression( lpArgumentString );
  361. if ( !addrTerm ) {
  362. return;
  363. }
  364. //
  365. // Read the term into memory
  366. //
  367. b = ReadMemory(
  368. (LPVOID) addrTerm,
  369. &amlTerm,
  370. sizeof(AMLTERM),
  371. NULL
  372. );
  373. if (!b) {
  374. return;
  375. }
  376. //
  377. // Begin to print things
  378. //
  379. dprintf("AMLTERM: %x\n", addrTerm);
  380. //
  381. // Read the name of the term into memory
  382. //
  383. nameBuff[16] = '\0';
  384. b = ReadMemory(
  385. (LPVOID) amlTerm.TermName,
  386. nameBuff,
  387. 16,
  388. NULL
  389. );
  390. dprintf("Name: %-16s ",( !b ? "<Cannot Read Name>" : nameBuff) );
  391. //
  392. // Handle the symbol term
  393. //
  394. if (amlTerm.FunctionHandler != NULL) {
  395. //
  396. // Read the symbol of the term
  397. //
  398. GetSymbol( (LPVOID) amlTerm.FunctionHandler, symbolBuff, &offset );
  399. dprintf(" Handler: %-30s\n", symbolBuff );
  400. } else {
  401. dprintf("\n");
  402. }
  403. //
  404. // Display the opcode
  405. //
  406. if ( amlTerm.OpCode > 0xFF) {
  407. dprintf(
  408. "Opcode: %2x %2x",
  409. (amlTerm.OpCode & 0xff),
  410. (amlTerm.OpCode >> 8)
  411. );
  412. } else {
  413. dprintf("Opcode: %2x ", amlTerm.OpCode );
  414. }
  415. //
  416. // Display the Argument Types
  417. //
  418. RtlZeroMemory( nameBuff, 17 );
  419. if (amlTerm.ArgumentTypes) {
  420. b = ReadMemory(
  421. (LPVOID) amlTerm.ArgumentTypes,
  422. nameBuff,
  423. 16,
  424. NULL
  425. );
  426. dprintf(" Args: %-4s", (!b ? "????" : nameBuff ) );
  427. } else {
  428. dprintf(" Args: %-4s", "None");
  429. }
  430. //
  431. // Display the flags
  432. //
  433. switch( (amlTerm.OpCodeFlags & 0xF) ) {
  434. case 0: dprintf(" Flags: NORMAL "); break;
  435. case 1: dprintf(" Flags: VARIABLE"); break;
  436. case 2: dprintf(" Flags: ARG "); break;
  437. case 3: dprintf(" Flags: LOCAL "); break;
  438. case 4: dprintf(" Flags: CONSTANT"); break;
  439. case 5: dprintf(" Flags: NAME "); break;
  440. case 6: dprintf(" Flags: DATA "); break;
  441. case 7: dprintf(" Flags: DEBUG "); break;
  442. case 8: dprintf(" Flags: REF "); break;
  443. default: dprintf(" Flags: UNKNOWN "); break;
  444. }
  445. //
  446. // Display the term group
  447. //
  448. switch(amlTerm.TermGroup & 0xF) {
  449. case 1: dprintf(" Group: NAMESPACE\n"); break;
  450. case 2: dprintf(" Group: NAMED OBJECT\n"); break;
  451. case 3: dprintf(" Group: TYPE 1\n"); break;
  452. case 4: dprintf(" Group: TYPE 2\n"); break;
  453. case 5: dprintf(" Group: OTHER\n"); break;
  454. default: dprintf(" Group: UNKNOWN\n"); break;
  455. }
  456. }
  457. DECLARE_API( scope )
  458. {
  459. BOOL b;
  460. DWORD addrScope;
  461. SCOPE scope;
  462. INIT_API();
  463. //
  464. // Evaluate the argument string to get the address of the
  465. // stack to dump
  466. //
  467. addrScope = GetExpression( lpArgumentString );
  468. if ( !addrScope) {
  469. return;
  470. }
  471. //
  472. // Read the stack header into memory
  473. //
  474. b = ReadMemory(
  475. (LPVOID) addrScope,
  476. &scope,
  477. sizeof(scope),
  478. NULL
  479. );
  480. if (!b) {
  481. return;
  482. }
  483. //
  484. // Dump the string to the user
  485. //
  486. dumpScopeHeader(FALSE);
  487. dumpScope( &scope );
  488. }
  489. DECLARE_API( pstack )
  490. {
  491. DWORD addrStack;
  492. INIT_API();
  493. addrStack = GetExpression( lpArgumentString );
  494. if (!addrStack) {
  495. return;
  496. }
  497. dumpParseStack( addrStack );
  498. }
  499. DECLARE_API( sstack )
  500. {
  501. DWORD addrStack;
  502. INIT_API();
  503. addrStack = GetExpression( lpArgumentString );
  504. if (!addrStack) {
  505. return;
  506. }
  507. dumpStringStack( addrStack );
  508. }
  509. DECLARE_API( version )
  510. {
  511. OSVERSIONINFOA VersionInformation;
  512. HKEY hkey;
  513. DWORD cb, dwType;
  514. CHAR szCurrentType[128];
  515. CHAR szCSDString[3+128];
  516. INIT_API();
  517. VersionInformation.dwOSVersionInfoSize = sizeof(VersionInformation);
  518. if (!GetVersionEx( &VersionInformation )) {
  519. dprintf("GetVersionEx failed - %u\n", GetLastError());
  520. return;
  521. }
  522. szCurrentType[0] = '\0';
  523. if (RegOpenKeyEx(
  524. HKEY_LOCAL_MACHINE,
  525. "Software\\Microsoft\\Windows NT\\CurrentVersion",
  526. 0,
  527. KEY_READ,
  528. &hkey
  529. ) == NO_ERROR
  530. ) {
  531. cb = sizeof(szCurrentType);
  532. if (RegQueryValueEx(
  533. hkey,
  534. "CurrentType",
  535. NULL,
  536. &dwType,
  537. szCurrentType,
  538. &cb ) != 0
  539. ) {
  540. szCurrentType[0] = '\0';
  541. }
  542. }
  543. RegCloseKey(hkey);
  544. if (VersionInformation.szCSDVersion[0]) {
  545. sprintf(
  546. szCSDString,
  547. ": %s",
  548. VersionInformation.szCSDVersion
  549. );
  550. } else {
  551. szCSDString[0] = '\0';
  552. }
  553. dprintf(
  554. "Version %d.%d (Build %d%s) %s\n",
  555. VersionInformation.dwMajorVersion,
  556. VersionInformation.dwMinorVersion,
  557. VersionInformation.dwBuildNumber,
  558. szCSDString,
  559. szCurrentType
  560. );
  561. return;
  562. }
  563. DECLARE_API( help )
  564. {
  565. INIT_API();
  566. dprintf("!version - Dump System Version and Build Number\n");
  567. dprintf("!sscope - Dump an UnASM Scope Stack\n");
  568. dprintf("!scope - Dump an UnASM Scope\n");
  569. dprintf("!pstack - Dump an UnASM Parse Stack\n");
  570. dprintf("!sstack - Dump an UnASM String STack\n");
  571. }