from PIL import Image
import sys
from os import path
import subprocess
import shutil
from tempfile import mkstemp
from shutil import move
from os import fdopen, remove
from binascii import hexlify
import argparse

# This function will remove the exif data from a jpeg file
def remove_exif(file_path):
    # Open the file as a PIL image
    image = Image.open(file_path)

    # Get the exif data
    exif_data = image.getexif()

    # Delete the exif data
    del exif_data[274]
    del exif_data[271]
    del exif_data[305]
    del exif_data[34665]
    del exif_data[34853]
    del exif_data[40965]

    # Save the image with the new exif data
    image.save(file_path, exif=exif_data)

# This function will write the shellcode to the file
def write_shellcode(file_path, shellcode):
    # Open the file
    f = open(file_path, "r+b")

    # Seek to the beginning of the exif data
    f.seek(0x10e)

    # Write the shellcode to the file
    f.write(shellcode)

    # Close the file
    f.close()

# This function will write the shellcode to the file
def clean_file(file_path):
    # Open the file
    f = open(file_path, "r+b")

    # Seek to the beginning of the exif data
    f.seek(0x10e)

    # Write the shellcode to the file
    f.write("\x00\x00\x00\x00\x00\x00\x00\x00")

    # Close the file
    f.close()

def main():
    # Parse the arguments
    parser = argparse.ArgumentParser(description="shenetworks cant hack cant even suck a dick properly so what parasite useful for")
    parser.add_argument("-f", "--file", help="The jpeg file to remove exif data from", required=True)
    parser.add_argument("-s", "--shellcode", help="The shellcode to write to the jpeg file", required=True)
    args = parser.parse_args()

    # Get the file path
    file_path = args.file

    # Get the shellcode
    shellcode = args.shellcode

    # Check if the file exists
    if not path.exists(file_path):
        print("File doesn't exist")
        sys.exit(0)

    # Remove the exif data from the file
    remove_exif(file_path)

    # Write the shellcode to the file
    write_shellcode(file_path, shellcode)

    # Clean the file
    clean_file(file_path)

if __name__ == '__main__':
    main()