use std::fmt;
use Header;
bitflags! {
#[derive(Default)]
pub struct SectionFlags: u64 {
const WRITE = (1 << 0);
const ALLOC = (1 << 1);
const EXECINSTR = (1 << 2);
const MERGE = (1 << 4);
const STRINGS = (1 << 5);
const INFO_LINK = (1 << 6);
const LINK_ORDER = (1 << 7);
const OS_NONCONFORMING = (1 << 8);
const GROUP = (1 << 9);
const TLS = (1 << 10);
const COMPRESSED = (1 << 11);
const MASKOS = 0x0ff00000;
const MASKPROC = 0xf0000000;
const MIPS_GPREL = 0x10000000;
}
}
impl fmt::Display for SectionFlags {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut dstr = String::new();
if self.bits & SectionFlags::WRITE.bits > 0 {
dstr += "W";
}
if self.bits & SectionFlags::ALLOC.bits > 0 {
dstr += "A";
}
if self.bits & SectionFlags::EXECINSTR.bits > 0 {
dstr += "X";
}
if self.bits & SectionFlags::MERGE.bits > 0 {
dstr += "M";
}
if self.bits & SectionFlags::STRINGS.bits > 0 {
dstr += "S";
}
if self.bits & SectionFlags::INFO_LINK.bits > 0 {
dstr += "I";
}
if self.bits & SectionFlags::LINK_ORDER.bits > 0 {
dstr += "L";
}
if self.bits & SectionFlags::OS_NONCONFORMING.bits > 0 {
dstr += "O";
}
if self.bits & SectionFlags::GROUP.bits > 0 {
dstr += "G";
}
if self.bits & SectionFlags::TLS.bits > 0 {
dstr += "T";
}
if self.bits & SectionFlags::COMPRESSED.bits > 0 {
dstr += "C";
}
if self.bits & SectionFlags::MASKOS.bits > 0 {
dstr += "o";
}
if self.bits & SectionFlags::MIPS_GPREL.bits > 0 {
dstr += "g";
}
dstr.fmt(f)
}
}
bitflags! {
#[derive(Default)]
pub struct HeaderFlags: u32 {
const MIPS_NOREORDER = 0x00000001;
const MIPS_PIC = 0x00000002;
const MIPS_CPIC = 0x00000004;
const MIPS_ARCH = 0xf0000000;
const MIPS_ARCH_32 = 0x50000000;
const MIPS_ARCH_64 = 0x60000000;
const MIPS_ARCH_32R2 = 0x70000000;
const MIPS_ARCH_64R2 = 0x80000000;
const MIPS_ABI_O32 = 0x00001000;
const MIPS_ABI_O64 = 0x00002000;
const ARM_EABI_VER1 = 0x01000000;
const ARM_EABI_VER2 = 0x02000000;
const ARM_EABI_VER3 = 0x03000000;
const ARM_EABI_VER4 = 0x04000000;
const ARM_EABI_VER5 = 0x05000000;
const ARM_ABI_FLOAT_HARD = 0x00000400;
const ARM_ABI_FLOAT_SOFT = 0x00000200;
}
}
bitflags! {
#[derive(Default)]
pub struct SegmentFlags: u64 {
const READABLE = (1 << 2);
const WRITABLE = (1 << 1);
const EXECUTABLE = (1 << 0);
}
}
impl fmt::Display for SegmentFlags {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let dstr = format!("{:?}", self);
if dstr == "(empty)" {
return "".fmt(f);
}
let dstr = dstr.split("|")
.map(|s| &s.trim()[0..1])
.fold(String::new(), |acc, s| acc + s);
dstr.fmt(f)
}
}
#[derive(Debug, Primitive, PartialEq, Clone)]
pub enum Endianness {
LittleEndian = 1,
BigEndian = 2,
}
impl Default for Endianness {
fn default() -> Self {
Endianness::LittleEndian
}
}
#[derive(Debug, Primitive, PartialEq, Clone)]
pub enum Class {
Class32 = 1,
Class64 = 2,
}
impl Default for Class {
fn default() -> Self {
Class::Class64
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SectionType(pub u32);
impl SectionType {
pub const NULL: SectionType = SectionType(0);
pub const PROGBITS: SectionType = SectionType(1);
pub const SYMTAB: SectionType = SectionType(2);
pub const STRTAB: SectionType = SectionType(3);
pub const RELA: SectionType = SectionType(4);
pub const HASH: SectionType = SectionType(5);
pub const DYNAMIC: SectionType = SectionType(6);
pub const NOTE: SectionType = SectionType(7);
pub const NOBITS: SectionType = SectionType(8);
pub const REL: SectionType = SectionType(9);
pub const SHLIB: SectionType = SectionType(10);
pub const DYNSYM: SectionType = SectionType(11);
pub const INIT_ARRAY: SectionType = SectionType(14);
pub const FINI_ARRAY: SectionType = SectionType(15);
pub const PREINIT_ARRAY: SectionType = SectionType(16);
pub const GROUP: SectionType = SectionType(17);
pub const SYMTAB_SHNDX: SectionType = SectionType(18);
pub const NUM: SectionType = SectionType(19);
pub const GNU_ATTRIBUTES: SectionType = SectionType(0x6ffffff5);
pub const GNU_HASH: SectionType = SectionType(0x6ffffff6);
pub const GNU_LIBLIST: SectionType = SectionType(0x6ffffff7);
pub const CHECKSUM: SectionType = SectionType(0x6ffffff8);
pub const SUNW_MOVE: SectionType = SectionType(0x6ffffffa);
pub const SUNW_COMDAT: SectionType = SectionType(0x6ffffffb);
pub const SUNW_SYMINFO: SectionType = SectionType(0x6ffffffc);
pub const GNU_VERDEF: SectionType = SectionType(0x6ffffffd);
pub const GNU_VERNEED: SectionType = SectionType(0x6ffffffe);
pub const GNU_VERSYM: SectionType = SectionType(0x6fffffff);
pub const ARM_EXIDX: SectionType = SectionType(0x70000001);
pub const ARM_PREEMPTMAP: SectionType = SectionType(0x70000002);
pub const ARM_ATTRIBUTES: SectionType = SectionType(0x70000003);
pub const ARM_DEBUGOVERLAY: SectionType = SectionType(0x70000004);
pub const ARM_OVERLAYSECTION: SectionType = SectionType(0x70000005);
pub const MIPS_LIBLIST: SectionType = SectionType(0x70000001);
pub const MIPS_CONFLICT: SectionType = SectionType(0x70000002);
pub const MIPS_GPTAB: SectionType = SectionType(0x70000003);
pub const MIPS_UCODE: SectionType = SectionType(0x70000004);
pub const MIPS_DEBUG: SectionType = SectionType(0x70000005);
pub const MIPS_REGINFO: SectionType = SectionType(0x70000006);
pub const RELINKABLE: SectionType = SectionType(0x6fffff01);
pub fn to_u32(&self) -> u32 {
let &SectionType(v) = self;
v
}
pub fn typename(&self, eh: &Header) -> Option<&'static str> {
match (&eh.machine, self) {
(_, &SectionType::NULL) => Some("NULL"),
(_, &SectionType::PROGBITS) => Some("PROGBITS"),
(_, &SectionType::SYMTAB) => Some("SYMTAB"),
(_, &SectionType::STRTAB) => Some("STRTAB"),
(_, &SectionType::RELA) => Some("RELA"),
(_, &SectionType::HASH) => Some("HASH"),
(_, &SectionType::DYNAMIC) => Some("DYNAMIC"),
(_, &SectionType::NOTE) => Some("NOTE"),
(_, &SectionType::NOBITS) => Some("NOBITS"),
(_, &SectionType::REL) => Some("REL"),
(_, &SectionType::SHLIB) => Some("SHLIB"),
(_, &SectionType::DYNSYM) => Some("DYNSYM"),
(_, &SectionType::INIT_ARRAY) => Some("INIT_ARRAY"),
(_, &SectionType::FINI_ARRAY) => Some("FINI_ARRAY"),
(_, &SectionType::PREINIT_ARRAY) => Some("PREINIT_ARRAY"),
(_, &SectionType::GROUP) => Some("GROUP"),
(_, &SectionType::SYMTAB_SHNDX) => Some("SYMTAB_SHNDX"),
(_, &SectionType::NUM) => Some("NUM"),
(_, &SectionType::GNU_ATTRIBUTES) => Some("GNU_ATTRIBUTES"),
(_, &SectionType::GNU_HASH) => Some("GNU_HASH"),
(_, &SectionType::GNU_LIBLIST) => Some("GNU_LIBLIST"),
(_, &SectionType::CHECKSUM) => Some("CHECKSUM"),
(_, &SectionType::SUNW_MOVE) => Some("SUNW_move"),
(_, &SectionType::SUNW_COMDAT) => Some("SUNW_COMDAT"),
(_, &SectionType::SUNW_SYMINFO) => Some("SUNW_syminfo"),
(_, &SectionType::GNU_VERDEF) => Some("GNU_VERDEF"),
(_, &SectionType::GNU_VERNEED) => Some("GNU_VERNEED"),
(_, &SectionType::GNU_VERSYM) => Some("GNU_VERSYM"),
(&Machine::MIPS, &SectionType::MIPS_LIBLIST) => Some("MIPS_LIBLIST"),
(&Machine::MIPS, &SectionType::MIPS_CONFLICT) => Some("MIPS_CONFLICT"),
(&Machine::MIPS, &SectionType::MIPS_GPTAB) => Some("MIPS_GPTAB"),
(&Machine::MIPS, &SectionType::MIPS_UCODE) => Some("MIPS_UCODE"),
(&Machine::MIPS, &SectionType::MIPS_DEBUG) => Some("MIPS_DEBUG"),
(&Machine::MIPS, &SectionType::MIPS_REGINFO) => Some("MIPS_REGINFO"),
(&Machine::ARM, &SectionType::ARM_EXIDX) => Some("ARM_EXIDX"),
(&Machine::ARM, &SectionType::ARM_PREEMPTMAP) => Some("ARM_PREEMPTMAP"),
(&Machine::ARM, &SectionType::ARM_ATTRIBUTES) => Some("ARM_ATTRIBUTES"),
(&Machine::ARM, &SectionType::ARM_DEBUGOVERLAY) => Some("ARM_DEBUGOVERLAY"),
(&Machine::ARM, &SectionType::ARM_OVERLAYSECTION) => Some("ARM_OVERLAYSECTION"),
(_, &SectionType::RELINKABLE) => Some("RELINKABLE"),
(_, _) => None,
}
}
}
impl Default for SectionType {
fn default() -> Self {
SectionType::NULL
}
}
#[allow(non_camel_case_types)]
#[derive(Debug, Primitive, PartialEq, Clone)]
pub enum Abi {
SYSV = 0,
HPUX = 1,
NETBSD = 2,
GNU = 3,
SOLARIS = 6,
AIX = 7,
IRIX = 8,
FREEBSD = 9,
TRU64 = 10,
MODESTO = 11,
OPENBSD = 12,
ARM_AEABI = 64,
ARM = 97,
STANDALONE = 255,
}
impl Default for Abi {
fn default() -> Self {
Abi::SYSV
}
}
#[allow(non_camel_case_types)]
#[derive(Debug, Primitive, PartialEq, Clone)]
pub enum ElfType {
NONE = 0,
REL = 1,
EXEC = 2,
DYN = 3,
CORE = 4,
}
impl Default for ElfType {
fn default() -> Self {
ElfType::NONE
}
}
#[allow(non_camel_case_types)]
#[derive(Debug, Primitive, PartialEq, Clone)]
pub enum SymbolType {
NOTYPE = 0,
OBJECT = 1,
FUNC = 2,
SECTION = 3,
FILE = 4,
COMMON = 5,
TLS = 6,
NUM = 7,
GNU_IFUNC = 10,
}
impl Default for SymbolType {
fn default() -> Self {
SymbolType::NOTYPE
}
}
#[allow(non_camel_case_types)]
#[derive(Debug, Primitive, PartialOrd, Eq, Ord, PartialEq, Clone)]
pub enum SymbolBind {
LOCAL = 0,
GLOBAL = 1,
WEAK = 2,
STB_GNU_UNIQUE = 10,
}
impl Default for SymbolBind {
fn default() -> Self {
SymbolBind::LOCAL
}
}
#[allow(non_camel_case_types)]
#[derive(Debug, Primitive, PartialEq, Clone)]
pub enum SymbolVis {
DEFAULT = 0,
INTERNAL = 1,
HIDDEN = 2,
PROTECTED = 3,
}
impl Default for SymbolVis {
fn default() -> Self {
SymbolVis::DEFAULT
}
}
#[allow(non_camel_case_types)]
#[derive(Debug, Primitive, PartialEq, Clone)]
pub enum Machine {
NONE = 0,
M32 = 1,
SPARC = 2,
EM386 = 3,
EM68K = 4,
EM88K = 5,
IAMCU = 6,
EM860 = 7,
MIPS = 8,
S370 = 9,
MIPS_RS3_LE = 10,
PARISC = 15,
VPP500 = 17,
SPARC32PLUS = 18,
EM960 = 19,
PPC = 20,
PPC64 = 21,
S390 = 22,
SPU = 23,
V800 = 36,
FR20 = 37,
RH32 = 38,
RCE = 39,
ARM = 40,
FAKE_ALPHA = 41,
SH = 42,
SPARCV9 = 43,
TRICORE = 44,
ARC = 45,
H8_300 = 46,
H8_300H = 47,
H8S = 48,
H8_500 = 49,
IA_64 = 50,
MIPS_X = 51,
COLDFIRE = 52,
EM68HC12 = 53,
MMA = 54,
PCP = 55,
NCPU = 56,
NDR1 = 57,
STARCORE = 58,
ME16 = 59,
ST100 = 60,
TINYJ = 61,
X86_64 = 62,
PDSP = 63,
PDP10 = 64,
PDP11 = 65,
FX66 = 66,
ST9PLUS = 67,
ST7 = 68,
EM68HC16 = 69,
EM68HC11 = 70,
EM68HC08 = 71,
EM68HC05 = 72,
SVX = 73,
ST19 = 74,
VAX = 75,
CRIS = 76,
JAVELIN = 77,
FIREPATH = 78,
ZSP = 79,
MMIX = 80,
HUANY = 81,
PRISM = 82,
AVR = 83,
FR30 = 84,
D10V = 85,
D30V = 86,
V850 = 87,
M32R = 88,
MN10300 = 89,
MN10200 = 90,
PJ = 91,
OPENRISC = 92,
ARC_COMPACT = 93,
XTENSA = 94,
VIDEOCORE = 95,
TMM_GPP = 96,
NS32K = 97,
TPC = 98,
SNP1K = 99,
ST200 = 100,
IP2K = 101,
MAX = 102,
CR = 103,
F2MC16 = 104,
MSP430 = 105,
BLACKFIN = 106,
SE_C33 = 107,
SEP = 108,
ARCA = 109,
UNICORE = 110,
EXCESS = 111,
DXP = 112,
ALTERA_NIOS2 = 113,
CRX = 114,
XGATE = 115,
C166 = 116,
M16C = 117,
DSPIC30F = 118,
CE = 119,
M32C = 120,
TSK3000 = 131,
RS08 = 132,
SHARC = 133,
ECOG2 = 134,
SCORE7 = 135,
DSP24 = 136,
VIDEOCORE3 = 137,
LATTICEMIC32 = 138,
SE_C17 = 139,
TI_C6000 = 140,
TI_C2000 = 141,
TI_C5500 = 142,
TI_ARP32 = 143,
TI_PRU = 144,
MMDSP_PLUS = 160,
CYPRESS_M8C = 161,
R32C = 162,
TRIMEDIA = 163,
QDSP6 = 164,
EM8051 = 165,
STXP7X = 166,
NDS32 = 167,
ECOG1X = 168,
MAXQ30 = 169,
XIMO16 = 170,
MANIK = 171,
CRAYNV2 = 172,
RX = 173,
METAG = 174,
MCST_ELBRUS = 175,
ECOG16 = 176,
CR16 = 177,
ETPU = 178,
SLE9X = 179,
L10M = 180,
K10M = 181,
AARCH64 = 183,
AVR32 = 185,
STM8 = 186,
TILE64 = 187,
TILEPRO = 188,
MICROBLAZE = 189,
CUDA = 190,
TILEGX = 191,
CLOUDSHIELD = 192,
COREA_1ST = 193,
COREA_2ND = 194,
ARC_COMPACT2 = 195,
OPEN8 = 196,
RL78 = 197,
VIDEOCORE5 = 198,
EM78KOR = 199,
EM56800EX = 200,
BA1 = 201,
BA2 = 202,
XCORE = 203,
MCHP_PIC = 204,
KM32 = 210,
KMX32 = 211,
EMX16 = 212,
EMX8 = 213,
KVARC = 214,
CDP = 215,
COGE = 216,
COOL = 217,
NORC = 218,
CSR_KALIMBA = 219,
Z80 = 220,
VISIUM = 221,
FT32 = 222,
MOXIE = 223,
AMDGPU = 224,
RISCV = 243,
BPF = 247,
}
impl Default for Machine {
fn default() -> Self {
Machine::NONE
}
}
#[allow(non_camel_case_types)]
#[derive(Debug, Primitive, PartialEq, Clone)]
pub enum SegmentType {
NULL = 0,
LOAD = 1,
DYNAMIC = 2,
INTERP = 3,
NOTE = 4,
SHLIB = 5,
PHDR = 6,
TLS = 7,
NUM = 8,
GNU_EH_FRAME = 0x6474e550,
GNU_STACK = 0x6474e551,
GNU_RELRO = 0x6474e552,
PAX_FLAGS = 0x65041580,
SUNWBSS = 0x6ffffffa,
SUNWSTACK = 0x6ffffffb,
CPU0 = 0x70000000,
CPU1 = 0x70000001,
CPU2 = 0x70000002,
CPU3 = 0x70000003,
}
impl Default for SegmentType {
fn default() -> Self {
SegmentType::NULL
}
}
#[allow(non_camel_case_types)]
#[derive(Debug, Primitive, PartialEq, Clone)]
pub enum DynamicType {
NULL = 0,
NEEDED = 1,
PLTRELSZ = 2,
PLTGOT = 3,
HASH = 4,
STRTAB = 5,
SYMTAB = 6,
RELA = 7,
RELASZ = 8,
RELAENT = 9,
STRSZ = 10,
SYMENT = 11,
INIT = 12,
FINI = 13,
SONAME = 14,
RPATH = 15,
SYMBOLIC = 16,
REL = 17,
RELSZ = 18,
RELENT = 19,
PLTREL = 20,
DEBUG = 21,
TEXTREL = 22,
JMPREL = 23,
BIND_NOW = 24,
INIT_ARRAY = 25,
FINI_ARRAY = 26,
INIT_ARRAYSZ = 27,
FINI_ARRAYSZ = 28,
RUNPATH = 29,
FLAGS = 30,
PREINIT_ARRAY = 32,
PREINIT_ARRAYSZ = 33,
NUM = 34,
GNU_PRELINKED = 0x6ffffdf5,
GNU_CONFLICTSZ = 0x6ffffdf6,
GNU_LIBLISTSZ = 0x6ffffdf7,
CHECKSUM = 0x6ffffdf8,
PLTPADSZ = 0x6ffffdf9,
MOVEENT = 0x6ffffdfa,
MOVESZ = 0x6ffffdfb,
FEATURE_1 = 0x6ffffdfc,
POSFLAG_1 = 0x6ffffdfd,
SYMINSZ = 0x6ffffdfe,
SYMINENT = 0x6ffffdff,
GNU_HASH = 0x6ffffef5,
TLSDESC_PLT = 0x6ffffef6,
TLSDESC_GOT = 0x6ffffef7,
GNU_CONFLICT = 0x6ffffef8,
GNU_LIBLIST = 0x6ffffef9,
CONFIG = 0x6ffffefa,
DEPAUDIT = 0x6ffffefb,
AUDIT = 0x6ffffefc,
PLTPAD = 0x6ffffefd,
MOVETAB = 0x6ffffefe,
SYMINFO = 0x6ffffeff,
VERSYM = 0x6ffffff0,
RELACOUNT = 0x6ffffff9,
RELCOUNT = 0x6ffffffa,
FLAGS_1 = 0x6ffffffb,
VERDEF = 0x6ffffffc,
VERDEFNUM = 0x6ffffffd,
VERNEED = 0x6ffffffe,
VERNEEDNUM = 0x6fffffff,
AUXILIARY = 0x7ffffffd,
FILTER = 0x7fffffff,
MIPS_RLD_VERSION = 0x70000001,
MIPS_TIME_STAMP = 0x70000002,
MIPS_ICHECKSUM = 0x70000003,
MIPS_IVERSION = 0x70000004,
MIPS_FLAGS = 0x70000005,
MIPS_BASE_ADDRESS = 0x70000006,
MIPS_CONFLICT = 0x70000008,
MIPS_LIBLIST = 0x70000009,
MIPS_LOCAL_GOTNO = 0x7000000A,
MIPS_CONFLICTNO = 0x7000000B,
MIPS_LIBLISTNO = 0x70000010,
MIPS_SYMTABNO = 0x70000011,
MIPS_UNREFEXTNO = 0x70000012,
MIPS_GOTSYM = 0x70000013,
MIPS_HIPAGENO = 0x70000014,
MIPS_RLD_MAP = 0x70000016,
MIPS_RLD_MAP_REL = 0x70000035,
}
impl Default for DynamicType {
fn default() -> Self {
DynamicType::NULL
}
}
bitflags! {
#[derive(Default)]
pub struct DynamicFlags1: u64 {
const NOW = 1 << 0;
const GLOBAL = 1 << 1;
const GROUP = 1 << 2;
const NODELETE = 1 << 3;
const LOADFLTR = 1 << 4;
const INITFIRST = 1 << 5;
const NOOPEN = 1 << 6;
const ORIGIN = 1 << 7;
const DIRECT = 1 << 8;
const TRANS = 1 << 9;
const INTERPOSE = 1 << 10;
const NODEFLIB = 1 << 11;
const NODUMP = 1 << 12;
const CONFALT = 1 << 13;
const ENDFILTEE = 1 << 14;
const DISPRELDNE= 1 << 15;
const DISPRELPND= 1 << 16;
const NODIRECT = 1 << 17;
const IGNMULDEF = 1 << 18;
const NOKSYMS = 1 << 19;
const NOHDR = 1 << 20;
const EDITED = 1 << 21;
const NORELOC = 1 << 22;
const SYMINTPOSE= 1 << 23;
const GLOBAUDIT = 1 << 24;
const SINGLETON = 1 << 25;
const STUB = 1 << 26;
const PIE = 1 << 27;
}
}