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.

349 lines
10 KiB

  1. //=====================================================================
  2. //
  3. // Definition for the standard Mac formats
  4. //
  5. //=====================================================================
  6. #define LPNULL 0L
  7. #define MAXLEVELS 3 // Max number of level in the PE header tree
  8. #define IMAGE_FILE_MACHINE_M68K 0x0268 // Identify the M68K machine signature
  9. #define appleMark 20
  10. #define CODEPAGE (DWORD)-1L // Will assume ansi char set [might be wrong]
  11. #define MENU_TYPE 4 // Map MENU to menu (4)
  12. #define DLOG_TYPE 5 // Map DLOG to dialog (5)
  13. #define DITL_TYPE 17 // Map DITL to 17 since 17 is unused we avoid ID conflicts with DLOG
  14. #define STR_TYPE 6 // Map STR to string table (6)
  15. #define MSG_TYPE 11 // Map STR# and TEXT to message table (11)
  16. #define WIND_TYPE 18 // Map WIND to 18, unknown type, treated like a STR
  17. #define COORDINATE_FACTOR 0.50 // factor of reduction from mac to windows
  18. #define _APPLE_MARK_ "_APPLE_MARK_"
  19. //=====================================================================
  20. // Conversion utility
  21. //=====================================================================
  22. #define MACLONG(x) BYTE x[4]
  23. #define MACWORD(x) BYTE x[2]
  24. BYTE * WordToMacWord(WORD w);
  25. BYTE * LongToMacLong(LONG l);
  26. BYTE * LongToMacOffset(LONG l);
  27. BYTE * WinValToMacVal(WORD w);
  28. LONG __inline MacLongToLong(BYTE * p)
  29. {
  30. LONG l = 0;
  31. BYTE *pl = (BYTE *) &l;
  32. p += 3;
  33. *pl++ = *p--;
  34. *pl++ = *p--;
  35. *pl++ = *p--;
  36. *pl = *p;
  37. return l;
  38. }
  39. LONG __inline MacOffsetToLong(BYTE * p)
  40. {
  41. LONG l = 0;
  42. BYTE *pl = (BYTE *) &l;
  43. p += 2;
  44. *pl++ = *p--;
  45. *pl++ = *p--;
  46. *pl = *p;
  47. return l;
  48. }
  49. WORD __inline MacWordToWord(BYTE * p)
  50. {
  51. WORD w = 0;
  52. BYTE *pw = (BYTE *) &w;
  53. p += 1;
  54. *pw++ = *p--;
  55. *pw = *p;
  56. return w;
  57. }
  58. WORD __inline MacValToWinVal(BYTE * p)
  59. {
  60. return (WORD)(MacWordToWord(p)*COORDINATE_FACTOR);
  61. }
  62. DWORD __inline MemCopy( LPVOID lpTgt, LPVOID lpSrc, DWORD dwSize, DWORD dwMaxTgt)
  63. {
  64. if(!dwSize) // If the user is asking us to copy 0 then
  65. return 1; // do nothing but return 1 so the return test will be succesfull
  66. if(dwMaxTgt>=dwSize) {
  67. memcpy(lpTgt, lpSrc, dwSize);
  68. lpTgt = (BYTE*)lpTgt+dwSize;
  69. return dwSize;
  70. }
  71. return 0;
  72. }
  73. typedef BYTE * * LPLPBYTE;
  74. typedef struct tagMacResHeader
  75. {
  76. MACLONG(mulOffsetToResData);
  77. MACLONG(mulOffsetToResMap);
  78. MACLONG(mulSizeOfResData);
  79. MACLONG(mulSizeOfResMap);
  80. } MACRESHEADER, *PMACRESHEADER;
  81. typedef struct tagMacResMap
  82. {
  83. BYTE reserved[16+4+2];
  84. MACWORD(mwResFileAttribute);
  85. MACWORD(mwOffsetToTypeList);
  86. MACWORD(mwOffsetToNameList);
  87. } MACRESMAP, *PMACRESMAP;
  88. typedef struct tagMacResTypeList
  89. {
  90. BYTE szResName[4];
  91. MACWORD(mwNumOfThisType);
  92. MACWORD(mwOffsetToRefList);
  93. } MACRESTYPELIST, *PMACRESTYPELIST;
  94. typedef struct tagMacResRefList
  95. {
  96. MACWORD(mwResID);
  97. MACWORD(mwOffsetToResName);
  98. BYTE bResAttribute;
  99. BYTE bOffsetToResData[3];
  100. MACLONG(reserved);
  101. } MACRESREFLIST, *PMACRESREFLIST;
  102. typedef struct tagMacToWindowsMap
  103. {
  104. WORD wType;
  105. char szTypeName[5];
  106. WORD wResID;
  107. char szResName[256];
  108. DWORD dwOffsetToData;
  109. DWORD dwSizeOfData;
  110. } MACTOWINDOWSMAP, *PMACTOWINDOWSMAP;
  111. typedef struct tagUpdResList
  112. {
  113. WORD * pTypeId;
  114. BYTE * pTypeName;
  115. WORD * pResId;
  116. BYTE * pResName;
  117. DWORD * pLang;
  118. DWORD * pSize;
  119. struct tagUpdResList* pNext;
  120. } UPDATEDRESLIST, *PUPDATEDRESLIST;
  121. //=============================================================================
  122. //=============================================================================
  123. //
  124. // Dialog structures
  125. //
  126. //=============================================================================
  127. //=============================================================================
  128. typedef struct tagMacWDLG
  129. {
  130. MACLONG(dwStyle);
  131. MACLONG(dwExtStyle);
  132. MACWORD(wNumOfElem);
  133. MACWORD(wX);
  134. MACWORD(wY);
  135. MACWORD(wcX);
  136. MACWORD(wcY);
  137. // more
  138. } MACWDLG, *PMACWDLG;
  139. typedef struct tagMacWDLGI
  140. {
  141. MACLONG(dwStyle);
  142. MACLONG(dwExtStyle);
  143. MACWORD(wX);
  144. MACWORD(wY);
  145. MACWORD(wcX);
  146. MACWORD(wcY);
  147. MACWORD(wID);
  148. // more
  149. } MACWDLGI, *PMACWDLGI;
  150. typedef struct tagMacDLOG
  151. {
  152. MACWORD(wTop);
  153. MACWORD(wLeft);
  154. MACWORD(wBottom);
  155. MACWORD(wRight);
  156. MACWORD(wProcID);
  157. BYTE bVisibile;
  158. BYTE ignored1;
  159. BYTE bGoAway;
  160. BYTE ignored2;
  161. MACLONG(lRefCon);
  162. MACWORD(wRefIdOfDITL);
  163. BYTE bLenOfTitle;
  164. //BYTE Title[];
  165. } MACDLOG, *PMACDLOG;
  166. typedef struct tagMacALRT
  167. {
  168. MACWORD(wTop);
  169. MACWORD(wLeft);
  170. MACWORD(wBottom);
  171. MACWORD(wRight);
  172. MACWORD(wRefIdOfDITL);
  173. MACLONG(lStage);
  174. } MACALRT, *PMACALRT;
  175. typedef struct tagMacDIT
  176. {
  177. MACLONG(lPointer);
  178. MACWORD(wTop);
  179. MACWORD(wLeft);
  180. MACWORD(wBottom);
  181. MACWORD(wRight);
  182. BYTE bType;
  183. BYTE bSizeOfDataType;
  184. } MACDIT, *PMACDIT;
  185. typedef struct tagMacWIND
  186. {
  187. MACWORD(wTop);
  188. MACWORD(wLeft);
  189. MACWORD(wBottom);
  190. MACWORD(wRight);
  191. MACWORD(wProcId);
  192. BYTE bVisibile;
  193. BYTE ignored1;
  194. BYTE bGoAway;
  195. BYTE ignored2;
  196. MACLONG(lRefCon);
  197. BYTE bLenOfTitle;
  198. //BYTE Title[];
  199. } MACWIND, *PMACWIND;
  200. //=============================================================================
  201. //=============================================================================
  202. //
  203. // Menu structures
  204. //
  205. //=============================================================================
  206. //=============================================================================
  207. typedef struct tagMacMenu
  208. {
  209. MACWORD(wId);
  210. MACWORD(wWidth);
  211. MACWORD(wHeigth);
  212. MACWORD(wDefProcId);
  213. MACWORD(wReserved); // must be 0
  214. MACLONG(lEnableFlags);
  215. BYTE bSizeOfTitle;
  216. } MACMENU, *PMACMENU;
  217. typedef struct tagMacMenuItem
  218. {
  219. //BYTE bSizeOfText;
  220. // text
  221. BYTE bIconId;
  222. BYTE bKeyCodeId;
  223. BYTE bKeyCodeMark;
  224. BYTE bCharStyle;
  225. } MACMENUITEM, *PMACMENUITEM;
  226. //=============================================================================
  227. //=============================================================================
  228. //
  229. // PE Header parsing functions
  230. //
  231. //=============================================================================
  232. //=============================================================================
  233. UINT FindMacResourceSection( CFile*, BYTE **, PIMAGE_SECTION_HEADER*, int *);
  234. UINT ParseResourceFile( BYTE * pResFile, PIMAGE_SECTION_HEADER, BYTE **, LONG *, int );
  235. BOOL IsMacResFile ( CFile * pFile );
  236. //=============================================================================
  237. //=============================================================================
  238. //
  239. // Parsing functions
  240. //
  241. //=============================================================================
  242. //=============================================================================
  243. UINT ParseSTR( LPVOID lpImageBuf, DWORD dwImageSize, LPVOID lpBuffer, DWORD dwSize );
  244. UINT ParseTEXT( LPVOID lpImageBuf, DWORD dwImageSize, LPVOID lpBuffer, DWORD dwSize );
  245. UINT ParseSTRNUM( LPVOID lpImageBuf, DWORD dwImageSize, LPVOID lpBuffer, DWORD dwSize );
  246. UINT ParseDLOG( LPVOID lpImageBuf, DWORD dwImageSize, LPVOID lpBuffer, DWORD dwSize );
  247. UINT ParseALRT( LPVOID lpImageBuf, DWORD dwImageSize, LPVOID lpBuffer, DWORD dwSize );
  248. UINT ParseWDLG( LPVOID lpImageBuf, DWORD dwImageSize, LPVOID lpBuffer, DWORD dwSize );
  249. UINT ParseWIND( LPVOID lpImageBuf, DWORD dwImageSize, LPVOID lpBuffer, DWORD dwSize );
  250. UINT ParseWMNU( LPVOID lpImageBuf, DWORD dwImageSize, LPVOID lpBuffer, DWORD dwSize );
  251. UINT ParseMENU( LPVOID lpImageBuf, DWORD dwImageSize, LPVOID lpBuffer, DWORD dwSize );
  252. UINT ParseMBAR( LPVOID lpImageBuf, DWORD dwImageSize, LPVOID lpBuffer, DWORD dwSize );
  253. //=============================================================================
  254. // Used by ParseDLOG and ParseALRT to find the DITL
  255. DWORD FindMacResource( LPSTR pfilename, LPSTR lpType, LPSTR pName );
  256. DWORD FindResourceInResFile( BYTE * pResFile, PIMAGE_SECTION_HEADER pResSection, LPSTR pResType, LPSTR pResName);
  257. UINT ParseDITL( LPVOID lpImageBuf, DWORD dwImageSize, LPVOID lpBuffer, DWORD dwSize );
  258. //=============================================================================
  259. //=============================================================================
  260. //
  261. // Updating functions
  262. //
  263. //=============================================================================
  264. //=============================================================================
  265. UINT UpdateMENU( LPVOID, DWORD, LPVOID, DWORD, LPVOID, DWORD *);
  266. UINT UpdateSTR( LPVOID, DWORD, LPVOID, DWORD, LPVOID, DWORD *);
  267. UINT UpdateSTRNUM( LPVOID, DWORD, LPVOID, DWORD, LPVOID, DWORD *);
  268. UINT UpdateDLOG( LPVOID, DWORD, LPVOID, DWORD, LPVOID, DWORD *);
  269. UINT UpdateALRT( LPVOID, DWORD, LPVOID, DWORD, LPVOID, DWORD *);
  270. UINT UpdateDITL( LPVOID, DWORD, LPVOID, DWORD, LPVOID, DWORD *);
  271. UINT UpdateWDLG( LPVOID, DWORD, LPVOID, DWORD, LPVOID, DWORD *);
  272. UINT UpdateWIND( LPVOID, DWORD, LPVOID, DWORD, LPVOID, DWORD *);
  273. //=============================================================================
  274. //=============================================================================
  275. //
  276. // General helper functions
  277. //
  278. //=============================================================================
  279. //=============================================================================
  280. WORD GetMacWString( WORD **, char *, int );
  281. WORD PutMacWString( WORD *, char *, int );
  282. PUPDATEDRESLIST IsResUpdated( BYTE*, MACRESREFLIST, PUPDATEDRESLIST);
  283. PUPDATEDRESLIST UpdatedResList( LPVOID, UINT );
  284. //=============================================================================
  285. //=============================================================================
  286. //
  287. // Mac to ANSI and back conversion
  288. //
  289. //=============================================================================
  290. //=============================================================================
  291. LPCSTR MacCpToAnsiCp(LPCSTR str);
  292. LPCSTR AnsiCpToMacCp(LPCSTR str);