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.

328 lines
7.8 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. rcdump.c
  5. Abstract:
  6. Program to dump the resources from an image file.
  7. Author:
  8. Steve Wood (stevewo) 17-Jul-1991
  9. Revision History:
  10. --*/
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. #include <windows.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. void
  19. Usage( void );
  20. void
  21. DumpResources( char *FileName );
  22. BOOL VerboseOutput;
  23. int
  24. __cdecl
  25. main(
  26. int argc,
  27. char *argv[]
  28. )
  29. {
  30. char *s;
  31. int i;
  32. VerboseOutput = FALSE;
  33. if (argc > 1) {
  34. for (i=1; i<argc; i++) {
  35. s = _strupr( argv[i] );
  36. if (*s == '-' || *s == '/') {
  37. while (*++s)
  38. switch( *s ) {
  39. case 'V':
  40. VerboseOutput = TRUE;
  41. break;
  42. default:
  43. fprintf( stderr,
  44. "RCDUMP: Invalid switch letter '%c'\n",
  45. *s
  46. );
  47. Usage();
  48. }
  49. }
  50. else {
  51. DumpResources( argv[i] );
  52. }
  53. }
  54. }
  55. else {
  56. Usage();
  57. }
  58. exit( 0 );
  59. return 1;
  60. }
  61. void
  62. Usage( void )
  63. {
  64. fprintf( stderr, "usage: RCDUMP [-v] ImageFileName(s)\n" );
  65. exit( 1 );
  66. }
  67. BOOL
  68. EnumTypesFunc(
  69. HMODULE hModule,
  70. LPSTR lpType,
  71. LPARAM lParam
  72. );
  73. BOOL
  74. EnumNamesFunc(
  75. HMODULE hModule,
  76. LPCSTR lpType,
  77. LPSTR lpName,
  78. LPARAM lParam
  79. );
  80. BOOL
  81. EnumLangsFunc(
  82. HMODULE hModule,
  83. LPCSTR lpType,
  84. LPCSTR lpName,
  85. WORD language,
  86. LPARAM lParam
  87. );
  88. void
  89. DumpResources(
  90. char *FileName
  91. )
  92. {
  93. HMODULE hModule;
  94. if (FileName != NULL) {
  95. int i;
  96. i = SetErrorMode(SEM_FAILCRITICALERRORS);
  97. hModule = LoadLibraryEx( FileName, NULL, DONT_RESOLVE_DLL_REFERENCES|LOAD_LIBRARY_AS_DATAFILE );
  98. SetErrorMode(i);
  99. } else {
  100. hModule = NULL;
  101. }
  102. if (FileName != NULL && hModule == NULL) {
  103. printf( "RCDUMP: Unable to load image file %s - rc == %u\n",
  104. FileName,
  105. GetLastError()
  106. );
  107. } else {
  108. printf( "%s contains the following resources:\n",
  109. FileName ? FileName : "RCDUMP"
  110. );
  111. EnumResourceTypes( hModule, EnumTypesFunc, -1L );
  112. }
  113. }
  114. CHAR const *pTypeName[] = {
  115. NULL, // 0
  116. "CURSOR", // 1 RT_CURSOR
  117. "BITMAP", // 2 RT_BITMAP
  118. "ICON", // 3 RT_ICON
  119. "MENU", // 4 RT_MENU
  120. "DIALOG", // 5 RT_DIALOG
  121. "STRING", // 6 RT_STRING
  122. "FONTDIR", // 7 RT_FONTDIR
  123. "FONT", // 8 RT_FONT
  124. "ACCELERATOR", // 9 RT_ACCELERATOR
  125. "RCDATA", // 10 RT_RCDATA
  126. "MESSAGETABLE", // 11 RT_MESSAGETABLE
  127. "GROUP_CURSOR", // 12 RT_GROUP_CURSOR
  128. NULL, // 13 RT_NEWBITMAP -- according to NT
  129. "GROUP_ICON", // 14 RT_GROUP_ICON
  130. NULL, // 15 RT_NAMETABLE
  131. "VERSION", // 16 RT_VERSION
  132. "DIALOGEX", // 17 RT_DIALOGEX ;internal
  133. "DLGINCLUDE", // 18 RT_DLGINCLUDE
  134. "PLUGPLAY", // 19 RT_PLUGPLAY
  135. "VXD", // 20 RT_VXD
  136. "ANICURSOR", // 21 RT_ANICURSOR ;internal
  137. "ANIICON", // 22 RT_ANIICON ;internal
  138. "HTML" // 23 RT_HTML
  139. };
  140. BOOL
  141. EnumTypesFunc(
  142. HMODULE hModule,
  143. LPSTR lpType,
  144. LPARAM lParam
  145. )
  146. {
  147. if (lParam != -1L) {
  148. printf( "RCDUMP: EnumTypesFunc lParam value incorrect (%ld)\n", lParam );
  149. }
  150. printf( "Type: " );
  151. if ((ULONG_PTR)lpType & 0xFFFF0000) {
  152. printf("%s\n", lpType);
  153. }
  154. else {
  155. WORD wType = (WORD) lpType;
  156. if ((wType > sizeof(pTypeName) / sizeof(char *)) || (pTypeName[wType] == NULL))
  157. printf("%u\n", wType);
  158. else
  159. printf("%s\n", pTypeName[wType]);
  160. }
  161. EnumResourceNames( hModule,
  162. lpType,
  163. EnumNamesFunc,
  164. -2L
  165. );
  166. return TRUE;
  167. }
  168. BOOL
  169. EnumNamesFunc(
  170. HMODULE hModule,
  171. LPCSTR lpType,
  172. LPSTR lpName,
  173. LPARAM lParam
  174. )
  175. {
  176. if (lParam != -2L) {
  177. printf( "RCDUMP: EnumNamesFunc lParam value incorrect (%ld)\n", lParam );
  178. }
  179. printf( " Name: " );
  180. if ((ULONG_PTR)lpName & 0xFFFF0000) {
  181. printf("%s\n", lpName);
  182. } else {
  183. printf( "%u\n", (USHORT)lpName );
  184. }
  185. EnumResourceLanguages( hModule,
  186. lpType,
  187. lpName,
  188. EnumLangsFunc,
  189. -3L
  190. );
  191. return TRUE;
  192. }
  193. BOOL
  194. EnumLangsFunc(
  195. HMODULE hModule,
  196. LPCSTR lpType,
  197. LPCSTR lpName,
  198. WORD language,
  199. LPARAM lParam
  200. )
  201. {
  202. HRSRC hResInfo;
  203. PVOID pv;
  204. HGLOBAL hr;
  205. if (lParam != -3L) {
  206. printf( "RCDUMP: EnumLangsFunc lParam value incorrect (%ld)\n", lParam );
  207. }
  208. printf( " Resource: " );
  209. if ((ULONG_PTR)lpName & 0xFFFF0000) {
  210. printf( "%s . ", lpName );
  211. } else {
  212. printf( "%u . ", (USHORT)lpName );
  213. }
  214. if ((ULONG_PTR)lpType & 0xFFFF0000) {
  215. printf("%s . ", lpType );
  216. }
  217. else {
  218. WORD wType = (WORD) lpType;
  219. if ((wType > sizeof(pTypeName) / sizeof(char *)) || (pTypeName[wType] == NULL))
  220. printf("%u\n", wType);
  221. else
  222. printf("%s\n", pTypeName[wType]);
  223. }
  224. printf( "%08x", language );
  225. hResInfo = FindResourceEx( hModule, lpType, lpName, language );
  226. if (hResInfo == NULL) {
  227. printf( " - FindResourceEx failed, rc == %u\n", GetLastError() );
  228. } else {
  229. hr = LoadResource(hModule, hResInfo);
  230. pv = LockResource(hr);
  231. if (VerboseOutput && pv) {
  232. if (lpType == RT_MESSAGETABLE) {
  233. PMESSAGE_RESOURCE_DATA pmrd;
  234. PMESSAGE_RESOURCE_BLOCK pmrb;
  235. PMESSAGE_RESOURCE_ENTRY pmre;
  236. ULONG i, j;
  237. ULONG cb;
  238. printf("\n");
  239. pmrd = (PMESSAGE_RESOURCE_DATA) pv;
  240. pmrb = &(pmrd->Blocks[0]);
  241. for (i=pmrd->NumberOfBlocks ; i>0 ; i--,pmrb++) {
  242. pmre = (PMESSAGE_RESOURCE_ENTRY)(((char*)pv)+pmrb->OffsetToEntries);
  243. for (j=pmrb->LowId ; j<=pmrb->HighId ; j++) {
  244. if (pmre->Flags & MESSAGE_RESOURCE_UNICODE) {
  245. printf("%d - \"%ws\"\n", j, &(pmre->Text));
  246. } else {
  247. printf("%d - \"%s\"\n", j, &(pmre->Text));
  248. }
  249. pmre = (PMESSAGE_RESOURCE_ENTRY)(((char*)pmre) + pmre->Length);
  250. }
  251. }
  252. } else
  253. if (lpType == RT_STRING) {
  254. int i;
  255. PWCHAR pw;
  256. printf("\n");
  257. pw = (PWCHAR) pv;
  258. for (i=0 ; i<16 ; i++,pw++) {
  259. if (*pw) {
  260. printf("%d - \"%-.*ws\"\n", i+((USHORT)lpName)*16, *pw, pw+1);
  261. pw += *pw;
  262. }
  263. }
  264. } else {
  265. printf( " - hResInfo == %p,\n\t\tAddress == %p - Size == %lu\n",
  266. hResInfo, pv, SizeofResource( hModule, hResInfo )
  267. );
  268. }
  269. } else {
  270. printf( " - hResInfo == %p,\n\t\tAddress == %p - Size == %lu\n",
  271. hResInfo,
  272. pv, SizeofResource( hModule, hResInfo )
  273. );
  274. }
  275. }
  276. return TRUE;
  277. }