'Gather info about the binary'

def gather_file_info(self):

    print '[*]    Gathering    file    info'
    bin = self.bin_file
    bin.seek(0)
    EI_MAG = bin.read(4)
    self.EI_CLASS = struct.unpack('<B', bin.read(1))[0]
    self.EI_DATA = struct.unpack('<B', bin.read(1))[0]
    if (self.EI_DATA == 1):
        self.endian = '<'
    else:
        self.endian = '>'
    self.EI_VERSION = struct.unpack('<B', bin.read(1))[0]
    self.EI_OSABI = struct.unpack('<B', bin.read(1))[0]
    self.EI_ABIVERSION = struct.unpack('<B', bin.read(1))[0]
    self.EI_PAD = struct.unpack((self.endian + 'BBBBBBB'), bin.read(7))[0]
    self.e_type = struct.unpack((self.endian + 'H'), bin.read(2))[0]
    self.e_machine = struct.unpack((self.endian + 'H'), bin.read(2))[0]
    self.e_version = struct.unpack((self.endian + 'I'), bin.read(4))[0]
    if (self.EI_CLASS == 1):
        self.e_entryLocOnDisk = bin.tell()
        self.e_entry = struct.unpack((self.endian + 'I'), bin.read(4))[0]
        self.e_phoff = struct.unpack((self.endian + 'I'), bin.read(4))[0]
        self.e_shoff = struct.unpack((self.endian + 'I'), bin.read(4))[0]
    else:
        self.e_entryLocOnDisk = bin.tell()
        self.e_entry = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
        self.e_phoff = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
        self.e_shoff = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
    self.VrtStrtngPnt = self.e_entry
    self.e_flags = struct.unpack((self.endian + 'I'), bin.read(4))[0]
    self.e_ehsize = struct.unpack((self.endian + 'H'), bin.read(2))[0]
    self.e_phentsize = struct.unpack((self.endian + 'H'), bin.read(2))[0]
    self.e_phnum = struct.unpack((self.endian + 'H'), bin.read(2))[0]
    self.e_shentsize = struct.unpack((self.endian + 'H'), bin.read(2))[0]
    self.e_shnum = struct.unpack((self.endian + 'H'), bin.read(2))[0]
    self.e_shstrndx = struct.unpack((self.endian + 'H'), bin.read(2))[0]
    if (self.e_phoff > os.path.getsize(self.FILE)):
        print '[!]    El    fuzzero'
        return False
    bin.seek(self.e_phoff, 0)
    if (self.e_shnum == 0):
        print '[*]    More    than    0xFF00    sections'
        print '[*]    NOPE    NOPE    NOPE'
        return False
    else:
        self.real_num_sections = self.e_shnum
    if (self.e_phoff > self.file_size):
        print '[*]    e_phoff    is    greater    than    file    size'
        return False
    bin.seek(self.e_phoff, 0)
    self.prog_hdr = {}
    for i in range(self.e_phnum):
        self.prog_hdr[i] = {}
        if (self.EI_CLASS == 1):
            if ((self.e_phoff + ((self.e_phnum * 4) * 8)) > self.file_size):
                print '[!]    e_phoff    and    e_phnum    is    greater    than    the    file    size'
                return False
            self.prog_hdr[i]['p_type'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
            self.prog_hdr[i]['p_offset'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
            self.prog_hdr[i]['p_vaddr'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
            self.prog_hdr[i]['p_paddr'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
            self.prog_hdr[i]['p_filesz'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
            self.prog_hdr[i]['p_memsz'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
            self.prog_hdr[i]['p_flags'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
            self.prog_hdr[i]['p_align'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
        else:
            if ((self.e_phoff + (self.e_phnum * ((4 * 2) + (6 * 8)))) > self.file_size):
                print '[!]    e_phoff    and    e_phnum    is    greater    than    the    file    size'
                return False
            self.prog_hdr[i]['p_type'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
            self.prog_hdr[i]['p_flags'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
            self.prog_hdr[i]['p_offset'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
            self.prog_hdr[i]['p_vaddr'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
            self.prog_hdr[i]['p_paddr'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
            self.prog_hdr[i]['p_filesz'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
            self.prog_hdr[i]['p_memsz'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
            self.prog_hdr[i]['p_align'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
        if ((self.prog_hdr[i]['p_type'] == 1) and (self.prog_hdr[i]['p_vaddr'] < self.e_entry)):
            self.offset_addr = self.prog_hdr[i]['p_vaddr']
            self.LocOfEntryinCode = (self.e_entry - self.offset_addr)
    if (self.e_shoff > self.file_size):
        print '[!]    e_shoff    location    is    greater    than    file    size'
        return False
    if (self.e_shnum > self.file_size):
        print '[!]    e_shnum    is    greater    than    file    size'
        return False
    bin.seek(self.e_shoff, 0)
    self.sec_hdr = {}
    for i in range(self.e_shnum):
        self.sec_hdr[i] = {}
        if (self.EI_CLASS == 1):
            if ((self.e_shoff + ((self.e_shnum * 4) * 10)) > self.file_size):
                print '[!]    e_shnum    is    greater    than    file    size'
                return False
            self.sec_hdr[i]['sh_name'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
            self.sec_hdr[i]['sh_type'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
            self.sec_hdr[i]['sh_flags'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
            self.sec_hdr[i]['sh_addr'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
            self.sec_hdr[i]['sh_offset'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
            self.sec_hdr[i]['sh_size'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
            self.sec_hdr[i]['sh_link'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
            self.sec_hdr[i]['sh_info'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
            self.sec_hdr[i]['sh_addralign'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
            self.sec_hdr[i]['sh_entsize'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
        else:
            if ((self.e_shoff + (self.e_shnum * ((4 * 4) + (6 * 8)))) > self.file_size):
                print '[!]    e_shnum    is    greater    than    file    size'
                return False
            self.sec_hdr[i]['sh_name'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
            self.sec_hdr[i]['sh_type'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
            self.sec_hdr[i]['sh_flags'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
            self.sec_hdr[i]['sh_addr'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
            self.sec_hdr[i]['sh_offset'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
            self.sec_hdr[i]['sh_size'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
            self.sec_hdr[i]['sh_link'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
            self.sec_hdr[i]['sh_info'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
            self.sec_hdr[i]['sh_addralign'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
            self.sec_hdr[i]['sh_entsize'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
    if (self.set_section_name() is False):
        print '[!]    Fuzzing    sections'
        return False
    if (self.e_type != 2):
        print '[!]    Only    supporting    executable    elf    e_types,    things    may    get    weird.'
    return True
