From 791a2749886f02ec7b8db25bf8862e8269b96da5 Mon Sep 17 00:00:00 2001
From: Harvey Harrison
- * This byte identifies the version of the ABI to which the object is targeted.
- * This field is used to distinguish among incompatible versions of an ABI.
- * The interpretation of this version number is dependent on the ABI identified by the EI_OSABI field.
+ * This byte identifies the version of the ABI to which the object is targeted.
+ * This field is used to distinguish among incompatible versions of an ABI.
+ * The interpretation of this version number is dependent on the ABI identified by the EI_OSABI field.
* Applications conforming to this specification use the value 0.
- *
- * Start of padding. - * These bytes are reserved and set to zero. - * Programs which read them should ignore them. + * Start of padding. + * These bytes are reserved and set to zero. + * Programs which read them should ignore them. * The value for EI_PAD will change in the future if currently unused bytes are given meanings. *
*/ public static final int EI_PAD = 9; - + /** * This masks an 8-bit version number, the version of the ABI to which this * ELF file conforms. This ABI is version 5. A value of 0 denotes unknown conformance. @@ -144,27 +144,27 @@ public class ElfHeader { */ public static final int EF_ARM_ABIMASK = 0xFF000000; public static final int EF_ARM_ABISHIFT = 24; - + /** * ARM ABI version 5. * {@value} */ public static final int EF_ARM_ABI5 = 0x05000000; - + /** * The ELF file contains BE-8 code, suitable for execution on an ARM * Architecture v6 processor. This flag must only be set on an executable file. * {@value} */ public static final int EF_ARM_BE8 = 0x00800000; - + /** * Legacy code (ABI version 4 and earlier) generated by gcc-arm-xxx might * use these bits. * {@value} */ public static final int EF_ARM_GCCMASK = 0x00400FFF; - + /** * Set in executable file headers (e_type = ET_EXEC or ET_DYN) to note that * the executable file was built to conform to the hardware floating-point @@ -173,28 +173,28 @@ public class ElfHeader { * Compatible with legacy (pre version 5) gcc use as EF_ARM_VFP_FLOAT. * *- * Note: This is not used (anymore) - *
+ * Note: This is not used (anymore) + * * {@value} */ public static final int EF_ARM_ABI_FLOAT_HARD = 0x00000400; - + /** * Set in executable file headers (e_type = ET_EXEC or ET_DYN) to note * explicitly that the executable file was built to conform to the software * floating-point procedure-call standard (the base standard). If both - * {@link #EF_ARM_ABI_FLOAT_HARD} and {@link #EF_ARM_ABI_FLOAT_SOFT} are clear, + * {@link #EF_ARM_ABI_FLOAT_HARD} and {@link #EF_ARM_ABI_FLOAT_SOFT} are clear, * conformance to the base procedure-call standard is implied. ** Compatible with legacy (pre version 5) gcc use as EF_ARM_SOFT_FLOAT. *
*- * Note: This is not used (anymore) - *
+ * Note: This is not used (anymore) + * * {@value} */ public static final int EF_ARM_ABI_FLOAT_SOFT = 0x00000200; - + /** An unknown type - {@value} */ public static final short ET_NONE = 0; /** A relocatable file - {@value} */ @@ -205,7 +205,7 @@ public class ElfHeader { public static final short ET_DYN = 3; /** A core file - {@value} */ public static final short ET_CORE = 4; - + public static final short EM_NONE = 0; public static final short EM_M32 = 1; public static final short EM_SPARC = 2; @@ -357,34 +357,34 @@ public class ElfHeader { public static final short EM_TILEPRO = 188; public static final short EM_MICROBLAZE = 189; public static final short EM_CUDA = 190; - + public static final boolean isIdentityValid(byte[] ident) { return ELFMAG0 == ident[0] && ELFMAG1 == ident[1] && ELFMAG2 == ident[2] && ELFMAG3 == ident[3] ; } - + /** Public access to the raw elf header */ public final Ehdr d; - + /** Public access to the {@link SectionHeader} */ - public final SectionHeader[] sht; - + public final SectionHeader[] sht; + private final String string; - + /** * Note: The input stream shall stay untouch to be able to read sections! - * + * * @param in input stream of a binary file at position zero * @return - * @throws IOException if reading from the given input stream fails or less then ELF Header size bytes + * @throws IOException if reading from the given input stream fails or less then ELF Header size bytes * @throws IllegalArgumentException if the given input stream does not represent an ELF Header */ public static ElfHeader read(RandomAccessFile in) throws IOException, IllegalArgumentException { final int eh_sz = Ehdr.size(); final byte[] buf = new byte[eh_sz]; - readBytes (in, buf, 0, eh_sz); + readBytes (in, buf, 0, eh_sz); final ElfHeader eh = new ElfHeader(ByteBuffer.wrap(buf, 0, buf.length), in); return eh; } @@ -392,7 +392,7 @@ public class ElfHeader { /** * @param buf ELF Header bytes * @throws IllegalArgumentException if the given buffer does not represent an ELF Header - * @throws IOException + * @throws IOException */ ElfHeader(java.nio.ByteBuffer buf, RandomAccessFile in) throws IllegalArgumentException, IOException { d = Ehdr.create(buf); @@ -404,11 +404,11 @@ public class ElfHeader { } public final short getSize() { return d.getE_ehsize(); } - - /** - * Returns the architecture class in bits, - * 32 for {@link #ELFCLASS32}, 64 for {@link #ELFCLASS64} - * and 0 for {@link #ELFCLASSNONE}. + + /** + * Returns the architecture class in bits, + * 32 for {@link #ELFCLASS32}, 64 for {@link #ELFCLASS64} + * and 0 for {@link #ELFCLASSNONE}. */ public final int getArchClassBits() { switch( d.getE_ident()[EI_CLASS] ) { @@ -417,48 +417,48 @@ public class ElfHeader { default: return 0; } } - - /** - * Returns the processor's data encoding, i.e. - * {@link #ELFDATA2LSB}, {@link #ELFDATA2MSB} or {@link #ELFDATANONE}; + + /** + * Returns the processor's data encoding, i.e. + * {@link #ELFDATA2LSB}, {@link #ELFDATA2MSB} or {@link #ELFDATANONE}; */ public final byte getDataEncodingMode() { return d.getE_ident()[EI_DATA]; } - + /** Returns the ELF file version, should be {@link #EV_CURRENT}. */ public final byte getVersion() { return d.getE_ident()[EI_VERSION]; } - + /** Returns the operating system and ABI for this file, 3 == Linux. Note: Often not used. */ public final byte getOSABI() { return d.getE_ident()[EI_OSABI]; } - + /** Returns the version of the {@link #getOSABI() OSABI} for this file. */ public final byte getOSABIVersion() { return d.getE_ident()[EI_ABIVERSION]; } - /** Returns the object file type, e.g. {@link #ET_EXEC}, .. */ + /** Returns the object file type, e.g. {@link #ET_EXEC}, .. */ public final short getType() { return d.getE_type(); } - /** Returns the required architecture for the file, e.g. {@link #EM_386}, .. */ + /** Returns the required architecture for the file, e.g. {@link #EM_386}, .. */ public final short getMachine() { - return d.getE_machine(); + return d.getE_machine(); } - - /** + + /** * Returns true if {@link #getMachine() machine} is a 32 or 64 bit ARM CPU * of type {@link #EM_ARM}. */ public final boolean isArm() { return getMachine() == EM_ARM; } - - /** + + /** * Returns true if {@link #getMachine() machine} is a 32 or 64 bit Intel CPU * of type {@link #EM_386}, {@link #EM_486} or {@link #EM_X86_64}. */ public final boolean isIntel() { @@ -467,30 +467,30 @@ public class ElfHeader { EM_486 == m || EM_X86_64 == m; } - + /** Returns the processor-specific flags associated with the file. */ public final int getFlags() { return d.getE_flags(); } - + /** Returns the ARM EABI version from {@link #getFlags() flags}, maybe 0 if not an ARM EABI. */ public byte getArmABI() { - return (byte) ( ( ( EF_ARM_ABIMASK & d.getE_flags() ) >> EF_ARM_ABISHIFT ) & 0xff ); + return (byte) ( ( ( EF_ARM_ABIMASK & d.getE_flags() ) >> EF_ARM_ABISHIFT ) & 0xff ); } - + /** Returns the ARM EABI legacy GCC {@link #getFlags() flags}, maybe 0 if not an ARM EABI or not having legacy GCC flags. */ public int getArmLegacyGCCFlags() { final int f = d.getE_flags(); - return 0 != ( EF_ARM_ABIMASK & f ) ? ( EF_ARM_GCCMASK & f ) : 0; + return 0 != ( EF_ARM_ABIMASK & f ) ? ( EF_ARM_GCCMASK & f ) : 0; } - - /** + + /** * Returns the ARM EABI float mode from {@link #getFlags() flags}, * i.e. 1 for {@link #EF_ARM_ABI_FLOAT_SOFT}, 2 for {@link #EF_ARM_ABI_FLOAT_HARD} * or 0 for none. *- * Note: This is not used (anymore) - *
+ * Note: This is not used (anymore) + * */ public byte getArmFloatMode() { final int f = d.getE_flags(); @@ -515,7 +515,7 @@ public class ElfHeader { } return null; } - + /** Returns the 1st occurence of matching SectionHeader {@link SectionHeader#getName() name}, or null if not exists. */ public final SectionHeader getSectionHeader(String name) { for(int i=0; i