pub fn new(path: &'a str, load: bool) -> Self {
        println!("Path is {:?}", path);
        let library = if load {
            Some(unsafe { Library::new(path) })
        } else {
            None
        };

        println!("library: {:?}", library);

        let (start, end) = mapping_for_library(path);

        let file_in_memory = unsafe { std::slice::from_raw_parts(start as *const u8, end - start) };
        let mut elf = Elf::lazy_parse(
           Elf::parse_header(file_in_memory).expect("Failed to parse elf"),
        )
        .expect("Failed to parse elf lazily");

        let ctx = Ctx {
            le: Endian::Little,
            container: Container::Big,
        };
        elf.program_headers = ProgramHeader::parse(
            &file_in_memory,
            elf.header.e_phoff as usize,
            elf.header.e_phnum as usize,
            ctx,
        )
        .expect("parse program headers");
        // because we're in memory, we need to use the vaddr. goblin uses offsets, so we'll
        // just patch the PHDRS so that they have offsets equal to vaddr.
        for mut program_header in &mut elf.program_headers {
            program_header.p_offset = program_header.p_vaddr;
        }
        elf.dynamic =
            Dynamic::parse(&file_in_memory, &elf.program_headers, ctx)
                .expect("parse dynamic section");


        //let mut android_relr_offset = 0;
        //let mut android_relr_size = 0;

        //for entry in elf.dynamic.dyns {
            //match entry.tag {
                //// DT_ANDROID_REL
                //DT_LOOS + 2 => {

                //},
                //// DT_ANDROID_RELSZ
                //DT_LOOS + 3 => {

                //},
                //// DT_ANDROID_RELA
                //DT_LOOS + 4 => {

                //},
                //// DT_ANDROID_RELASZ
                //DT_LOOS + 5 => {

                //},
                //// DT_ANDROID_RELR
                //0x6fffe000 | 36 => {
                    //android_rel_offset = entry.val;
                //},
                //// DT_ANDROID_RELRSZ
                //0x6fffe001 | 35 => {
                    //android_relr_size = entry.val;
                //},
                //// DT_ANDROID_RELRENT
                //0x6fffe003 | 37 => {
                    //android_relr_entry_size = entry.val;
                //},
                //// DT_ANDROID_RELRCOUNT
                //0x6fffe005 => {

                //},
                //_ => (),
            //}
        //}

        //if android_relr_offset != 0 {
            //let mut relocations: Vec<usize> = vec!();
            //let qwords = std::slice::from_raw_parts((start + android_relr_offset) as usize as *mut usize, android_relr_size / android_relr_entry_size);
            //let mut index = 0;
            //while index < qwords.len() {
                //let base_address = qwords[index];
                //assert!(base_address % 2 == 0);

                //index += 1;
                //while qwords[index] & 1 == 1 {
                    //let bitmap = qwords[index];
                    //index += 1;

                    //for bitindex in 1..63 {
                        //if (bitmap >> bitindex) & 1 == 1 {

                        //}
                    //}
                //}


            //}

        //}

        let info = &elf.dynamic.as_ref().unwrap().info;

        // second word of hash
        let chain_count = unsafe {
            if let Some(offset) = info.hash {
                std::slice::from_raw_parts((start + offset as usize + 4) as *mut u32, 1)[0]
            } else {
                (info.pltrelsz / info.syment) as u32
            }
        };

        elf.dynsyms = Symtab::parse(
            &file_in_memory,
            info.symtab,
            chain_count as usize,
            ctx,
        )
        .expect("parse dynsyms");
        elf.dynstrtab =
            Strtab::parse(&file_in_memory, info.strtab, info.strsz, b'\x00')
                .expect("parse dynstrtab");
        elf.pltrelocs = RelocSection::parse(
            &file_in_memory,
            info.jmprel,
            info.pltrelsz,
            info.pltrel == DT_RELA,
            ctx,
        )
        .expect("parse pltrel");
        //
        //let dynsyms = &elf.dynsyms.to_vec();
        //let gnu_hash_metadata = unsafe { std::slice::from_raw_parts((start + dynamic.info.gnu_hash.unwrap() as usize) as *mut u32, 4)};
        //let gnu_hash_size = (dynsyms.len() - gnu_hash_metadata[1] as usize) * 4 + gnu_hash_metadata[0] as usize * 4 + gnu_hash_metadata[2] as usize  * 8 + 4 * 4;
        //let gnu_hash = unsafe { goblin::elf64::gnu_hash::GnuHash::from_raw_table(
        //std::slice::from_raw_parts((start + dynamic.info.gnu_hash.unwrap() as usize) as *mut u8,  gnu_hash_size as usize),
        //dynsyms) }.expect("parse gnu_hash");

        Self {
            path,
            start,
            end,
            file_in_memory: Box::new(file_in_memory),
            elf,
        }
    }
