pef.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /* PEF support for BFD.
  2. Copyright (C) 1999-2022 Free Software Foundation, Inc.
  3. This file is part of BFD, the Binary File Descriptor library.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. #include "sysdep.h"
  17. #include "bfd.h"
  18. #include <stdio.h>
  19. struct bfd_pef_header
  20. {
  21. unsigned long tag1;
  22. unsigned long tag2;
  23. unsigned long architecture;
  24. unsigned long format_version;
  25. unsigned long timestamp;
  26. unsigned long old_definition_version;
  27. unsigned long old_implementation_version;
  28. unsigned long current_version;
  29. unsigned short section_count;
  30. unsigned short instantiated_section_count;
  31. unsigned long reserved;
  32. };
  33. typedef struct bfd_pef_header bfd_pef_header;
  34. struct bfd_pef_loader_header
  35. {
  36. long main_section;
  37. unsigned long main_offset;
  38. long init_section;
  39. unsigned long init_offset;
  40. long term_section;
  41. unsigned long term_offset;
  42. unsigned long imported_library_count;
  43. unsigned long total_imported_symbol_count;
  44. unsigned long reloc_section_count;
  45. unsigned long reloc_instr_offset;
  46. unsigned long loader_strings_offset;
  47. unsigned long export_hash_offset;
  48. unsigned long export_hash_table_power;
  49. unsigned long exported_symbol_count;
  50. };
  51. typedef struct bfd_pef_loader_header bfd_pef_loader_header;
  52. struct bfd_pef_imported_library
  53. {
  54. unsigned long name_offset;
  55. unsigned long old_implementation_version;
  56. unsigned long current_version;
  57. unsigned long imported_symbol_count;
  58. unsigned long first_imported_symbol;
  59. unsigned char options;
  60. unsigned char reserved_a;
  61. unsigned short reserved_b;
  62. };
  63. typedef struct bfd_pef_imported_library bfd_pef_imported_library;
  64. enum bfd_pef_imported_library_options
  65. {
  66. BFD_PEF_WEAK_IMPORT_LIB = 0x40,
  67. BFD_PEF_INIT_LIB_BEFORE = 0x80
  68. };
  69. struct bfd_pef_imported_symbol
  70. {
  71. unsigned char symbol_class;
  72. unsigned long name;
  73. };
  74. typedef struct bfd_pef_imported_symbol bfd_pef_imported_symbol;
  75. enum bfd_pef_imported_symbol_class
  76. {
  77. BFD_PEF_CODE_SYMBOL = 0x00,
  78. BFD_PEF_DATA_SYMBOL = 0x01,
  79. BFD_PEF_TVECTOR_SYMBOL = 0x02,
  80. BFD_PEF_TOC_SYMBOL = 0x03,
  81. BFD_PEF_GLUE_SYMBOL = 0x04,
  82. BFD_PEF_UNDEFINED_SYMBOL = 0x0F,
  83. BFD_PEF_WEAK_IMPORT_SYMBOL_MASK = 0x80
  84. };
  85. #define BFD_PEF_TAG1 0x4A6F7921 /* 'Joy!' */
  86. #define BFD_PEF_TAG2 0x70656666 /* 'peff' */
  87. #define BFD_PEF_VERSION 0x00000001
  88. struct bfd_pef_section
  89. {
  90. long name_offset;
  91. unsigned long header_offset;
  92. unsigned long default_address;
  93. unsigned long total_length;
  94. unsigned long unpacked_length;
  95. unsigned long container_length;
  96. unsigned long container_offset;
  97. unsigned char section_kind;
  98. unsigned char share_kind;
  99. unsigned char alignment;
  100. unsigned char reserved;
  101. asection *bfd_section;
  102. };
  103. typedef struct bfd_pef_section bfd_pef_section;
  104. #define BFD_PEF_SECTION_CODE 0
  105. #define BFD_PEF_SECTION_UNPACKED_DATA 1
  106. #define BFD_PEF_SECTION_PACKED_DATA 2
  107. #define BFD_PEF_SECTION_CONSTANT 3
  108. #define BFD_PEF_SECTION_LOADER 4
  109. #define BFD_PEF_SECTION_DEBUG 5
  110. #define BFD_PEF_SECTION_EXEC_DATA 6
  111. #define BFD_PEF_SECTION_EXCEPTION 7
  112. #define BFD_PEF_SECTION_TRACEBACK 8
  113. #define BFD_PEF_SHARE_PROCESS 1
  114. #define BFD_PEF_SHARE_GLOBAL 4
  115. #define BFD_PEF_SHARE_PROTECTED 5
  116. struct bfd_pef_data_struct
  117. {
  118. bfd_pef_header header;
  119. bfd_pef_section *sections;
  120. bfd *ibfd;
  121. };
  122. typedef struct bfd_pef_data_struct bfd_pef_data_struct;
  123. #define BFD_PEF_XLIB_TAG1 0xF04D6163 /* '?Mac' */
  124. #define BFD_PEF_VLIB_TAG2 0x564C6962 /* 'VLib' */
  125. #define BFD_PEF_BLIB_TAG2 0x424C6962 /* 'BLib' */
  126. #define BFD_PEF_XLIB_VERSION 0x00000001
  127. struct bfd_pef_xlib_header
  128. {
  129. unsigned long tag1;
  130. unsigned long tag2;
  131. unsigned long current_format;
  132. unsigned long container_strings_offset;
  133. unsigned long export_hash_offset;
  134. unsigned long export_key_offset;
  135. unsigned long export_symbol_offset;
  136. unsigned long export_names_offset;
  137. unsigned long export_hash_table_power;
  138. unsigned long exported_symbol_count;
  139. unsigned long frag_name_offset;
  140. unsigned long frag_name_length;
  141. unsigned long dylib_path_offset;
  142. unsigned long dylib_path_length;
  143. unsigned long cpu_family;
  144. unsigned long cpu_model;
  145. unsigned long date_time_stamp;
  146. unsigned long current_version;
  147. unsigned long old_definition_version;
  148. unsigned long old_implementation_version;
  149. };
  150. typedef struct bfd_pef_xlib_header bfd_pef_xlib_header;
  151. struct bfd_pef_xlib_data_struct
  152. {
  153. bfd_pef_xlib_header header;
  154. };
  155. typedef struct bfd_pef_xlib_data_struct bfd_pef_xlib_data_struct;
  156. int bfd_pef_parse_loader_header (bfd *, unsigned char *, size_t, bfd_pef_loader_header *);
  157. int bfd_pef_print_loader_section (bfd *, FILE *);
  158. void bfd_pef_print_loader_header (bfd *, bfd_pef_loader_header *, FILE *);
  159. int bfd_pef_parse_imported_library (bfd *, unsigned char *, size_t, bfd_pef_imported_library *);
  160. int bfd_pef_parse_imported_symbol (bfd *, unsigned char *, size_t, bfd_pef_imported_symbol *);
  161. int bfd_pef_scan_section (bfd *, bfd_pef_section *);
  162. int bfd_pef_scan_start_address (bfd *);
  163. int bfd_pef_scan (bfd *, bfd_pef_header *, bfd_pef_data_struct *);