res32.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. /*
  2. * Builtin dlls resource support
  3. *
  4. * Copyright 2000 Alexandre Julliard
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  19. */
  20. #include "config.h"
  21. #include <assert.h>
  22. #include <ctype.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <stdarg.h>
  26. #include <stdio.h>
  27. #include "build.h"
  28. typedef unsigned short WCHAR;
  29. /* Unicode string or integer id */
  30. struct string_id
  31. {
  32. WCHAR *str; /* ptr to Unicode string */
  33. unsigned int len; /* len in characters */
  34. unsigned short id; /* integer id if str is NULL */
  35. };
  36. /* descriptor for a resource */
  37. struct resource
  38. {
  39. struct string_id type;
  40. struct string_id name;
  41. const void *data;
  42. unsigned int data_size;
  43. unsigned int data_offset;
  44. unsigned short mem_options;
  45. unsigned short lang;
  46. unsigned int version;
  47. };
  48. /* name level of the resource tree */
  49. struct res_name
  50. {
  51. const struct string_id *name; /* name */
  52. struct resource *res; /* resource */
  53. int nb_languages; /* number of languages */
  54. unsigned int dir_offset; /* offset of directory in resource dir */
  55. unsigned int name_offset; /* offset of name in resource dir */
  56. };
  57. /* type level of the resource tree */
  58. struct res_type
  59. {
  60. const struct string_id *type; /* type name */
  61. struct res_name *names; /* names array */
  62. unsigned int nb_names; /* total number of names */
  63. unsigned int nb_id_names; /* number of names that have a numeric id */
  64. unsigned int dir_offset; /* offset of directory in resource dir */
  65. unsigned int name_offset; /* offset of type name in resource dir */
  66. };
  67. /* top level of the resource tree */
  68. struct res_tree
  69. {
  70. struct res_type *types; /* types array */
  71. unsigned int nb_types; /* total number of types */
  72. };
  73. /* size of a resource directory with n entries */
  74. #define RESOURCE_DIR_SIZE (4 * sizeof(unsigned int))
  75. #define RESOURCE_DIR_ENTRY_SIZE (2 * sizeof(unsigned int))
  76. #define RESOURCE_DATA_ENTRY_SIZE (4 * sizeof(unsigned int))
  77. #define RESDIR_SIZE(n) (RESOURCE_DIR_SIZE + (n) * RESOURCE_DIR_ENTRY_SIZE)
  78. static inline struct resource *add_resource( DLLSPEC *spec )
  79. {
  80. spec->resources = xrealloc( spec->resources, (spec->nb_resources + 1) * sizeof(spec->resources[0]) );
  81. return &spec->resources[spec->nb_resources++];
  82. }
  83. static struct res_name *add_name( struct res_type *type, struct resource *res )
  84. {
  85. struct res_name *name;
  86. type->names = xrealloc( type->names, (type->nb_names + 1) * sizeof(*type->names) );
  87. name = &type->names[type->nb_names++];
  88. name->name = &res->name;
  89. name->res = res;
  90. name->nb_languages = 1;
  91. if (!name->name->str) type->nb_id_names++;
  92. return name;
  93. }
  94. static struct res_type *add_type( struct res_tree *tree, struct resource *res )
  95. {
  96. struct res_type *type;
  97. tree->types = xrealloc( tree->types, (tree->nb_types + 1) * sizeof(*tree->types) );
  98. type = &tree->types[tree->nb_types++];
  99. type->type = &res->type;
  100. type->names = NULL;
  101. type->nb_names = 0;
  102. type->nb_id_names = 0;
  103. return type;
  104. }
  105. /* get a string from the current resource file */
  106. static void get_string( struct string_id *str )
  107. {
  108. unsigned int i = 0;
  109. size_t start_pos = input_buffer_pos;
  110. WCHAR wc = get_word();
  111. str->len = 0;
  112. if (wc == 0xffff)
  113. {
  114. str->str = NULL;
  115. str->id = get_word();
  116. }
  117. else
  118. {
  119. input_buffer_pos = start_pos;
  120. while (get_word()) str->len++;
  121. str->str = xmalloc( str->len * sizeof(WCHAR) );
  122. input_buffer_pos = start_pos;
  123. while ((wc = get_word())) str->str[i++] = wc;
  124. }
  125. }
  126. /* put a string into the resource file */
  127. static void put_string( const struct string_id *str )
  128. {
  129. if (str->str)
  130. {
  131. unsigned int i;
  132. for (i = 0; i < str->len; i++) put_word( str->str[i] );
  133. put_word( 0 );
  134. }
  135. else
  136. {
  137. put_word( 0xffff );
  138. put_word( str->id );
  139. }
  140. }
  141. static void dump_res_data( const struct resource *res )
  142. {
  143. unsigned int i = 0;
  144. unsigned int size = (res->data_size + 3) & ~3;
  145. if (!size) return;
  146. input_buffer = res->data;
  147. input_buffer_pos = 0;
  148. input_buffer_size = size;
  149. output( "\t.long " );
  150. while (size > 4)
  151. {
  152. if ((i++ % 16) == 15) output( "0x%08x\n\t.long ", get_dword() );
  153. else output( "0x%08x,", get_dword() );
  154. size -= 4;
  155. }
  156. output( "0x%08x\n", get_dword() );
  157. assert( input_buffer_pos == input_buffer_size );
  158. }
  159. /* check the file header */
  160. /* all values must be zero except header size */
  161. static int check_header(void)
  162. {
  163. unsigned int size;
  164. if (get_dword()) return 0; /* data size */
  165. size = get_dword(); /* header size */
  166. if (size == 0x20000000) byte_swapped = 1;
  167. else if (size != 0x20) return 0;
  168. if (get_word() != 0xffff || get_word()) return 0; /* type, must be id 0 */
  169. if (get_word() != 0xffff || get_word()) return 0; /* name, must be id 0 */
  170. if (get_dword()) return 0; /* data version */
  171. if (get_word()) return 0; /* mem options */
  172. if (get_word()) return 0; /* language */
  173. if (get_dword()) return 0; /* version */
  174. if (get_dword()) return 0; /* characteristics */
  175. return 1;
  176. }
  177. /* load the next resource from the current file */
  178. static void load_next_resource( DLLSPEC *spec )
  179. {
  180. unsigned int hdr_size;
  181. struct resource *res = add_resource( spec );
  182. res->data_size = get_dword();
  183. hdr_size = get_dword();
  184. if (hdr_size & 3) fatal_error( "%s header size not aligned\n", input_buffer_filename );
  185. if (hdr_size < 32) fatal_error( "%s invalid header size %u\n", input_buffer_filename, hdr_size );
  186. res->data = input_buffer + input_buffer_pos - 2*sizeof(unsigned int) + hdr_size;
  187. if ((const unsigned char *)res->data < input_buffer ||
  188. (const unsigned char *)res->data >= input_buffer + input_buffer_size)
  189. fatal_error( "%s invalid header size %u\n", input_buffer_filename, hdr_size );
  190. get_string( &res->type );
  191. get_string( &res->name );
  192. if (input_buffer_pos & 2) get_word(); /* align to dword boundary */
  193. get_dword(); /* skip data version */
  194. res->mem_options = get_word();
  195. res->lang = get_word();
  196. res->version = get_dword();
  197. get_dword(); /* skip characteristics */
  198. input_buffer_pos = ((const unsigned char *)res->data - input_buffer) + ((res->data_size + 3) & ~3);
  199. input_buffer_pos = (input_buffer_pos + 3) & ~3;
  200. if (input_buffer_pos > input_buffer_size)
  201. fatal_error( "%s is a truncated file\n", input_buffer_filename );
  202. }
  203. /* load a Win32 .res file */
  204. int load_res32_file( const char *name, DLLSPEC *spec )
  205. {
  206. int ret;
  207. init_input_buffer( name );
  208. if ((ret = check_header()))
  209. {
  210. while (input_buffer_pos < input_buffer_size) load_next_resource( spec );
  211. }
  212. return ret;
  213. }
  214. /* compare two unicode strings/ids */
  215. static int cmp_string( const struct string_id *str1, const struct string_id *str2 )
  216. {
  217. unsigned int i;
  218. if (!str1->str)
  219. {
  220. if (!str2->str) return str1->id - str2->id;
  221. return 1; /* an id compares larger than a string */
  222. }
  223. if (!str2->str) return -1;
  224. for (i = 0; i < str1->len && i < str2->len; i++)
  225. if (str1->str[i] != str2->str[i]) return str1->str[i] - str2->str[i];
  226. return str1->len - str2->len;
  227. }
  228. /* compare two resources for sorting the resource directory */
  229. /* resources are stored first by type, then by name, then by language */
  230. static int cmp_res( const void *ptr1, const void *ptr2 )
  231. {
  232. const struct resource *res1 = ptr1;
  233. const struct resource *res2 = ptr2;
  234. int ret;
  235. if ((ret = cmp_string( &res1->type, &res2->type ))) return ret;
  236. if ((ret = cmp_string( &res1->name, &res2->name ))) return ret;
  237. if ((ret = res1->lang - res2->lang)) return ret;
  238. return res1->version - res2->version;
  239. }
  240. static char *format_res_string( const struct string_id *str )
  241. {
  242. unsigned int i;
  243. char *ret;
  244. if (!str->str) return strmake( "#%04x", str->id );
  245. ret = xmalloc( str->len + 1 );
  246. for (i = 0; i < str->len; i++) ret[i] = str->str[i]; /* dumb W->A conversion */
  247. ret[i] = 0;
  248. return ret;
  249. }
  250. /* get rid of duplicate resources with different versions */
  251. static void remove_duplicate_resources( DLLSPEC *spec )
  252. {
  253. unsigned int i, n;
  254. for (i = n = 0; i < spec->nb_resources; i++, n++)
  255. {
  256. if (i && !cmp_string( &spec->resources[i].type, &spec->resources[i-1].type ) &&
  257. !cmp_string( &spec->resources[i].name, &spec->resources[i-1].name ) &&
  258. spec->resources[i].lang == spec->resources[i-1].lang)
  259. {
  260. if (spec->resources[i].version == spec->resources[i-1].version)
  261. {
  262. char *type_str = format_res_string( &spec->resources[i].type );
  263. char *name_str = format_res_string( &spec->resources[i].name );
  264. error( "winebuild: duplicate resource type %s name %s language %04x version %08x\n",
  265. type_str, name_str, spec->resources[i].lang, spec->resources[i].version );
  266. }
  267. else n--; /* replace the previous one */
  268. }
  269. if (n < i) spec->resources[n] = spec->resources[i];
  270. }
  271. spec->nb_resources = n;
  272. }
  273. /* build the 3-level (type,name,language) resource tree */
  274. static struct res_tree *build_resource_tree( DLLSPEC *spec, unsigned int *dir_size )
  275. {
  276. unsigned int i, k, n, offset, data_offset;
  277. struct res_tree *tree;
  278. struct res_type *type = NULL;
  279. struct res_name *name = NULL;
  280. struct resource *res;
  281. qsort( spec->resources, spec->nb_resources, sizeof(*spec->resources), cmp_res );
  282. remove_duplicate_resources( spec );
  283. tree = xmalloc( sizeof(*tree) );
  284. tree->types = NULL;
  285. tree->nb_types = 0;
  286. for (i = 0; i < spec->nb_resources; i++)
  287. {
  288. if (!i || cmp_string( &spec->resources[i].type, &spec->resources[i-1].type )) /* new type */
  289. {
  290. type = add_type( tree, &spec->resources[i] );
  291. name = add_name( type, &spec->resources[i] );
  292. }
  293. else if (cmp_string( &spec->resources[i].name, &spec->resources[i-1].name )) /* new name */
  294. {
  295. name = add_name( type, &spec->resources[i] );
  296. }
  297. else
  298. {
  299. name->nb_languages++;
  300. }
  301. }
  302. /* compute the offsets */
  303. offset = RESDIR_SIZE( tree->nb_types );
  304. for (i = 0, type = tree->types; i < tree->nb_types; i++, type++)
  305. {
  306. type->dir_offset = offset;
  307. offset += RESDIR_SIZE( type->nb_names );
  308. for (n = 0, name = type->names; n < type->nb_names; n++, name++)
  309. {
  310. name->dir_offset = offset;
  311. offset += RESDIR_SIZE( name->nb_languages );
  312. }
  313. }
  314. data_offset = offset;
  315. offset += spec->nb_resources * RESOURCE_DATA_ENTRY_SIZE;
  316. for (i = 0, type = tree->types; i < tree->nb_types; i++, type++)
  317. {
  318. if (type->type->str)
  319. {
  320. type->name_offset = offset | 0x80000000;
  321. offset += (type->type->len + 1) * sizeof(WCHAR);
  322. }
  323. else type->name_offset = type->type->id;
  324. for (n = 0, name = type->names; n < type->nb_names; n++, name++)
  325. {
  326. if (name->name->str)
  327. {
  328. name->name_offset = offset | 0x80000000;
  329. offset += (name->name->len + 1) * sizeof(WCHAR);
  330. }
  331. else name->name_offset = name->name->id;
  332. for (k = 0, res = name->res; k < name->nb_languages; k++, res++)
  333. {
  334. unsigned int entry_offset = (res - spec->resources) * RESOURCE_DATA_ENTRY_SIZE;
  335. res->data_offset = data_offset + entry_offset;
  336. }
  337. }
  338. }
  339. if (dir_size) *dir_size = (offset + 3) & ~3;
  340. return tree;
  341. }
  342. /* free the resource tree */
  343. static void free_resource_tree( struct res_tree *tree )
  344. {
  345. unsigned int i;
  346. for (i = 0; i < tree->nb_types; i++) free( tree->types[i].names );
  347. free( tree->types );
  348. free( tree );
  349. }
  350. /* output a Unicode string */
  351. static void output_string( const struct string_id *str )
  352. {
  353. unsigned int i;
  354. output( "\t.short 0x%04x", str->len );
  355. for (i = 0; i < str->len; i++) output( ",0x%04x", str->str[i] );
  356. output( " /* " );
  357. for (i = 0; i < str->len; i++) output( "%c", isprint((char)str->str[i]) ? (char)str->str[i] : '?' );
  358. output( " */\n" );
  359. }
  360. /* output a resource directory */
  361. static inline void output_res_dir( unsigned int nb_names, unsigned int nb_ids )
  362. {
  363. output( "\t.long 0\n" ); /* Characteristics */
  364. output( "\t.long 0\n" ); /* TimeDateStamp */
  365. output( "\t.short 0,0\n" ); /* Major/MinorVersion */
  366. output( "\t.short %u,%u\n", /* NumberOfNamed/IdEntries */
  367. nb_names, nb_ids );
  368. }
  369. /* output the resource definitions */
  370. void output_resources( DLLSPEC *spec )
  371. {
  372. int k, nb_id_types;
  373. unsigned int i, n;
  374. struct res_tree *tree;
  375. struct res_type *type;
  376. struct res_name *name;
  377. const struct resource *res;
  378. if (!spec->nb_resources) return;
  379. tree = build_resource_tree( spec, NULL );
  380. /* output the resource directories */
  381. output( "\n/* resources */\n\n" );
  382. output( "\t%s\n", get_asm_rsrc_section() );
  383. output( "\t.align %d\n", get_alignment(get_ptr_size()) );
  384. output( ".L__wine_spec_resources:\n" );
  385. for (i = nb_id_types = 0, type = tree->types; i < tree->nb_types; i++, type++)
  386. if (!type->type->str) nb_id_types++;
  387. output_res_dir( tree->nb_types - nb_id_types, nb_id_types );
  388. /* dump the type directory */
  389. for (i = 0, type = tree->types; i < tree->nb_types; i++, type++)
  390. output( "\t.long 0x%08x,0x%08x\n",
  391. type->name_offset, type->dir_offset | 0x80000000 );
  392. /* dump the names and languages directories */
  393. for (i = 0, type = tree->types; i < tree->nb_types; i++, type++)
  394. {
  395. output_res_dir( type->nb_names - type->nb_id_names, type->nb_id_names );
  396. for (n = 0, name = type->names; n < type->nb_names; n++, name++)
  397. output( "\t.long 0x%08x,0x%08x\n",
  398. name->name_offset, name->dir_offset | 0x80000000 );
  399. for (n = 0, name = type->names; n < type->nb_names; n++, name++)
  400. {
  401. output_res_dir( 0, name->nb_languages );
  402. for (k = 0, res = name->res; k < name->nb_languages; k++, res++)
  403. output( "\t.long 0x%08x,0x%08x\n", res->lang, res->data_offset );
  404. }
  405. }
  406. /* dump the resource data entries */
  407. for (i = 0, res = spec->resources; i < spec->nb_resources; i++, res++)
  408. {
  409. output_rva( ".L__wine_spec_res_%d", i );
  410. output( "\t.long %u,0,0\n", res->data_size );
  411. }
  412. /* dump the name strings */
  413. for (i = 0, type = tree->types; i < tree->nb_types; i++, type++)
  414. {
  415. if (type->type->str) output_string( type->type );
  416. for (n = 0, name = type->names; n < type->nb_names; n++, name++)
  417. if (name->name->str) output_string( name->name );
  418. }
  419. /* resource data */
  420. for (i = 0, res = spec->resources; i < spec->nb_resources; i++, res++)
  421. {
  422. output( "\n\t.align %d\n", get_alignment(4) );
  423. output( ".L__wine_spec_res_%d:\n", i );
  424. dump_res_data( res );
  425. }
  426. if (!is_pe())
  427. {
  428. output( ".L__wine_spec_resources_end:\n" );
  429. output( "\t.byte 0\n" );
  430. }
  431. free_resource_tree( tree );
  432. }
  433. /* output a Unicode string in binary format */
  434. static void output_bin_string( const struct string_id *str )
  435. {
  436. unsigned int i;
  437. put_word( str->len );
  438. for (i = 0; i < str->len; i++) put_word( str->str[i] );
  439. }
  440. /* output a resource directory in binary format */
  441. static inline void output_bin_res_dir( unsigned int nb_names, unsigned int nb_ids )
  442. {
  443. put_dword( 0 ); /* Characteristics */
  444. put_dword( 0 ); /* TimeDateStamp */
  445. put_word( 0 ); /* MajorVersion */
  446. put_word( 0 ); /* MinorVersion */
  447. put_word( nb_names ); /* NumberOfNamedEntries */
  448. put_word( nb_ids ); /* NumberOfIdEntries */
  449. }
  450. /* output the resource definitions in binary format */
  451. void output_bin_resources( DLLSPEC *spec, unsigned int start_rva )
  452. {
  453. int k, nb_id_types;
  454. unsigned int i, n, data_offset;
  455. struct res_tree *tree;
  456. struct res_type *type;
  457. struct res_name *name;
  458. const struct resource *res;
  459. if (!spec->nb_resources) return;
  460. tree = build_resource_tree( spec, &data_offset );
  461. init_output_buffer();
  462. /* output the resource directories */
  463. for (i = nb_id_types = 0, type = tree->types; i < tree->nb_types; i++, type++)
  464. if (!type->type->str) nb_id_types++;
  465. output_bin_res_dir( tree->nb_types - nb_id_types, nb_id_types );
  466. /* dump the type directory */
  467. for (i = 0, type = tree->types; i < tree->nb_types; i++, type++)
  468. {
  469. put_dword( type->name_offset );
  470. put_dword( type->dir_offset | 0x80000000 );
  471. }
  472. /* dump the names and languages directories */
  473. for (i = 0, type = tree->types; i < tree->nb_types; i++, type++)
  474. {
  475. output_bin_res_dir( type->nb_names - type->nb_id_names, type->nb_id_names );
  476. for (n = 0, name = type->names; n < type->nb_names; n++, name++)
  477. {
  478. put_dword( name->name_offset );
  479. put_dword( name->dir_offset | 0x80000000 );
  480. }
  481. for (n = 0, name = type->names; n < type->nb_names; n++, name++)
  482. {
  483. output_bin_res_dir( 0, name->nb_languages );
  484. for (k = 0, res = name->res; k < name->nb_languages; k++, res++)
  485. {
  486. put_dword( res->lang );
  487. put_dword( res->data_offset );
  488. }
  489. }
  490. }
  491. /* dump the resource data entries */
  492. for (i = 0, res = spec->resources; i < spec->nb_resources; i++, res++)
  493. {
  494. put_dword( data_offset + start_rva );
  495. put_dword( res->data_size );
  496. put_dword( 0 );
  497. put_dword( 0 );
  498. data_offset += (res->data_size + 3) & ~3;
  499. }
  500. /* dump the name strings */
  501. for (i = 0, type = tree->types; i < tree->nb_types; i++, type++)
  502. {
  503. if (type->type->str) output_bin_string( type->type );
  504. for (n = 0, name = type->names; n < type->nb_names; n++, name++)
  505. if (name->name->str) output_bin_string( name->name );
  506. }
  507. /* resource data */
  508. align_output( 4 );
  509. for (i = 0, res = spec->resources; i < spec->nb_resources; i++, res++)
  510. {
  511. put_data( res->data, res->data_size );
  512. align_output( 4 );
  513. }
  514. free_resource_tree( tree );
  515. }
  516. static unsigned int get_resource_header_size( const struct resource *res )
  517. {
  518. unsigned int size = 5 * sizeof(unsigned int) + 2 * sizeof(unsigned short);
  519. if (!res->type.str) size += 2 * sizeof(unsigned short);
  520. else size += (res->type.len + 1) * sizeof(WCHAR);
  521. if (!res->name.str) size += 2 * sizeof(unsigned short);
  522. else size += (res->name.len + 1) * sizeof(WCHAR);
  523. return size;
  524. }
  525. /* output the resources into a .o file */
  526. void output_res_o_file( DLLSPEC *spec )
  527. {
  528. unsigned int i;
  529. char *res_file = NULL;
  530. struct strarray args;
  531. if (!spec->nb_resources) fatal_error( "--resources mode needs at least one resource file as input\n" );
  532. if (!output_file_name) fatal_error( "No output file name specified\n" );
  533. qsort( spec->resources, spec->nb_resources, sizeof(*spec->resources), cmp_res );
  534. remove_duplicate_resources( spec );
  535. byte_swapped = 0;
  536. init_output_buffer();
  537. put_dword( 0 ); /* ResSize */
  538. put_dword( 32 ); /* HeaderSize */
  539. put_word( 0xffff ); /* ResType */
  540. put_word( 0x0000 );
  541. put_word( 0xffff ); /* ResName */
  542. put_word( 0x0000 );
  543. put_dword( 0 ); /* DataVersion */
  544. put_word( 0 ); /* Memory options */
  545. put_word( 0 ); /* Language */
  546. put_dword( 0 ); /* Version */
  547. put_dword( 0 ); /* Characteristics */
  548. for (i = 0; i < spec->nb_resources; i++)
  549. {
  550. unsigned int header_size = get_resource_header_size( &spec->resources[i] );
  551. put_dword( spec->resources[i].data_size );
  552. put_dword( (header_size + 3) & ~3 );
  553. put_string( &spec->resources[i].type );
  554. put_string( &spec->resources[i].name );
  555. align_output( 4 );
  556. put_dword( 0 );
  557. put_word( spec->resources[i].mem_options );
  558. put_word( spec->resources[i].lang );
  559. put_dword( spec->resources[i].version );
  560. put_dword( 0 );
  561. put_data( spec->resources[i].data, spec->resources[i].data_size );
  562. align_output( 4 );
  563. }
  564. /* if the output file name is a .res too, don't run the results through windres */
  565. if (strendswith( output_file_name, ".res"))
  566. {
  567. flush_output_buffer( output_file_name );
  568. return;
  569. }
  570. res_file = get_temp_file_name( output_file_name, ".res" );
  571. flush_output_buffer( res_file );
  572. args = find_tool( "windres", NULL );
  573. strarray_add( &args, "-i" );
  574. strarray_add( &args, res_file );
  575. strarray_add( &args, "-o" );
  576. strarray_add( &args, output_file_name );
  577. switch (target.cpu)
  578. {
  579. case CPU_i386:
  580. strarray_add( &args, "-F" );
  581. strarray_add( &args, "pe-i386" );
  582. break;
  583. case CPU_x86_64:
  584. strarray_add( &args, "-F" );
  585. strarray_add( &args, "pe-x86-64" );
  586. break;
  587. default:
  588. break;
  589. }
  590. spawn( args );
  591. }