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.

297 lines
5.5 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. apciuasm.c
  5. Abstract:
  6. This unassembles an AML file
  7. Author:
  8. Based on code by Mike Tsang (MikeTs)
  9. Stephane Plante (Splante)
  10. Environment:
  11. User mode only
  12. Revision History:
  13. --*/
  14. #include <nt.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. #include <zwapi.h>
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <stdlib.h>
  21. #include <stdarg.h>
  22. #include <memory.h>
  23. #include <crt\io.h>
  24. #include <fcntl.h>
  25. #include <windows.h>
  26. #include <windef.h>
  27. #define SPEC_VER 100
  28. #include "acpitabl.h"
  29. #include "unasmdll.h"
  30. #include "parsearg.h"
  31. ULONG ParseOutput( PUCHAR *Argument, PARGTYPE TableEntry );
  32. ULONG PrintHelp(PUCHAR *Argument, PARGTYPE TableEntry );
  33. VOID PrintOutput(PCCHAR Format, ... );
  34. ARGTYPE ArgTypes[] = {
  35. { "?", AT_ACTION, 0, PrintHelp, 0, NULL },
  36. { "Fo", AT_ACTION, PF_SEPARATOR, ParseOutput, 0, NULL },
  37. { "" , 0, 0, 0, 0, NULL }
  38. };
  39. #pragma warning(default: 4054)
  40. PROGINFO ProgInfo = { NULL, NULL, NULL, NULL };
  41. FILE *outputHandle;
  42. int
  43. __cdecl
  44. main(
  45. IN int argc,
  46. IN char *argv[]
  47. )
  48. /*++
  49. Routine Description:
  50. This routine unassembles and displays a file
  51. Arguments:
  52. argc - Number of Arguments
  53. argv - Array of Arruments
  54. Return Value:
  55. int
  56. --*/
  57. {
  58. int rc;
  59. int handle;
  60. NTSTATUS result;
  61. PUCHAR byte = NULL;
  62. ULONG length;
  63. ULONG readLength;
  64. outputHandle = stdout;
  65. //
  66. // Beging by initializing the program information
  67. //
  68. ParseProgramInfo( argv[0], &ProgInfo );
  69. argv++;
  70. argc--;
  71. //
  72. // Parse all the switches away
  73. //
  74. if (ParseSwitches( &argc, &argv, ArgTypes, &ProgInfo) != ARGERR_NONE ||
  75. argc != 1) {
  76. PrintHelp( NULL, NULL );
  77. return 0;
  78. }
  79. //
  80. // Open the remaining argument as our input file
  81. //
  82. handle = _open( argv[0], _O_BINARY | _O_RDONLY);
  83. if (handle == -1) {
  84. fprintf( stderr, "%s: Failed to open AML file - %s\n",
  85. ProgInfo.ProgName, argv[0] );
  86. return -1;
  87. }
  88. byte = malloc( sizeof(DESCRIPTION_HEADER) );
  89. if (byte == NULL) {
  90. fprintf( stderr, "%s: Failed to allocate description header block\n",
  91. ProgInfo.ProgName );
  92. return -2;
  93. }
  94. rc = _read( handle, byte, sizeof(DESCRIPTION_HEADER) );
  95. if (rc != sizeof(DESCRIPTION_HEADER) ) {
  96. fprintf( stderr, "%s: Failed to read description header block\n",
  97. ProgInfo.ProgName );
  98. return -3;
  99. }
  100. rc = _lseek( handle, 0, SEEK_SET);
  101. if (rc == -1) {
  102. fprintf( stderr, "%s: Failed seeking to beginning of file\n",
  103. ProgInfo.ProgName );
  104. return -4;
  105. }
  106. length = ( (PDESCRIPTION_HEADER) byte)->Length;
  107. free (byte);
  108. byte = malloc( length );
  109. if (byte == NULL) {
  110. fprintf( stderr, "%s: Failed to allocate AML file buffer\n",
  111. ProgInfo.ProgName );
  112. return -5;
  113. }
  114. readLength = (ULONG) _read( handle, byte, length );
  115. if (readLength != length) {
  116. fprintf( stderr, "%s: failed to read AML file\n",
  117. ProgInfo.ProgName );
  118. return - 6;
  119. }
  120. result = UnAsmLoadDSDT( byte );
  121. if (result == 0) {
  122. result = UnAsmDSDT( byte, PrintOutput, 0, 0 );
  123. }
  124. if (result != 0) {
  125. fprintf(stderr, "%s: result = 0x%08lx\n",
  126. ProgInfo.ProgName, result );
  127. }
  128. if (byte) {
  129. free(byte);
  130. }
  131. if (handle) {
  132. _close(handle);
  133. }
  134. return 0;
  135. }
  136. ULONG
  137. ParseOutput(
  138. PUCHAR *Argument,
  139. PARGTYPE TableEntry
  140. )
  141. /*++
  142. Routine Description:
  143. This routine is called if the user specifies a different file to output
  144. things to
  145. Arguments:
  146. Argument - Pointer to the string
  147. TableEntry - Which table entry was matched
  148. Return Value:
  149. ULONG
  150. --*/
  151. {
  152. if (*Argument == '\0') {
  153. return ARGERR_INVALID_TAIL;
  154. }
  155. outputHandle = fopen( *Argument, "w" );
  156. if (outputHandle == NULL) {
  157. fprintf( stderr, "Failed to open AML file - %s\n", *Argument );
  158. return ARGERR_INVALID_TAIL;
  159. }
  160. return ARGERR_NONE;
  161. }
  162. ULONG
  163. PrintHelp(
  164. PUCHAR *Argument,
  165. PARGTYPE TableEntry
  166. )
  167. /*++
  168. Routine Description:
  169. Print the help for the function
  170. Arguments:
  171. Argument - Pointer to the string
  172. TableEntry - Which table entry was matched
  173. Return Value:
  174. ULONG
  175. --*/
  176. {
  177. if (Argument != NULL) {
  178. printf("Error on Argument - \"%s\"\n", *Argument );
  179. }
  180. printf("Usage:\t%s /?\n", ProgInfo.ProgName );
  181. printf("\t%s [/Fo=<ASLFile>] <AMLFile>\n", ProgInfo.ProgName );
  182. printf("\t? - Print this help message.\n");
  183. printf("\tFo=ASLFile - Write output to ASLFile.\n");
  184. printf("\tAMLFile - AML File to Unassemble\n");
  185. return ARGERR_NONE;
  186. }
  187. VOID
  188. PrintOutput(
  189. PCCHAR Format,
  190. ...
  191. )
  192. /*++
  193. Routine Description:
  194. This routine is called to display information to the user
  195. Arguments:
  196. Format - Character formating
  197. ... - Arguments
  198. Return Value:
  199. Null
  200. --*/
  201. {
  202. va_list marker;
  203. va_start( marker, Format );
  204. vfprintf( outputHandle, Format, marker );
  205. fflush( outputHandle );
  206. va_end( marker );
  207. }