001/** 002 * Copyright 2012 Emmanuel Bourg 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http:/**www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package net.jsign.pe; 018 019import java.util.ArrayList; 020import java.util.List; 021 022/** 023 * Characteristics of the section of an executable file. 024 * 025 * @author Emmanuel Bourg 026 * @since 1.0 027 */ 028public enum SectionFlag { 029 030 /** The section should not be padded to the next boundary. This flag is obsolete and is replaced by ALIGN_1BYTES. This is valid only for object files.. */ 031 TYPE_NO_PAD (0x00000008), 032 033 /** The section contains executable code. */ 034 CODE (0x00000020), 035 036 /** The section contains initialized data. */ 037 INITIALIZED_DATA (0x00000040), 038 039 /** The section contains uninitialized data. */ 040 UNINITIALIZED_DATA (0x00000080), 041 042 /** Reserved for future use. */ 043 LNK_OTHER (0x00000100), 044 045 /** The section contains comments or other information. The .drectve section has this type. This is valid for object files only. */ 046 LNK_INFO (0x00000200), 047 048 /** The section will not become part of the image. This is valid only for object files. */ 049 LNK_REMOVE (0x00000800), 050 051 /** The section contains COMDAT data. This is valid only for object files. */ 052 LNK_COMDAT (0x00001000), 053 054 /** The section contains data referenced through the global pointer (GP). */ 055 GPREL (0x00008000), 056 057 /** Reserved for future use. */ 058 MEM_PURGEABLE (0x00020000), 059 060 /** For ARM machine types, the section contains Thumb code. Reserved for future use with other machine types. */ 061 MEM_16BIT (0x00020000), 062 063 /** Reserved for future use. */ 064 MEM_LOCKED (0x00040000), 065 066 /** Reserved for future use. */ 067 MEM_PRELOAD (0x00080000), 068 069 /** Align data on a 1-byte boundary. Valid only for object files. */ 070 ALIGN_1BYTES (0x00100000), 071 072 /** Align data on a 2-byte boundary. Valid only for object files. */ 073 ALIGN_2BYTES (0x00200000), 074 075 /** Align data on a 4-byte boundary. Valid only for object files. */ 076 ALIGN_4BYTES (0x00300000), 077 078 /** Align data on an 8-byte boundary. Valid only for object files. */ 079 ALIGN_8BYTES (0x00400000), 080 081 /** Align data on a 16-byte boundary. Valid only for object files. */ 082 ALIGN_16BYTES (0x00500000), 083 084 /** Align data on a 32-byte boundary. Valid only for object files. */ 085 ALIGN_32BYTES (0x00600000), 086 087 /** Align data on a 64-byte boundary. Valid only for object files. */ 088 ALIGN_64BYTES (0x00700000), 089 090 /** Align data on a 128-byte boundary. Valid only for object files. */ 091 ALIGN_128BYTES (0x00800000), 092 093 /** Align data on a 256-byte boundary. Valid only for object files. */ 094 ALIGN_256BYTES (0x00900000), 095 096 /** Align data on a 512-byte boundary. Valid only for object files. */ 097 ALIGN_512BYTES (0x00A00000), 098 099 /** Align data on a 1024-byte boundary. Valid only for object files. */ 100 ALIGN_1024BYTES (0x00B00000), 101 102 /** Align data on a 2048-byte boundary. Valid only for object files. */ 103 ALIGN_2048BYTES (0x00C00000), 104 105 /** Align data on a 4096-byte boundary. Valid only for object files. */ 106 ALIGN_4096BYTES (0x00D00000), 107 108 /** Align data on an 8192-byte boundary. Valid only for object files. */ 109 ALIGN_8192BYTES (0x00E00000), 110 111 /** The section contains extended relocations. */ 112 LNK_NRELOC_OVFL (0x01000000), 113 114 /** The section can be discarded as needed. */ 115 MEM_DISCARDABLE (0x02000000), 116 117 /** The section cannot be cached. */ 118 MEM_NOT_CACHED (0x04000000), 119 120 /** The section is not pageable. */ 121 MEM_NOT_PAGED (0x08000000), 122 123 /** The section can be shared in memory. */ 124 MEM_SHARED (0x10000000), 125 126 /** The section can be executed as code. */ 127 EXECUTE (0x20000000), 128 129 /** The section can be read. */ 130 READ (0x40000000), 131 132 /** The section can be written to. */ 133 WRITE (0x80000000); 134 135 private final int mask; 136 137 SectionFlag(int mask) { 138 this.mask = mask; 139 } 140 141 static List<SectionFlag> getFlags(int flags) { 142 List<SectionFlag> result = new ArrayList<>(); 143 144 for (SectionFlag flag : values()) { 145 if ((flag.mask & flags) != 0) { 146 result.add(flag); 147 } 148 } 149 150 return result; 151 } 152}