8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package jdk.tools.jaotc.binformat.pecoff; 25 26 /** 27 * 28 * Support for the creation of Coff files. 29 * Current support is limited to 64 bit x86_64. 30 * 31 */ 32 33 public class PECoff { 34 35 /** 36 * IMAGE_FILE_HEADER structure defines 37 */ 38 public enum IMAGE_FILE_HEADER { 39 Machine( 0, 2), 40 NumberOfSections( 2, 2), 41 TimeDateStamp( 4, 4), 42 PointerToSymbolTable( 8, 4), 43 NumberOfSymbols(12, 4), 44 SizeOfOptionalHeader(16, 2), 45 Characteristics(18, 2); 46 47 public final int off; 48 public final int sz; 49 50 IMAGE_FILE_HEADER(int offset, int size) { 51 this.off = offset; 52 this.sz = size; 53 } 54 55 public static int totalsize = 20; 56 57 /** 58 * IMAGE_FILE_HEADER defines 59 */ 60 61 /** 62 * Machine 63 */ 64 public static final char IMAGE_FILE_MACHINE_UNKNOWN = 0x0; 65 public static final char IMAGE_FILE_MACHINE_AMD64 = 0x8664; 66 67 } 68 69 /** 70 * IMAGE_SECTION_HEADER structure defines 71 */ 72 public enum IMAGE_SECTION_HEADER { 73 Name( 0, 8), 74 PhysicalAddress( 8, 4), 75 VirtualSize( 8, 4), 76 VirtualAddress(12, 4), 77 SizeOfRawData(16, 4), 78 PointerToRawData(20, 4), 79 PointerToRelocations(24, 4), 80 PointerToLinenumbers(28, 4), 81 NumberOfRelocations(32, 2), 82 NumberOfLinenumbers(34, 2), 83 Characteristics(36, 4); 84 85 public final int off; 86 public final int sz; 87 88 IMAGE_SECTION_HEADER(int offset, int size) { 89 this.off = offset; 90 this.sz = size; 91 } 92 93 public static int totalsize = 40; 94 95 /** 96 * IMAGE_SECTION_HEADER defines 97 */ 98 99 /** 100 * Characteristics 101 */ 102 public static final int IMAGE_SCN_CNT_CODE = 0x20; 103 public static final int IMAGE_SCN_CNT_INITIALIZED_DATA = 0x40; 104 public static final int IMAGE_SCN_CNT_UNINITIALIZED_DATA = 0x80; 105 public static final int IMAGE_SCN_LNK_COMDAT = 0x1000; 106 public static final int IMAGE_SCN_LNK_INFO = 0x200; 107 public static final int IMAGE_SCN_LNK_REMOVE = 0x800; 108 109 public static final int IMAGE_SCN_ALIGN_1BYTES = 0x100000; 110 public static final int IMAGE_SCN_ALIGN_2BYTES = 0x200000; 111 public static final int IMAGE_SCN_ALIGN_4BYTES = 0x300000; 112 public static final int IMAGE_SCN_ALIGN_8BYTES = 0x400000; 113 public static final int IMAGE_SCN_ALIGN_16BYTES = 0x500000; 114 public static final int IMAGE_SCN_ALIGN_32BYTES = 0x600000; 115 public static final int IMAGE_SCN_ALIGN_64BYTES = 0x700000; 116 public static final int IMAGE_SCN_ALIGN_MASK = 0xf00000; 117 public static final int IMAGE_SCN_ALIGN_SHIFT = 20; 118 119 public static final int IMAGE_SCN_LNK_NRELOC_OVFL = 0x01000000; 120 121 public static final int IMAGE_SCN_MEM_SHARED = 0x10000000; 122 public static final int IMAGE_SCN_MEM_EXECUTE = 0x20000000; 123 public static final int IMAGE_SCN_MEM_READ = 0x40000000; 124 public static final int IMAGE_SCN_MEM_WRITE = 0x80000000; 125 126 } 127 128 /** 129 * Symbol table entry definitions 130 * 131 * IMAGE_SYMBOL structure defines 132 */ 133 public enum IMAGE_SYMBOL { 134 ShortName( 0, 8), 135 Short( 0, 4), 136 Long( 4, 4), 137 Value( 8, 4), 138 SectionNumber(12, 2), 139 Type(14, 2), 140 StorageClass(16, 1), 141 NumberOfAuxSymbols(17, 1); 142 143 public final int off; 144 public final int sz; 145 146 IMAGE_SYMBOL(int offset, int size) { 147 this.off = offset; 148 this.sz = size; 149 } 150 151 public static int totalsize = 18; 152 153 /** 154 * Type 155 */ 156 public static final int IMAGE_SYM_DTYPE_NONE = 0x0; 157 public static final int IMAGE_SYM_DTYPE_FUNCTION = 0x20; 158 159 /** 160 * StorageClass 161 */ 162 public static final int IMAGE_SYM_CLASS_NULL = 0x0; 163 public static final int IMAGE_SYM_CLASS_EXTERNAL = 0x2; 164 public static final int IMAGE_SYM_CLASS_STATIC = 0x3; 165 public static final int IMAGE_SYM_CLASS_LABEL = 0x6; 166 167 } 168 169 /** 170 * IMAGE_RELOCATION structure defines 171 */ 172 public enum IMAGE_RELOCATION { 173 VirtualAddress( 0, 4), 174 SymbolTableIndex( 4, 4), 175 Type( 8, 2); 176 177 public final int off; 178 public final int sz; 179 180 IMAGE_RELOCATION(int offset, int size) { 181 this.off = offset; 182 this.sz = size; 183 } 184 185 public static int totalsize = 10; 186 187 /** 188 * Relocation types 189 */ 190 public static final int IMAGE_REL_AMD64_ABSOLUTE = 0x0; 191 public static final int IMAGE_REL_AMD64_ADDR32 = 0x2; 192 public static final int IMAGE_REL_AMD64_ADDR64 = 0x1; 193 public static final int IMAGE_REL_AMD64_REL32 = 0x4; 194 public static final int IMAGE_REL_AMD64_REL32_1 = 0x5; 195 public static final int IMAGE_REL_AMD64_REL32_2 = 0x6; 196 public static final int IMAGE_REL_AMD64_REL32_3 = 0x7; 197 public static final int IMAGE_REL_AMD64_REL32_4 = 0x8; 198 public static final int IMAGE_REL_AMD64_REL32_5 = 0x9; 199 200 } 201 202 } | 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package jdk.tools.jaotc.binformat.pecoff; 25 26 /** 27 * 28 * Support for the creation of Coff files. Current support is limited to 64 bit x86_64. 29 * 30 */ 31 32 final class PECoff { 33 //@formatter:off 34 /** 35 * IMAGE_FILE_HEADER structure defines 36 */ 37 enum IMAGE_FILE_HEADER { 38 Machine( 0, 2), 39 NumberOfSections( 2, 2), 40 TimeDateStamp( 4, 4), 41 PointerToSymbolTable( 8, 4), 42 NumberOfSymbols(12, 4), 43 SizeOfOptionalHeader(16, 2), 44 Characteristics(18, 2); 45 46 final int off; 47 final int sz; 48 49 IMAGE_FILE_HEADER(int offset, int size) { 50 this.off = offset; 51 this.sz = size; 52 } 53 54 static int totalsize = 20; 55 56 /** 57 * IMAGE_FILE_HEADER defines 58 */ 59 60 /** 61 * Machine 62 */ 63 static final char IMAGE_FILE_MACHINE_UNKNOWN = 0x0; 64 static final char IMAGE_FILE_MACHINE_AMD64 = 0x8664; 65 66 } 67 68 /** 69 * IMAGE_SECTION_HEADER structure defines 70 */ 71 enum IMAGE_SECTION_HEADER { 72 Name( 0, 8), 73 PhysicalAddress( 8, 4), 74 VirtualSize( 8, 4), 75 VirtualAddress(12, 4), 76 SizeOfRawData(16, 4), 77 PointerToRawData(20, 4), 78 PointerToRelocations(24, 4), 79 PointerToLinenumbers(28, 4), 80 NumberOfRelocations(32, 2), 81 NumberOfLinenumbers(34, 2), 82 Characteristics(36, 4); 83 84 final int off; 85 final int sz; 86 87 IMAGE_SECTION_HEADER(int offset, int size) { 88 this.off = offset; 89 this.sz = size; 90 } 91 92 static int totalsize = 40; 93 94 /** 95 * IMAGE_SECTION_HEADER defines 96 */ 97 98 /** 99 * Characteristics 100 */ 101 static final int IMAGE_SCN_CNT_CODE = 0x20; 102 static final int IMAGE_SCN_CNT_INITIALIZED_DATA = 0x40; 103 static final int IMAGE_SCN_CNT_UNINITIALIZED_DATA = 0x80; 104 static final int IMAGE_SCN_LNK_COMDAT = 0x1000; 105 static final int IMAGE_SCN_LNK_INFO = 0x200; 106 static final int IMAGE_SCN_LNK_REMOVE = 0x800; 107 108 static final int IMAGE_SCN_ALIGN_1BYTES = 0x100000; 109 static final int IMAGE_SCN_ALIGN_2BYTES = 0x200000; 110 static final int IMAGE_SCN_ALIGN_4BYTES = 0x300000; 111 static final int IMAGE_SCN_ALIGN_8BYTES = 0x400000; 112 static final int IMAGE_SCN_ALIGN_16BYTES = 0x500000; 113 static final int IMAGE_SCN_ALIGN_32BYTES = 0x600000; 114 static final int IMAGE_SCN_ALIGN_64BYTES = 0x700000; 115 static final int IMAGE_SCN_ALIGN_128BYTES = 0x800000; 116 static final int IMAGE_SCN_ALIGN_256BYTES = 0x900000; 117 static final int IMAGE_SCN_ALIGN_512BYTES = 0xa00000; 118 static final int IMAGE_SCN_ALIGN_1024BYTES = 0xb00000; 119 static final int IMAGE_SCN_ALIGN_MASK = 0xf00000; 120 static final int IMAGE_SCN_ALIGN_SHIFT = 20; 121 122 static final int IMAGE_SCN_LNK_NRELOC_OVFL = 0x01000000; 123 124 static final int IMAGE_SCN_MEM_SHARED = 0x10000000; 125 static final int IMAGE_SCN_MEM_EXECUTE = 0x20000000; 126 static final int IMAGE_SCN_MEM_READ = 0x40000000; 127 static final int IMAGE_SCN_MEM_WRITE = 0x80000000; 128 129 } 130 131 /** 132 * Symbol table entry definitions 133 * 134 * IMAGE_SYMBOL structure defines 135 */ 136 enum IMAGE_SYMBOL { 137 ShortName( 0, 8), 138 Short( 0, 4), 139 Long( 4, 4), 140 Value( 8, 4), 141 SectionNumber(12, 2), 142 Type(14, 2), 143 StorageClass(16, 1), 144 NumberOfAuxSymbols(17, 1); 145 146 final int off; 147 final int sz; 148 149 IMAGE_SYMBOL(int offset, int size) { 150 this.off = offset; 151 this.sz = size; 152 } 153 154 static int totalsize = 18; 155 156 /** 157 * Type 158 */ 159 static final int IMAGE_SYM_DTYPE_NONE = 0x0; 160 static final int IMAGE_SYM_DTYPE_FUNCTION = 0x20; 161 162 /** 163 * StorageClass 164 */ 165 static final int IMAGE_SYM_CLASS_NULL = 0x0; 166 static final int IMAGE_SYM_CLASS_EXTERNAL = 0x2; 167 static final int IMAGE_SYM_CLASS_STATIC = 0x3; 168 static final int IMAGE_SYM_CLASS_LABEL = 0x6; 169 170 } 171 172 /** 173 * IMAGE_RELOCATION structure defines 174 */ 175 enum IMAGE_RELOCATION { 176 VirtualAddress( 0, 4), 177 SymbolTableIndex( 4, 4), 178 Type( 8, 2); 179 180 final int off; 181 final int sz; 182 183 IMAGE_RELOCATION(int offset, int size) { 184 this.off = offset; 185 this.sz = size; 186 } 187 188 static int totalsize = 10; 189 190 /** 191 * Relocation types 192 */ 193 static final int IMAGE_REL_AMD64_ABSOLUTE = 0x0; 194 static final int IMAGE_REL_AMD64_ADDR32 = 0x2; 195 static final int IMAGE_REL_AMD64_ADDR64 = 0x1; 196 static final int IMAGE_REL_AMD64_REL32 = 0x4; 197 static final int IMAGE_REL_AMD64_REL32_1 = 0x5; 198 static final int IMAGE_REL_AMD64_REL32_2 = 0x6; 199 static final int IMAGE_REL_AMD64_REL32_3 = 0x7; 200 static final int IMAGE_REL_AMD64_REL32_4 = 0x8; 201 static final int IMAGE_REL_AMD64_REL32_5 = 0x9; 202 203 } 204 //@formatter:on 205 } |