/// Create a new library to be hooked from a path. If the load boolean is true, the library will first be
/// loaded.
Create a new library to be hooked from a path. If the load boolean is true, the library will first be
loaded.
Create a new library to be hooked from a path . If the load boolean is true the library will first be loaded .
pub fn new(path: &'a str, load: bool) -> Self {
        println!("Path is {:?}", path);
        let library = if load {
            Some(unsafe { Library::new(path) })
        } else {
            None
        };
        println!("library: {:?}", library);
        let (start, end) = mapping_for_library(path);
        let file_in_memory = unsafe { std::slice::from_raw_parts(start as *const u8, end - start) };
        let mut elf = Elf::lazy_parse(
           Elf::parse_header(file_in_memory).expect("Failed to parse elf"),
        )
        .expect("Failed to parse elf lazily");
        let ctx = Ctx {
            le: Endian::Little,
            container: Container::Big,
        };
        elf.program_headers = ProgramHeader::parse(
            &file_in_memory,
            elf.header.e_phoff as usize,
            elf.header.e_phnum as usize,
            ctx,
        )
        .expect("parse program headers");
        // because we're in memory, we need to use the vaddr. goblin uses offsets, so we'll
        // just patch the PHDRS so that they have offsets equal to vaddr.
        for mut program_header in &mut elf.program_headers {
            program_header.p_offset = program_header.p_vaddr;
        }
        elf.dynamic =
            Dynamic::parse(&file_in_memory, &elf.program_headers, ctx)
                .expect("parse dynamic section");
        //let mut android_relr_offset = 0;
        //let mut android_relr_size = 0;
        //for entry in elf.dynamic.dyns {
            //match entry.tag {
                //// DT_ANDROID_REL
                //DT_LOOS + 2 => {
                //},
                //// DT_ANDROID_RELSZ
                //DT_LOOS + 3 => {
                //},
                //// DT_ANDROID_RELA
                //DT_LOOS + 4 => {
                //},
                //// DT_ANDROID_RELASZ
                //DT_LOOS + 5 => {
                //},
                //// DT_ANDROID_RELR
                //0x6fffe000 | 36 => {
                    //android_rel_offset = entry.val;
                //},
                //// DT_ANDROID_RELRSZ
                //0x6fffe001 | 35 => {
                    //android_relr_size = entry.val;
                //},
                //// DT_ANDROID_RELRENT
                //0x6fffe003 | 37 => {
                    //android_relr_entry_size = entry.val;
                //},
                //// DT_ANDROID_RELRCOUNT
                //0x6fffe005 => {
                //},
                //_ => (),
            //}
        //}
        //if android_relr_offset != 0 {
            //let mut relocations: Vec<usize> = vec!();
            //let qwords = std::slice::from_raw_parts((start + android_relr_offset) as usize as *mut usize, android_relr_size / android_relr_entry_size);
            //let mut index = 0;
            //while index < qwords.len() {
                //let base_address = qwords[index];
                //assert!(base_address % 2 == 0);
                //index += 1;
                //while qwords[index] & 1 == 1 {
                    //let bitmap = qwords[index];
                    //index += 1;
                    //for bitindex in 1..63 {
                        //if (bitmap >> bitindex) & 1 == 1 {
                        //}
                    //}
                //}
            //}
        //}
        let info = &elf.dynamic.as_ref().unwrap().info;
        // second word of hash
        let chain_count = unsafe {
            if let Some(offset) = info.hash {
                std::slice::from_raw_parts((start + offset as usize + 4) as *mut u32, 1)[0]
            } else {
                (info.pltrelsz / info.syment) as u32
            }
        };
        elf.dynsyms = Symtab::parse(
            &file_in_memory,
            info.symtab,
            chain_count as usize,
            ctx,
        )
        .expect("parse dynsyms");
        elf.dynstrtab =
            Strtab::parse(&file_in_memory, info.strtab, info.strsz, b'\x00')
                .expect("parse dynstrtab");
        elf.pltrelocs = RelocSection::parse(
            &file_in_memory,
            info.jmprel,
            info.pltrelsz,
            info.pltrel == DT_RELA,
            ctx,
        )
        .expect("parse pltrel");
        //
        //let dynsyms = &elf.dynsyms.to_vec();
        //let gnu_hash_metadata = unsafe { std::slice::from_raw_parts((start + dynamic.info.gnu_hash.unwrap() as usize) as *mut u32, 4)};
        //let gnu_hash_size = (dynsyms.len() - gnu_hash_metadata[1] as usize) * 4 + gnu_hash_metadata[0] as usize * 4 + gnu_hash_metadata[2] as usize  * 8 + 4 * 4;
        //let gnu_hash = unsafe { goblin::elf64::gnu_hash::GnuHash::from_raw_table(
        //std::slice::from_raw_parts((start + dynamic.info.gnu_hash.unwrap() as usize) as *mut u8,  gnu_hash_size as usize),
        //dynsyms) }.expect("parse gnu_hash");
        Self {
            path,
            start,
            end,
            file_in_memory: Box::new(file_in_memory),
            elf,
        }
    }
