26package org.jau.sys.elf;
28import static org.jau.sys.elf.IOUtils.getString;
29import static org.jau.sys.elf.IOUtils.long2Int;
30import static org.jau.sys.elf.IOUtils.readBytes;
31import static org.jau.sys.elf.IOUtils.seek;
32import static org.jau.sys.elf.IOUtils.toHexString;
34import java.io.IOException;
35import java.io.RandomAccessFile;
36import java.nio.ByteBuffer;
52public class SectionHeader {
168 public static final short SHN_ABS = (short)0xfff1;
184 private final int idx;
187 SectionHeader(
final ElfHeaderPart2 eh,
final byte[] buf,
final int offset,
final int length,
final int sectionIdx) {
188 this( eh, ByteBuffer.wrap(buf, 0, buf.length), sectionIdx );
199 return "SectionHeader[idx "+idx+
", name "+name+
", type "+toHexString(
getType())+
", link "+
raw.getSh_link()+
", info "+toHexString(
raw.getSh_info())+
", flags "+toHexString(
getFlags())+
"]";
206 void initName(
final Section strS,
final int nameOffset)
throws IndexOutOfBoundsException {
207 name = getString(strS.data, strS.offset + nameOffset, strS.length - nameOffset,
null);
217 return raw.getSh_type();
222 return raw.getSh_flags();
227 return raw.getSh_size();
243 final int s_size = long2Int(
raw.getSh_size());
244 if( 0 == s_size || 0 > s_size ) {
245 throw new IllegalArgumentException(
"Shdr["+idx+
"] has invalid int size: "+
raw.getSh_size()+
" -> "+s_size);
247 final byte[] s_buf =
new byte[s_size];
248 return readSectionImpl(in, s_buf, 0, s_size);
262 public Section readSection(
final RandomAccessFile in,
final byte[] b,
final int b_off,
final int r_len)
throws IOException, IllegalArgumentException {
263 final int s_size = long2Int(
raw.getSh_size());
264 if( 0 == s_size || 0 > s_size ) {
265 throw new IllegalArgumentException(
"Shdr["+idx+
"] has invalid int size: "+
raw.getSh_size()+
" -> "+s_size);
267 if( r_len > s_size ) {
268 throw new IllegalArgumentException(
"Shdr["+idx+
"] has only "+s_size+
" bytes, while read request is of "+r_len+
" bytes");
270 return readSectionImpl(in, b, b_off, r_len);
273 Section readSectionImpl(
final RandomAccessFile in,
final byte[] b,
final int b_off,
final int r_len)
throws IOException, IllegalArgumentException {
276 readBytes(in, b, b_off, r_len);
280 return new Section(
this, b, b_off, r_len);
ARM EABI attributes within section header SectionHeader#SHT_ARM_ATTRIBUTES.
static Shdr create(final int mdIdx)
long getSh_offset()
Getter for native field: CType['ElfN_Off' (typedef), size [fixed false, lnx64 8], [int]].