package com.oracle.truffle.llvm.parser.elf;
import java.util.HashMap;
import java.util.Map;
import org.graalvm.polyglot.io.ByteSequence;
public final class {
private static final int = 40;
private static final int = 64;
public static final class {
private final int ;
private final int ;
private final long ;
private final long ;
private final long ;
private final long ;
private final int ;
private final int ;
private final long ;
private final long ;
private (int shName, int shType, long shFlags, long shAddr, long shOffset, long shSize, int shLink, int shInfo, long shAddralign, long shEntsize) {
assert shSize < Long.MAX_VALUE;
this.shName = shName;
this.shType = shType;
this.shFlags = shFlags;
this.shAddr = shAddr;
this.shOffset = shOffset;
this.shSize = shSize;
this.shLink = shLink;
this.shInfo = shInfo;
this.shAddralign = shAddralign;
this.shEntsize = shEntsize;
}
public int () {
return shType;
}
protected long () {
return shFlags;
}
public String (ElfSectionHeaderTable sht) {
return sht.getString(shName);
}
public long () {
return shOffset;
}
public long () {
return shSize;
}
public int () {
return shLink;
}
public long () {
return shEntsize;
}
public long () {
return shAddr;
}
public long () {
return shAddralign;
}
public long () {
return shEntsize;
}
public long () {
return shFlags;
}
public int () {
return shInfo;
}
public int () {
return shLink;
}
public int () {
return shName;
}
public long () {
return shOffset;
}
public long () {
return shSize;
}
public int () {
return shType;
}
}
private final Entry[] ;
private final Map<Integer, String> ;
private final ByteSequence ;
private (Entry[] entries, ByteSequence stringTable) {
this.entries = entries;
this.stringMap = new HashMap<>();
this.stringTable = stringTable;
}
public static ElfSectionHeaderTable (ElfHeader header, ElfReader buffer) {
Entry[] entries = new Entry[header.getShnum()];
buffer.setPosition((int) header.getShoff());
for (int cntr = 0; cntr < entries.length; cntr++) {
entries[cntr] = readEntry(header, buffer);
}
ByteSequence data = null;
if (header.getShstrndx() < entries.length) {
Entry e = entries[header.getShstrndx()];
if (e.getSize() > 0) {
data = buffer.getStringTable(e.getOffset(), e.getSize());
}
}
return new ElfSectionHeaderTable(entries, data);
}
public Entry[] () {
return entries;
}
public Entry (String name) {
for (Entry e : entries) {
if (e.getName(this).equals(name)) {
return e;
}
}
return null;
}
private String (int ind) {
if (stringTable == null || ind >= stringTable.length()) {
return "";
}
String str = stringMap.get(ind);
if (str == null) {
final StringBuilder buf = new StringBuilder();
int pos = ind;
byte b = stringTable.byteAt(pos++);
while (b != 0) {
buf.append((char) b);
b = stringTable.byteAt(pos++);
}
str = buf.toString();
stringMap.put(ind, str);
}
return str;
}
private static Entry (ElfHeader header, ElfReader buffer) {
if (buffer.is64Bit()) {
return readEntry64(header, buffer);
} else {
return readEntry32(header, buffer);
}
}
private static Entry (ElfHeader header, ElfReader buffer) {
int shName = buffer.getInt();
int shType = buffer.getInt();
long shFlags = buffer.getInt();
long shAddr = buffer.getInt();
long shOffset = buffer.getInt();
long shSize = buffer.getInt();
int shLink = buffer.getInt();
int shInfo = buffer.getInt();
long shAddralign = buffer.getInt();
long shEntsize = buffer.getInt();
buffer.skip(header.getShentsize() - ELF32_SHTENT_SIZE);
return new Entry(shName, shType, shFlags, shAddr, shOffset, shSize, shLink, shInfo, shAddralign, shEntsize);
}
private static Entry (ElfHeader header, ElfReader buffer) {
int shName = buffer.getInt();
int shType = buffer.getInt();
long shFlags = buffer.getLong();
long shAddr = buffer.getLong();
long shOffset = buffer.getLong();
long shSize = buffer.getLong();
int shLink = buffer.getInt();
int shInfo = buffer.getInt();
long shAddralign = buffer.getLong();
long shEntsize = buffer.getLong();
buffer.skip(header.getShentsize() - ELF64_SHTENT_SIZE);
return new Entry(shName, shType, shFlags, shAddr, shOffset, shSize, shLink, shInfo, shAddralign, shEntsize);
}
}