'This function finds all the codecaves in a inputed file.
Prints results to screen'

def find_all_caves(self):

    print '[*]    Looking    for    caves'
    SIZE_CAVE_TO_FIND = self.SHELL_LEN
    BeginCave = 0
    Tracking = 0
    count = 1
    caveTracker = []
    caveSpecs = []
    self.binary = open(self.FILE, 'r+b')
    self.binary.seek(0)
    while True:
        try:
            s = struct.unpack('<b', self.binary.read(1))[0]
        except Exception as e:
            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.flItms['Sections']:
            sectionFound = False
            if ((caves[0] >= section[4]) and (caves[1] <= (section[3] + section[4])) and ((caves[1] - caves[0]) >= SIZE_CAVE_TO_FIND)):
                print 'We    have    a    winner:', section[0]
                print '->Begin    Cave', hex(caves[0])
                print '->End    of    Cave', hex(caves[1])
                print 'Size    of    Cave    (int)', (caves[1] - caves[0])
                print 'SizeOfRawData', hex(section[3])
                print 'PointerToRawData', hex(section[4])
                print 'End    of    Raw    Data:', hex((section[3] + section[4]))
                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))
    self.binary.close()
