use scroll::*;
use self::constants::R_SCATTERED;
pub mod constants {
pub const R_ABS: u8 = 0;
pub const R_SCATTERED: u32 = 0x80000000;
pub const X86_64_RELOC_UNSIGNED: u8 = 0;
pub const X86_64_RELOC_SIGNED: u8 = 1;
pub const X86_64_RELOC_BRANCH: u8 = 2;
pub const X86_64_RELOC_GOT_LOAD: u8 = 3;
pub const X86_64_RELOC_GOT: u8 = 4;
pub const X86_64_RELOC_SUBTRACTOR: u8 = 5;
pub const X86_64_RELOC_SIGNED_1: u8 = 6;
pub const X86_64_RELOC_SIGNED_2: u8 = 7;
pub const X86_64_RELOC_SIGNED_4: u8 = 8;
pub const X86_64_RELOC_TLV: u8 = 9;
pub const GENERIC_RELOC_VANILLA: u8 = 0;
pub const GENERIC_RELOC_PAIR: u8 = 1;
pub const GENERIC_RELOC_SECTDIFF: u8 = 2;
pub const GENERIC_RELOC_PB_LA_PTR: u8 = 3;
pub const GENERIC_RELOC_LOCAL_SECTDIFF: u8 = 4;
pub const GENERIC_RELOC_TLV: u8 = 5;
pub const ARM_RELOC_VANILLA: u8 = GENERIC_RELOC_VANILLA;
pub const ARM_RELOC_PAIR: u8 = GENERIC_RELOC_PAIR;
pub const ARM_RELOC_SECTDIFF: u8 = GENERIC_RELOC_SECTDIFF;
pub const ARM_RELOC_LOCAL_SECTDIFF: u8 = 3;
pub const ARM_RELOC_PB_LA_PTR: u8 = 4;
pub const ARM_RELOC_BR24: u8 = 5;
pub const ARM_THUMB_RELOC_BR22: u8 = 6;
pub const ARM_THUMB_32BIT_BRANCH: u8 = 7;
pub const ARM_RELOC_HALF: u8 = 8;
pub const ARM_RELOC_HALF_SECTDIFF: u8 = 9;
pub const ARM64_RELOC_UNSIGNED: u8 = 0;
pub const ARM64_RELOC_SUBTRACTOR: u8 = 1;
pub const ARM64_RELOC_BRANCH26: u8 = 2;
pub const ARM64_RELOC_PAGE21: u8 = 3;
pub const ARM64_RELOC_PAGEOFF12: u8 = 4;
pub const ARM64_RELOC_GOT_LOAD_PAGE21: u8 = 5;
pub const ARM64_RELOC_GOT_LOAD_PAGEOFF12: u8 = 6;
pub const ARM64_RELOC_POINTER_TO_GOT: u8 = 7;
pub const ARM64_RELOC_TLVP_LOAD_PAGE21: u8 = 8;
pub const ARM64_RELOC_TLVP_LOAD_PAGEOFF12: u8 = 9;
pub const ARM64_RELOC_ADDEND: u8 = 10;
}
#[derive(IOread, SizeWith)]
pub struct RelocationInfo {
pub r_address: i32,
pub r_bitfield: u32,
}
impl RelocationInfo {
pub fn r_symbolnum(&self) -> usize {
(self.r_bitfield & 0x00ff_ffffu32) as usize
}
pub fn r_pcrel(&self) -> u8 {
((self.r_bitfield & 0x0100_0000u32) >> 24) as u8
}
pub fn r_length(&self) -> u8 {
((self.r_bitfield & 0x0600_0000u32) >> 25) as u8
}
pub fn r_extern(&self) -> u8 {
((self.r_bitfield & 0x0800_0000) >> 27) as u8
}
pub fn r_type(&self) -> u8 {
((self.r_bitfield & 0xf000_0000) >> 28) as u8
}
pub fn is_scattered(&self) -> bool {
self.r_address as u32 & R_SCATTERED == R_SCATTERED
}
}