'This function finds all the codecaves in a inputed file.
Prints results to screen. Generally not many caves in the ELF
format.  And why there is no need to cave jump.'

def find_all_caves(self):

    print '[*]    Looking    for    caves'
    SIZE_CAVE_TO_FIND = 94
    BeginCave = 0
    Tracking = 0
    count = 1
    caveTracker = []
    caveSpecs = []
    self.bin_file.seek(0)
    while True:
        try:
            s = struct.unpack('<b', self.bin_file.read(1))[0]
        except:
            break
        if (s == 0):
            if (count == 1):
                BeginCave = Tracking
            count += 1
        else:
            if (count >= SIZE_CAVE_TO_FIND):
                caveSpecs.append(BeginCave)
                caveSpecs.append(Tracking)
                caveTracker.append(caveSpecs)
            count = 1
            caveSpecs = []
        Tracking += 1
    for caves in caveTracker:
        for section in self.sec_hdr.iteritems():
            section = section[1]
            sectionFound = False
            if ((caves[0] >= section['sh_offset']) and (caves[1] <= (section['sh_size'] + section['sh_offset'])) and ((caves[1] - caves[0]) >= SIZE_CAVE_TO_FIND)):
                print 'We    have    a    winner:', section['name']
                print '->Begin    Cave', hex(caves[0])
                print '->End    of    Cave', hex(caves[1])
                print 'Size    of    Cave    (int)', (caves[1] - caves[0])
                print 'sh_size', hex(section['sh_size'])
                print 'sh_offset', hex(section['sh_offset'])
                print 'End    of    Raw    Data:', hex((section['sh_size'] + section['sh_offset']))
                print ('*' * 50)
                sectionFound = True
                break
        if (sectionFound is False):
            try:
                print 'No    section'
                print '->Begin    Cave', hex(caves[0])
                print '->End    of    Cave', hex(caves[1])
                print 'Size    of    Cave    (int)', (caves[1] - caves[0])
                print ('*' * 50)
            except Exception as e:
                print str(e)
    print ('[*]    Total    of    %s    caves    found' % len(caveTracker))
