26package org.jau.sys.elf;
28import static org.jau.sys.elf.IOUtils.getString;
29import static org.jau.sys.elf.IOUtils.readUInt32;
30import static org.jau.sys.elf.IOUtils.toHexString;
32import java.util.ArrayList;
35import org.jau.io.Bitstream;
80 public static enum Tag {
130 public static Tag get(
final int id) {
131 final Tag[] tags =
Tag.values();
132 final int tag_count = tags.length;
133 for(
int i=0; i < tag_count; i++) {
134 if( tags[i].
id ==
id ) {
149 private final Object value;
161 return (String) value;
163 throw new IllegalArgumentException(
"Not NTBS but "+
tag.
type);
167 return Type.ULEB128 ==
tag.
type;
171 return ((Byte) value).byteValue();
173 throw new IllegalArgumentException(
"Not ULEB128 but "+
tag.
type);
178 return tag+
" = "+value;
211 for(
int j=0; j<attributes.size(); j++) {
221 public final List<Attribute>
get(
final String vendor) {
225 static final List<Attribute>
get(
final List<VendorAttributes>
vendorAttributesList,
final String vendor) {
228 if( vas.vendor.equals(vendor) ) {
229 return vas.attributes;
244 static List<VendorAttributes> parse(
final SectionHeader
sh,
final byte[] in,
final int offset,
final int remaining)
throws IndexOutOfBoundsException, IllegalArgumentException {
245 Bitstream.checkBounds(in,
offset, remaining);
248 throw new IllegalArgumentException(
"ShArmAttr: Not version A, but: "+toHexString(in[i]));
255 while(i < remaining) {
257 final int secLen = readUInt32(isBigEndian, in, i);
262 final int[] i_post =
new int[] { 0 };
263 vendor = getString(in, i, secLen - 4, i_post);
267 final List<Attribute> attributes =
new ArrayList<Attribute>();
270 final int[] i_post =
new int[] { 0 };
271 parseSub(isBigEndian, in, i, secLen - i, i_post, attributes);
275 if( i_pre + secLen != i ) {
276 throw new IllegalArgumentException(
"ShArmAttr: Section length count mismatch, expected "+(i_pre + secLen)+
", has "+i);
280 if(
null != mergeAttribs ) {
281 mergeAttribs.addAll(attributes);
299 private static void parseSub(
final boolean isBigEndian,
final byte[] in,
final int offset,
final int remaining,
300 final int[] offset_post,
final List<Attribute> attributes)
301 throws IndexOutOfBoundsException, IllegalArgumentException
303 Bitstream.checkBounds(in,
offset, remaining);
307 final int i_sTag = in[i++];
308 final Tag sTag = Tag.get(i_sTag);
310 throw new IllegalArgumentException(
"ShArmAttr: Invalid Sub-Section tag (NaT): "+i_sTag);
317 subSecLen = readUInt32(isBigEndian, in, i);
321 throw new IllegalArgumentException(
"ShArmAttr: Invalid Sub-Section tag: "+sTag);
323 if( Tag.File == sTag ) {
324 while( i <
offset + subSecLen ) {
325 final int i_tag = in[i++];
326 final Tag tag = Tag.get(i_tag);
328 throw new IllegalArgumentException(
"ShArmAttr: Invalid Attribute tag (NaT): "+i_tag);
333 final int[] i_post =
new int[] { 0 };
334 final String value = getString(in, i, subSecLen +
offset - i, i_post);
335 attributes.add(
new Attribute(tag, value));
341 final byte value = in[i++];
342 attributes.add(
new Attribute( tag, Byte.valueOf(value) ) );
346 throw new IllegalArgumentException(
"ShArmAttr: Invalid Attribute tag: "+tag);
350 offset_post[0] =
offset + subSecLen;
final boolean isULEB128()
final List< Attribute > attributes
ARM EABI attributes within section header SectionHeader#SHT_ARM_ATTRIBUTES.
static final byte ABI_VFP_ARGS_IS_BOTH_BASE_AND_VFP_VARIANT
ULEB128 Value for Tag#ABI_VFP_args: FP parameter/result passing conforms to both ,...
static final byte ABI_VFP_ARGS_IS_CUSTOM_VARIANT
ULEB128 Value for Tag#ABI_VFP_args: FP parameter/result passing conforms to custom toolchain.
final List< VendorAttributes > vendorAttributesList
static final byte ABI_VFP_ARGS_IS_BASE_VARIANT
ULEB128 Value for Tag#ABI_VFP_args: FP parameter/result passing conforms to AAPCS,...
static final byte FORMAT_VERSION_A
static final boolean abiVFPArgsAcceptsVFPVariant(final byte v)
Returns true if value is either ABI_VFP_ARGS_IS_VFP_VARIANT or ABI_VFP_ARGS_IS_BOTH_BASE_AND_VFP_VARI...
static final byte ABI_VFP_ARGS_IS_VFP_VARIANT
ULEB128 Value for Tag#ABI_VFP_args: FP parameter/result passing conforms to AAPCS,...
ABI_FP_optimization_goals
Tag(final int id, final Type type)
CPU_unaligned_access
with each byte interpreted as an ULEB128 with closing EOS
SubSection
A Sub-Section - following the 4 byte sub section total size (tag + size + content) - byte order of th...
NTBS
Null Terminated Byte-String.