pub fn new ( path : & ' a str , load : bool ) -> Self { println ! ( " " path ) ; let library = if load { Some ( unsafe { Library :: new ( path ) } ) } else { None } ; println ! ( " " library ) ; let ( start , end ) = mapping_for_library ( path ) ; let file_in_memory = unsafe { std :: slice :: from_raw_parts ( start as * const u8 , end - start ) } ; let mut elf = Elf :: lazy_parse ( Elf :: parse_header ( file_in_memory ) . expect ( " " ) , ) . expect ( " " ) ; let ctx = Ctx { le : Endian :: Little , container : Container :: Big , } ; elf . program_headers = ProgramHeader :: parse ( & file_in_memory , elf . header . e_phoff as usize , elf . header . e_phnum as usize , ctx , ) . expect ( " " ) ; // because we're in memory, we need to use the vaddr. goblin uses offsets, so we'll // just patch the PHDRS so that they have offsets equal to vaddr. for mut program_header in & mut elf . program_headers { program_header . p_offset = program_header . p_vaddr ; } elf . dynamic = Dynamic :: parse ( & file_in_memory , & elf . program_headers , ctx ) . expect ( " " ) ; //let mut android_relr_offset = 0; //let mut android_relr_size = 0; //for entry in elf.dynamic.dyns { //match entry.tag { //// DT_ANDROID_REL //DT_LOOS + 2 => { //}, //// DT_ANDROID_RELSZ //DT_LOOS + 3 => { //}, //// DT_ANDROID_RELA //DT_LOOS + 4 => { //}, //// DT_ANDROID_RELASZ //DT_LOOS + 5 => { //}, //// DT_ANDROID_RELR //0x6fffe000 | 36 => { //android_rel_offset = entry.val; //}, //// DT_ANDROID_RELRSZ //0x6fffe001 | 35 => { //android_relr_size = entry.val; //}, //// DT_ANDROID_RELRENT //0x6fffe003 | 37 => { //android_relr_entry_size = entry.val; //}, //// DT_ANDROID_RELRCOUNT //0x6fffe005 => { //}, //_ => (), //} //} //if android_relr_offset != 0 { //let mut relocations: Vec<usize> = vec!(); //let qwords = std::slice::from_raw_parts((start + android_relr_offset) as usize as *mut usize, android_relr_size / android_relr_entry_size); //let mut index = 0; //while index < qwords.len() { //let base_address = qwords[index]; //assert!(base_address % 2 == 0); //index += 1; //while qwords[index] & 1 == 1 { //let bitmap = qwords[index]; //index += 1; //for bitindex in 1..63 { //if (bitmap >> bitindex) & 1 == 1 { //} //} //} //} //} let info = & elf . dynamic . as_ref ( ) . unwrap ( ) . info ; // second word of hash let chain_count = unsafe { if let Some ( offset ) = info . hash { std :: slice :: from_raw_parts ( ( start + offset as usize + 4 ) as * mut u32 , 1 ) [ 0 ] } else { ( info . pltrelsz / info . syment ) as u32 } } ; elf . dynsyms = Symtab :: parse ( & file_in_memory , info . symtab , chain_count as usize , ctx , ) . expect ( " " ) ; elf . dynstrtab = Strtab :: parse ( & file_in_memory , info . strtab , info . strsz , b'\x00' ) . expect ( " " ) ; elf . pltrelocs = RelocSection :: parse ( & file_in_memory , info . jmprel , info . pltrelsz , info . pltrel == DT_RELA , ctx , ) . expect ( " " ) ; // //let dynsyms = &elf.dynsyms.to_vec(); //let gnu_hash_metadata = unsafe { std::slice::from_raw_parts((start + dynamic.info.gnu_hash.unwrap() as usize) as *mut u32, 4)}; //let gnu_hash_size = (dynsyms.len() - gnu_hash_metadata[1] as usize) * 4 + gnu_hash_metadata[0] as usize * 4 + gnu_hash_metadata[2] as usize  * 8 + 4 * 4; //let gnu_hash = unsafe { goblin::elf64::gnu_hash::GnuHash::from_raw_table( //std::slice::from_raw_parts((start + dynamic.info.gnu_hash.unwrap() as usize) as *mut u8,  gnu_hash_size as usize), //dynsyms) }.expect("parse gnu_hash"); Self { path , start , end , file_in_memory : Box :: new ( file_in_memory ) , elf , } }
Create a new library to be hooked from a path.
Create a new library to be hooked from a path .
path
&'a str
load
bool
path
&'a str
load
bool