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.

214 lines
4.8 KiB

  1. /****************************************************************************/
  2. /* */
  3. /* READ.C - */
  4. /* */
  5. /* Windows DOS Version 3.2 add resource onto executable */
  6. /* (C) Copyright Microsoft Corporation 1988-1992 */
  7. /* */
  8. /* */
  9. /****************************************************************************/
  10. #include <windows.h>
  11. #include <stdlib.h>
  12. #include "rc.h"
  13. #include "resonexe.h"
  14. //
  15. // Reads a String structure from fhIn
  16. // If the first word is 0xffff then this is an ID
  17. // return the ID instead
  18. //
  19. BOOL
  20. ReadStringOrID(
  21. IN int fhIn,
  22. IN WCHAR *s,
  23. OUT WORD *pOrdinal
  24. )
  25. {
  26. USHORT cb;
  27. WCHAR *pwch;
  28. pwch = s;
  29. *pwch = 0;
  30. *pOrdinal = 0;
  31. MyRead(fhIn, (PUCHAR)s, sizeof(WORD));
  32. if ( *s == ID_WORD) {
  33. //
  34. // an ID
  35. //
  36. MyRead(fhIn, (PUCHAR)pOrdinal, sizeof(WORD));
  37. return IS_ID;
  38. }
  39. else {
  40. //
  41. // a string
  42. //
  43. while (*s) {
  44. s++;
  45. MyRead(fhIn, (PUCHAR)s, sizeof(WCHAR));
  46. }
  47. *(s+1) = 0;
  48. cb = s - pwch;
  49. return IS_STRING;
  50. }
  51. }
  52. CHAR *pTypeName[] = {
  53. NULL, /* 0 */
  54. "CURSOR", /* 1 */
  55. "BITMAP", /* 2 */
  56. "ICON", /* 3 */
  57. "MENU", /* 4 */
  58. "DIALOG", /* 5 */
  59. "STRING", /* 6 */
  60. "FONTDIR", /* 7 */
  61. "FONT", /* 8 */
  62. "ACCELERATOR", /* 9 */
  63. "RCDATA", /* 10 */
  64. "MESSAGETABLE", /* 11 */
  65. "GROUP_CURSOR", /* 12 */
  66. NULL, /* 13 */
  67. "GROUP_ICON", /* 14 */
  68. NULL, /* 15 */
  69. "VERSION", /* 16 */
  70. "DLGINCLUDE" /* 17 */
  71. };
  72. BOOL
  73. ReadRes(
  74. IN int fhIn,
  75. IN ULONG cbInFile,
  76. IN HANDLE hupd
  77. )
  78. /*++
  79. Routine Description:
  80. Arguments:
  81. fhIn - Supplies input file handle.
  82. fhOut - Supplies output file handle.
  83. cbInFile - Supplies size of input file.
  84. Return Value:
  85. fSuccess
  86. --*/
  87. {
  88. WCHAR type[256];
  89. WCHAR name[256];
  90. WORD typeord;
  91. WORD nameord;
  92. ULONG offHere; // input file offset
  93. RESADDITIONAL Additional;
  94. UCHAR Buffer[1024];
  95. PVOID pdata;
  96. //
  97. // Build up Type and Name directories
  98. //
  99. offHere = 0;
  100. while (offHere < cbInFile) {
  101. //
  102. // Get the sizes from the file
  103. //
  104. MyRead(fhIn, (PUCHAR)&Additional.DataSize, sizeof(ULONG));
  105. MyRead(fhIn, (PUCHAR)&Additional.HeaderSize, sizeof(ULONG));
  106. if (Additional.DataSize == 0) {
  107. offHere = MySeek(fhIn, Additional.HeaderSize-2*sizeof(ULONG), SEEK_CUR);
  108. continue;
  109. }
  110. //
  111. // Read the TYPE and NAME
  112. //
  113. ReadStringOrID(fhIn, type, &typeord);
  114. ReadStringOrID(fhIn, name, &nameord);
  115. offHere = MySeek(fhIn, 0, SEEK_CUR);
  116. while (offHere & 3)
  117. offHere = MySeek(fhIn, 1, SEEK_CUR);
  118. //
  119. // Read the rest of the header
  120. //
  121. MyRead(fhIn, (PUCHAR)&Additional.DataVersion,
  122. sizeof(RESADDITIONAL)-2*sizeof(ULONG));
  123. //
  124. // if were converting a win30 resource and this is
  125. // a name table then discard it
  126. //
  127. if (fVerbose) {
  128. if ( typeord == 0) {
  129. printf("Adding resource - Type:%S, ", type);
  130. }
  131. else {
  132. if (typeord <= 17)
  133. printf("Adding resource - Type:%s, ", pTypeName[typeord]);
  134. else
  135. printf("Adding resource - Type:%d, ", typeord);
  136. }
  137. if ( nameord == 0 ) {
  138. printf("Name:%S, ", name);
  139. }
  140. else {
  141. printf("Name:%d, ", nameord);
  142. }
  143. printf("Size:%ld\n", Additional.DataSize);
  144. }
  145. pdata = (PVOID)MyAlloc(Additional.DataSize);
  146. MyRead(fhIn, pdata, Additional.DataSize);
  147. if (typeord == 0) {
  148. if (nameord == 0) {
  149. UpdateResourceW(hupd, type, name,
  150. Additional.LanguageId,
  151. pdata, Additional.DataSize);
  152. }
  153. else {
  154. UpdateResourceW(hupd, type, (LPWSTR)nameord,
  155. Additional.LanguageId,
  156. pdata, Additional.DataSize);
  157. }
  158. }
  159. else {
  160. if (nameord == 0) {
  161. UpdateResourceW(hupd, (LPWSTR)typeord, name,
  162. Additional.LanguageId,
  163. pdata, Additional.DataSize);
  164. }
  165. else {
  166. UpdateResourceW(hupd, (LPWSTR)typeord, (LPWSTR)nameord,
  167. Additional.LanguageId,
  168. pdata, Additional.DataSize);
  169. }
  170. }
  171. offHere = MySeek(fhIn, 0, SEEK_CUR);
  172. while (offHere & 3)
  173. offHere = MySeek(fhIn, 1, SEEK_CUR);
  174. }
  175. return(TRUE);
  176. }