<gh_stars>1-10
from HystrixBox.Tools.fileType.getFileExtenstion import getFileExtension
import os

def findFiles(filename, output='hiddenFile'):
    # Read image
    try:
        with open(filename, 'rb') as file:
            f = bytearray(file.read())
    except:
        print('Cant read the file')
        return

    endTag = 0
    # Check image format
    extension = getFileExtension(filename)
    if extension is None:
        print('File extension not found')
        return
    if extension.extension == 'jpg':
        endTag = bytearray(b'\xFF\xD9')
    elif extension.extension == 'png':
        endTag = bytearray(b'\x00\x00\x00\x00\x49\x45\x4E\x44\xAE\x42\x60\x82')
    else:
        print('File extension is nor png or jpg')
        return

    # Find end png tag
    index = f.find(endTag)

    if index == -1:
        print('corrupted file')
        return

    if index+len(endTag) == len(f):
        print('There is no hidden files in this image')
        return

    # save all extra bytes to file
    with open(output, 'wb') as file:
        file.write(f[index + len(endTag):])
        print('Hidden files extracted')

    # Check with file command to detect file extension
    extension = getFileExtension(output)
    if extension is None:
        print('File extension not found')
        return
    print('File extension is: ' + extension.extension)
    os.rename(output, output + '.' + extension.extension)



from HystrixBox.Tools.fileType.getFileExtenstion import getFileExtension
import os

def findFiles(filename, output='hiddenFile'):
    # Read image
    try:
        with open(filename, 'rb') as file:
            f = bytearray(file.read())
    except:
        print('Cant read the file')
        return

    endTag = 0
    # Check image format
    extension = getFileExtension(filename)
    if extension is None:
        print('File extension not found')
        return
    if extension.extension == 'jpg':
        endTag = bytearray(b'\xFF\xD9')
    elif extension.extension == 'png':
        endTag = bytearray(b'\x00\x00\x00\x00\x49\x45\x4E\x44\xAE\x42\x60\x82')
    else:
        print('File extension is nor png or jpg')
        return

    # Find end png tag
    index = f.find(endTag)

    if index == -1:
        print('corrupted file')
        return

    if index+len(endTag) == len(f):
        print('There is no hidden files in this image')
        return

    # save all extra bytes to file
    with open(output, 'wb') as file:
        file.write(f[index + len(endTag):])
        print('Hidden files extracted')

    # Check with file command to detect file extension
    extension = getFileExtension(output)
    if extension is None:
        print('File extension not found')
        return
    print('File extension is: ' + extension.extension)
    os.rename(output, output + '.' + extension.extension)
# Read image # Check image format # Find end png tag # save all extra bytes to file # Check with file command to detect file extension