elfMachine function
Returns the ELF e_machine field of a 64-bit little-endian ELF binary
bytes.
Throws a FormatException if bytes is not a valid 64-bit little-endian
ELF header.
Implementation
int elfMachine(Uint8List bytes) {
const expectedPrefix = [0x7f, 0x45, 0x4c, 0x46, 2, 1];
if (bytes.length < 64) {
throw const FormatException('ELF binary is shorter than 64 bytes.');
}
for (var i = 0; i < expectedPrefix.length; i++) {
if (bytes[i] != expectedPrefix[i]) {
throw const FormatException('Not a 64-bit little-endian ELF binary.');
}
}
return ByteData.sublistView(bytes).getUint16(18, Endian.little);
}