summaryrefslogtreecommitdiffstats
path: root/src/java/jogamp/common/os/elf
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/jogamp/common/os/elf')
-rw-r--r--src/java/jogamp/common/os/elf/ElfHeader.java148
-rw-r--r--src/java/jogamp/common/os/elf/IOUtils.java54
-rw-r--r--src/java/jogamp/common/os/elf/Section.java6
-rw-r--r--src/java/jogamp/common/os/elf/SectionArmAttributes.java100
-rw-r--r--src/java/jogamp/common/os/elf/SectionHeader.java32
5 files changed, 170 insertions, 170 deletions
diff --git a/src/java/jogamp/common/os/elf/ElfHeader.java b/src/java/jogamp/common/os/elf/ElfHeader.java
index 88562cf..d76dbab 100644
--- a/src/java/jogamp/common/os/elf/ElfHeader.java
+++ b/src/java/jogamp/common/os/elf/ElfHeader.java
@@ -53,7 +53,7 @@ import static jogamp.common.os.elf.IOUtils.toHexString;
public class ElfHeader {
/** Size of e_ident array - {@value} */
public static int EI_NIDENT = 16;
-
+
/** ident byte #0 - {@value} */
public static final byte ELFMAG0 = 0x7f;
/** ident byte #1 - {@value} */
@@ -62,13 +62,13 @@ public class ElfHeader {
public static final byte ELFMAG2 = 'L';
/** ident byte #3 - {@value} */
public static final byte ELFMAG3 = 'F';
-
+
/** ident byte #4 */
public static final int EI_CLASS = 4;
public static final byte ELFCLASSNONE = 0;
public static final byte ELFCLASS32 = 1;
public static final byte ELFCLASS64 = 2;
-
+
/** ident byte #5 */
public static final int EI_DATA = 5;
public static final byte ELFDATANONE = 0;
@@ -79,7 +79,7 @@ public class ElfHeader {
public static final int EI_VERSION = 6;
public static final byte EV_NONE = 0;
public static final byte EV_CURRENT = 1;
-
+
/** ident byte #7 */
public static final int EI_OSABI = 7;
/** Unix System V ABI - {@value} */
@@ -114,29 +114,29 @@ public class ElfHeader {
/** Amiga Research OS ABI - {@value} **/
public static final byte ELFOSABI_AROS = 15;
/** The FenixOS highly scalable multi-core OS 64-255 Architecture-specific value range - {@value} */
- public static final byte ELFOSABI_FENIXOS = 16;
-
+ public static final byte ELFOSABI_FENIXOS = 16;
+
/** ident byte #8
* <p>
- * 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.
- * </p>
+ * </p>
*/
public static final int EI_ABIVERSION = 8;
-
+
/**
* ident byte #9 .. ?
* <p>
- * 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.
* </p>
*/
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.
* </p>
* <p>
- * Note: This is not used (anymore)
- * </p>
+ * Note: This is not used (anymore)
+ * </p>
* {@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.
* <p>
* Compatible with legacy (pre version 5) gcc use as EF_ARM_SOFT_FLOAT.
* </p>
* <p>
- * Note: This is not used (anymore)
- * </p>
+ * Note: This is not used (anymore)
+ * </p>
* {@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.
* <p>
- * Note: This is not used (anymore)
- * </p>
+ * Note: This is not used (anymore)
+ * </p>
*/
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<sht.length; i++) {
@@ -526,11 +526,11 @@ public class ElfHeader {
}
return null;
}
-
+
public final String toString() {
return string;
}
-
+
private final String toStringImpl() {
final String machineS;
if( isArm() ) {
@@ -553,13 +553,13 @@ public class ElfHeader {
armFlagsS=", arm[abi "+armABI+", lGCC "+getArmLegacyGCCFlags()+", float "+getArmFloatMode()+"]";
} else {
armFlagsS="";
- }
+ }
return "ElfHeader[vers "+getVersion()+", machine["+getMachine()+machineS+"], bits "+getArchClassBits()+", enc "+encS+
", abi[os "+getOSABI()+", vers "+getOSABIVersion()+"], flags["+toHexString(getFlags())+armFlagsS+"], type "+getType()+", sh-num "+sht.length+"]";
}
-
+
final SectionHeader[] readSectionHeaderTable(RandomAccessFile in) throws IOException, IllegalArgumentException {
- // positioning
+ // positioning
{
final long off = d.getE_shoff(); // absolute offset
if( 0 == off ) {
@@ -572,7 +572,7 @@ public class ElfHeader {
final int size = d.getE_shentsize();
final int num;
int i;
- if( 0 == d.getE_shnum() ) {
+ if( 0 == d.getE_shnum() ) {
// Read 1st table 1st and use it's sh_size
final byte[] buf0 = new byte[size];
readBytes(in, buf0, 0, size);
@@ -608,7 +608,7 @@ public class ElfHeader {
sht[i].initName(strS, sht[i].d.getSh_name());
}
}
-
+
return sht;
- }
+ }
}
diff --git a/src/java/jogamp/common/os/elf/IOUtils.java b/src/java/jogamp/common/os/elf/IOUtils.java
index 8308463..8c7bfd1 100644
--- a/src/java/jogamp/common/os/elf/IOUtils.java
+++ b/src/java/jogamp/common/os/elf/IOUtils.java
@@ -34,15 +34,15 @@ import java.nio.ByteOrder;
class IOUtils {
static final long MAX_INT_VALUE = ( (long) Integer.MAX_VALUE & 0xffffffffL ) ;
-
+
static String toHexString(int i) { return "0x"+Integer.toHexString(i); }
-
+
static String toHexString(long i) { return "0x"+Long.toHexString(i); }
-
+
static int shortToInt(short s) {
return (int)s & 0x0000ffff;
}
-
+
static int long2Int(final long v) {
if( MAX_INT_VALUE < v ) {
throw new IllegalArgumentException("Read uint32 value "+toHexString(v)+" > int32-max "+toHexString(MAX_INT_VALUE));
@@ -53,46 +53,46 @@ class IOUtils {
static void checkBounds(final byte[] sb, final int offset, final int remaining) {
if( offset + remaining > sb.length ) {
throw new IndexOutOfBoundsException("Buffer of size "+sb.length+" cannot hold offset "+offset+" + remaining "+remaining);
- }
+ }
}
-
- static void readBytes(final RandomAccessFile in, final byte[] out, final int offset, final int len)
- throws IOException, IllegalArgumentException
- {
+
+ static void readBytes(final RandomAccessFile in, final byte[] out, final int offset, final int len)
+ throws IOException, IllegalArgumentException
+ {
in.readFully(out, offset, len);
}
-
+
static void seek(final RandomAccessFile in, long newPos) throws IOException {
in.seek(newPos);
}
-
+
static int readUInt32(final byte[] in, final int offset) {
final int v = readInt32(in, offset);
if( 0 > v ) {
- throw new IllegalArgumentException("Read uint32 value "+toHexString(v)+" > int32-max "+toHexString(MAX_INT_VALUE));
+ throw new IllegalArgumentException("Read uint32 value "+toHexString(v)+" > int32-max "+toHexString(MAX_INT_VALUE));
}
return v;
/** Need to fix endian for below path ..
checkBounds(in, offset, 4);
- final byte[] uint = new byte[] { 0, 0, 0, 0, in[offset+0], in[offset+1], in[offset+2], in[offset+3] };
+ final byte[] uint = new byte[] { 0, 0, 0, 0, in[offset+0], in[offset+1], in[offset+2], in[offset+3] };
final ByteBuffer b = ByteBuffer.wrap(uint, 0, 8).order(ByteOrder.nativeOrder());
return b.asLongBuffer().get(0); */
}
-
+
static int readInt32(final byte[] in, final int offset) {
checkBounds(in, offset, 4);
final ByteBuffer b = ByteBuffer.wrap(in, offset, 4).order(ByteOrder.nativeOrder());
return b.asIntBuffer().get(0);
}
-
+
/**
* @param sb byte source buffer to parse
* @param offset offset within byte source buffer to start parsing
- * @param remaining remaining numbers of bytes to parse beginning w/ <code>sb_off</code>,
+ * @param remaining remaining numbers of bytes to parse beginning w/ <code>sb_off</code>,
* which shall not exceed <code>sb.length - offset</code>.
* @param offset_post optional integer array holding offset post parsing
* @return the parsed string
- * @throws IndexOutOfBoundsException if <code>offset + remaining > sb.length</code>.
+ * @throws IndexOutOfBoundsException if <code>offset + remaining > sb.length</code>.
*/
static String getString(final byte[] sb, final int offset, final int remaining, int[] offset_post) throws IndexOutOfBoundsException {
checkBounds(sb, offset, remaining);
@@ -104,14 +104,14 @@ class IOUtils {
}
return s;
}
-
+
/**
* @param sb byte source buffer to parse
* @param offset offset within byte source buffer to start parsing
- * @param remaining remaining numbers of bytes to parse beginning w/ <code>sb_off</code>,
+ * @param remaining remaining numbers of bytes to parse beginning w/ <code>sb_off</code>,
* which shall not exceed <code>sb.length - offset</code>.
* @return the number of parsed strings
- * @throws IndexOutOfBoundsException if <code>offset + remaining > sb.length</code>.
+ * @throws IndexOutOfBoundsException if <code>offset + remaining > sb.length</code>.
*/
static int getStringCount(final byte[] sb, int offset, final int remaining) throws IndexOutOfBoundsException {
checkBounds(sb, offset, remaining);
@@ -120,21 +120,21 @@ class IOUtils {
for(; i < remaining && sb[i + offset] != 0; i++) { }
strnum++;
}
- return strnum;
+ return strnum;
}
-
+
/**
* @param sb byte source buffer to parse
* @param offset offset within byte source buffer to start parsing
- * @param remaining remaining numbers of bytes to parse beginning w/ <code>sb_off</code>,
+ * @param remaining remaining numbers of bytes to parse beginning w/ <code>sb_off</code>,
* which shall not exceed <code>sb.length - offset</code>.
* @return the parsed strings
- * @throws IndexOutOfBoundsException if <code>offset + remaining > sb.length</code>.
+ * @throws IndexOutOfBoundsException if <code>offset + remaining > sb.length</code>.
*/
public static String[] getStrings(final byte[] sb, int offset, final int remaining) throws IndexOutOfBoundsException {
final int strnum = getStringCount(sb, offset, remaining);
// System.err.println("XXX: strnum "+strnum+", sb_off "+sb_off+", sb_len "+sb_len);
-
+
final String[] sa = new String[strnum];
final int[] io_off = new int[] { offset };
for(int i=0; i < strnum; i++) {
@@ -142,7 +142,7 @@ class IOUtils {
sa[i] = getString(sb, io_off[0], remaining - io_off[0], io_off);
// System.err.println(".. "+io_off[0]+"[ "+sa[i]);
}
- return sa;
+ return sa;
}
-
+
}
diff --git a/src/java/jogamp/common/os/elf/Section.java b/src/java/jogamp/common/os/elf/Section.java
index 99c762c..a653668 100644
--- a/src/java/jogamp/common/os/elf/Section.java
+++ b/src/java/jogamp/common/os/elf/Section.java
@@ -32,19 +32,19 @@ public class Section {
public byte[] data;
public int offset;
public int length;
-
+
Section(SectionHeader sh, byte[] data, int offset, int length) {
this.sh = sh;
this.data = data;
this.offset = offset;
this.length = length;
}
-
+
public String toString() {
return "Section["+toSubString()+"]";
}
String toSubString() {
return sh+", data[off "+offset+", len "+length+"/"+data.length+"]";
}
-
+
}
diff --git a/src/java/jogamp/common/os/elf/SectionArmAttributes.java b/src/java/jogamp/common/os/elf/SectionArmAttributes.java
index 7b85bb9..413250a 100644
--- a/src/java/jogamp/common/os/elf/SectionArmAttributes.java
+++ b/src/java/jogamp/common/os/elf/SectionArmAttributes.java
@@ -23,17 +23,17 @@ import java.util.List;
*/
public class SectionArmAttributes extends Section {
public static final byte FORMAT_VERSION_A = 0x41; // 'A';
-
+
public static enum Type {
/** No Value */
- None,
+ None,
/** A Sub-Section - following the 4 byte sub section total size (tag + size + content) - byte order of the ELF file */
SubSection,
/** Null Terminated Byte-String */
NTBS,
ULEB128,
}
-
+
/** ULEB128 Value for {@link Tag#ABI_VFP_args}: FP parameter/result passing conforms to AAPCS, BASE variant. */
public static final byte ABI_VFP_ARGS_IS_BASE_VARIANT = 0;
/** ULEB128 Value for {@link Tag#ABI_VFP_args}: FP parameter/result passing conforms to AAPCS, VFP variant. */
@@ -41,18 +41,18 @@ public class SectionArmAttributes extends Section {
/** ULEB128 Value for {@link Tag#ABI_VFP_args}: FP parameter/result passing conforms to custom toolchain. */
public static final byte ABI_VFP_ARGS_IS_CUSTOM_VARIANT = 2;
/** ULEB128 Value for {@link Tag#ABI_VFP_args}: FP parameter/result passing conforms to both , BASE and VFP variant. */
- public static final byte ABI_VFP_ARGS_IS_BOTH_BASE_AND_VFP_VARIANT = 3;
-
- /**
+ public static final byte ABI_VFP_ARGS_IS_BOTH_BASE_AND_VFP_VARIANT = 3;
+
+ /**
* Returns true if value is either {@link #ABI_VFP_ARGS_IS_VFP_VARIANT} or {@link #ABI_VFP_ARGS_IS_BOTH_BASE_AND_VFP_VARIANT}
* @param v ULEB128 Value from {@link Tag#ABI_VFP_args} attribute
*/
public static final boolean abiVFPArgsAcceptsVFPVariant(byte v) {
return ABI_VFP_ARGS_IS_VFP_VARIANT == v || ABI_VFP_ARGS_IS_BOTH_BASE_AND_VFP_VARIANT == v;
}
-
+
public static enum Tag {
- None(0, Type.None),
+ None(0, Type.None),
File(1, Type.SubSection), Section(2, Type.SubSection), Symbol(3, Type.SubSection),
CPU_raw_name( 4, Type.NTBS ),
CPU_name( 5, Type.NTBS ),
@@ -96,10 +96,10 @@ public class SectionArmAttributes extends Section {
undefined69( 69, Type.None ),
MPextension_use_legacy( 70, Type.ULEB128 )
;
-
+
public final int id;
- public final Type type;
-
+ public final Type type;
+
/** Slow O(n) transition of a native tag value to a Tag. */
public static Tag get(final int id) {
final Tag[] tags = Tag.values();
@@ -117,16 +117,16 @@ public class SectionArmAttributes extends Section {
this.type = type;
}
}
-
+
public static class Attribute {
public final Tag tag;
private final Object value;
-
+
Attribute(Tag tag, Object value) {
this.tag = tag;
this.value = value;
}
-
+
public final boolean isNTBS() {
return Type.NTBS == tag.type;
}
@@ -136,7 +136,7 @@ public class SectionArmAttributes extends Section {
}
throw new IllegalArgumentException("Not NTBS but "+tag.type);
}
-
+
public final boolean isULEB128() {
return Type.ULEB128 == tag.type;
}
@@ -146,41 +146,41 @@ public class SectionArmAttributes extends Section {
}
throw new IllegalArgumentException("Not ULEB128 but "+tag.type);
}
-
+
public String toString() {
return tag+" = "+value;
}
}
-
+
public static class VendorAttributes {
public final String vendor;
public final List<Attribute> attributes;
-
+
VendorAttributes(String vendor, List<Attribute> attributes) {
this.vendor = vendor;
- this.attributes = attributes;
+ this.attributes = attributes;
}
-
+
public String toString() {
return vendor + attributes.toString();
}
}
public final List<VendorAttributes> vendorAttributesList;
-
+
SectionArmAttributes(SectionHeader sh, byte[] data, int offset, int length) throws IndexOutOfBoundsException, IllegalArgumentException {
super(sh, data, offset, length);
this.vendorAttributesList = parse(data, offset, length);
}
-
+
public String toString() {
return "SectionArmAttributes["+super.toSubString()+", "+vendorAttributesList.toString()+"]";
}
-
+
public final Attribute get(Tag tag) {
for(int i=0; i<vendorAttributesList.size(); i++) {
final List<Attribute> attributes = vendorAttributesList.get(i).attributes;
for(int j=0; j<attributes.size(); j++) {
- final Attribute a = attributes.get(j);
+ final Attribute a = attributes.get(j);
if( a.tag == tag ) {
return a;
}
@@ -188,11 +188,11 @@ public class SectionArmAttributes extends Section {
}
return null;
}
-
+
public final List<Attribute> get(String vendor) {
return get(vendorAttributesList, vendor);
}
-
+
static final List<Attribute> get(final List<VendorAttributes> vendorAttributesList, String vendor) {
for(int i=0; i<vendorAttributesList.size(); i++) {
final VendorAttributes vas = vendorAttributesList.get(i);
@@ -202,14 +202,14 @@ public class SectionArmAttributes extends Section {
}
return null;
}
-
+
/**
* @param in byte source buffer to parse
* @param offset offset within byte source buffer to start parsing
- * @param remaining remaining numbers of bytes to parse beginning w/ <code>sb_off</code>,
+ * @param remaining remaining numbers of bytes to parse beginning w/ <code>sb_off</code>,
* which shall not exceed <code>sb.length - offset</code>.
- * @throws IndexOutOfBoundsException if <code>offset + remaining > sb.length</code>.
- * @throws IllegalArgumentException if section parsing failed, i.e. incompatible version or data.
+ * @throws IndexOutOfBoundsException if <code>offset + remaining > sb.length</code>.
+ * @throws IllegalArgumentException if section parsing failed, i.e. incompatible version or data.
*/
static List<VendorAttributes> parse(final byte[] in, final int offset, final int remaining) throws IndexOutOfBoundsException, IllegalArgumentException {
checkBounds(in, offset, remaining);
@@ -218,33 +218,33 @@ public class SectionArmAttributes extends Section {
throw new IllegalArgumentException("ShArmAttr: Not version A, but: "+toHexString(in[i]));
}
i++;
-
+
final List<VendorAttributes> vendorAttributesList = new ArrayList<VendorAttributes>();
-
+
while(i < remaining) {
- final int i_pre = i;
+ final int i_pre = i;
final int secLen = readUInt32(in, i); /* total section size: 4 + string + content, i.e. offset to next section */
i+=4;
-
+
final String vendor;
{
- int[] i_post = new int[] { 0 };
+ int[] i_post = new int[] { 0 };
vendor = getString(in, i, secLen - 4, i_post);
i = i_post[0];
}
-
+
final List<Attribute> attributes = new ArrayList<Attribute>();
-
+
while(i < secLen) {
- int[] i_post = new int[] { 0 };
- parseSub(in, i, secLen - i, i_post, attributes);
+ int[] i_post = new int[] { 0 };
+ parseSub(in, i, secLen - i, i_post, attributes);
i = i_post[0];
}
-
+
if( i_pre + secLen != i ) {
throw new IllegalArgumentException("ShArmAttr: Section length count mismatch, expected "+(i_pre + secLen)+", has "+i);
}
-
+
final List<Attribute> mergeAttribs = get(vendorAttributesList, vendor);
if( null != mergeAttribs ) {
mergeAttribs.addAll(attributes);
@@ -252,21 +252,21 @@ public class SectionArmAttributes extends Section {
vendorAttributesList.add(new VendorAttributes(vendor, attributes));
}
}
-
+
return vendorAttributesList;
}
-
+
/**
* @param in byte source buffer to parse
* @param offset offset within byte source buffer to start parsing
- * @param remaining remaining numbers of bytes to parse beginning w/ <code>sb_off</code>,
+ * @param remaining remaining numbers of bytes to parse beginning w/ <code>sb_off</code>,
* which shall not exceed <code>sb.length - offset</code>.
- * @throws IndexOutOfBoundsException if <code>offset + remaining > sb.length</code>.
- * @throws IllegalArgumentException if section parsing failed, i.e. incompatible version or data.
+ * @throws IndexOutOfBoundsException if <code>offset + remaining > sb.length</code>.
+ * @throws IllegalArgumentException if section parsing failed, i.e. incompatible version or data.
*/
static void parseSub(final byte[] in, final int offset, final int remaining, int[] offset_post, List<Attribute> attributes) throws IndexOutOfBoundsException, IllegalArgumentException {
checkBounds(in, offset, remaining);
-
+
// Starts w/ sub-section Tag
int i = offset;
final int i_sTag = in[i++];
@@ -274,7 +274,7 @@ public class SectionArmAttributes extends Section {
if( null == sTag ) {
throw new IllegalArgumentException("ShArmAttr: Invalid Sub-Section tag (NaT): "+i_sTag);
}
- final int subSecLen; // sub section total size (tag + size + content)
+ final int subSecLen; // sub section total size (tag + size + content)
switch(sTag) {
case File:
case Section:
@@ -295,7 +295,7 @@ public class SectionArmAttributes extends Section {
switch(tag.type) {
case NTBS:
{
- int[] i_post = new int[] { 0 };
+ int[] i_post = new int[] { 0 };
final String value = getString(in, i, subSecLen + offset - i, i_post);
attributes.add(new Attribute(tag, value));
i = i_post[0];
@@ -313,5 +313,5 @@ public class SectionArmAttributes extends Section {
}
}
offset_post[0] = offset + subSecLen;
- }
+ }
}
diff --git a/src/java/jogamp/common/os/elf/SectionHeader.java b/src/java/jogamp/common/os/elf/SectionHeader.java
index 18a3293..fd28d2a 100644
--- a/src/java/jogamp/common/os/elf/SectionHeader.java
+++ b/src/java/jogamp/common/os/elf/SectionHeader.java
@@ -120,7 +120,7 @@ public class SectionHeader {
* {@value}
*/
public static final int SHT_HIUSER = 0xffffffff;
-
+
/**
* {@value}
*/
@@ -141,7 +141,7 @@ public class SectionHeader {
* {@value}
*/
public static final int SHT_ARM_OVERLAYSECTION = 0x70000005;
-
+
/**
* {@value}
*/
@@ -169,14 +169,14 @@ public class SectionHeader {
/**
* {@value}
*/
- public static final short SHN_HIRESERVE = (short)0xffff;
-
+ public static final short SHN_HIRESERVE = (short)0xffff;
+
/** Public access to the raw elf section header */
public final Shdr d;
-
+
private int idx;
private String name;
-
+
SectionHeader(byte[] buf, int offset, int length, int sectionIdx) {
this( ByteBuffer.wrap(buf, 0, buf.length), sectionIdx );
}
@@ -185,11 +185,11 @@ public class SectionHeader {
this.idx = idx;
name = null;
}
-
+
public String toString() {
return "SectionHeader[idx "+idx+", name "+name+", type "+toHexString(getType())+", link "+d.getSh_link()+", info "+toHexString(d.getSh_info())+", flags "+toHexString(getFlags())+"]";
}
-
+
/**
* @param strS the {@link SectionHeader#SHT_STRTAB} section containing all strings
* @param nameOffset name offset within strS
@@ -202,7 +202,7 @@ public class SectionHeader {
public int getIndex() {
return idx;
}
-
+
/** Returns the type of this section. */
public int getType() {
return d.getSh_type();
@@ -212,7 +212,7 @@ public class SectionHeader {
public long getFlags() {
return d.getSh_flags();
}
-
+
/** Returns the size of this section. */
public long getSize() {
return d.getSh_size();
@@ -222,10 +222,10 @@ public class SectionHeader {
public String getName() {
return name;
}
-
+
/**
* Returns the Section referenced w/ this section header
- *
+ *
* @param in file owning the section
* @throws IOException if read error occurs
* @throws IllegalArgumentException if section offset or size mismatch including size &gt; {@link Integer#MAX_VALUE}
@@ -238,10 +238,10 @@ public class SectionHeader {
final byte[] s_buf = new byte[s_size];
return readSectionImpl(in, s_buf, 0, s_size);
}
-
+
/**
* Returns the Section referenced w/ this section header using given byte array.
- *
+ *
* @param in file owning the section
* @param b destination buffer
* @param b_off offset in destination buffer
@@ -260,7 +260,7 @@ public class SectionHeader {
}
return readSectionImpl(in, b, b_off, r_len);
}
-
+
Section readSectionImpl(RandomAccessFile in, byte[] b, int b_off, int r_len) throws IOException, IllegalArgumentException {
final long s_off = d.getSh_offset();
seek(in, s_off);
@@ -270,5 +270,5 @@ public class SectionHeader {
} else {
return new Section(this, b, b_off, r_len);
}
- }
+ }
}