@@ -45,7 +45,7 @@ public static void Main(string[] args)
4545 {
4646 Console . Title = $ "SharpLoader";
4747
48- var dragDropSources = new List < string > ( ) ;
48+ var dragDropPaths = new List < string > ( ) ;
4949 var seed = - 1 ;
5050
5151 for ( var i = 0 ; i < args . Length ; i ++ )
@@ -56,13 +56,12 @@ public static void Main(string[] args)
5656 // Directory
5757 if ( File . GetAttributes ( args [ i ] ) . HasFlag ( FileAttributes . Directory ) )
5858 {
59- var files = GetFilesFromDirectory ( args [ i ] ) ;
60- dragDropSources . AddRange ( files ) ;
59+ dragDropPaths . AddRange ( GetFilesFromDirectory ( args [ i ] ) ) ;
6160 }
6261 // File
6362 else
6463 {
65- dragDropSources . Add ( args [ i ] ) ;
64+ dragDropPaths . Add ( args [ i ] ) ;
6665 }
6766 }
6867 // Normal argument
@@ -116,12 +115,12 @@ public static void Main(string[] args)
116115 Console . ForegroundColor = ConsoleColor . Red ;
117116 Console . WriteLine ( $ "-=: Config file not found ({ ConfigFileName } )") ;
118117
119- WinApi . WritePrivateProfileString ( "SharpLoader" , "Assemblies " , "" , ConfigPath ) ;
118+ WinApi . WritePrivateProfileString ( "SharpLoader" , "References " , "" , ConfigPath ) ;
120119 WinApi . WritePrivateProfileString ( "SharpLoader" , "Directory" , "" , ConfigPath ) ;
121120 WinApi . WritePrivateProfileString ( "SharpLoader" , "Sources" , "" , ConfigPath ) ;
122121 WinApi . WritePrivateProfileString ( "SharpLoader" , "Output" , "SharpLoader" , ConfigPath ) ;
123- WinApi . WritePrivateProfileString ( "SharpLoader" , "AutoRun" , "false" , ConfigPath ) ;
124122 WinApi . WritePrivateProfileString ( "SharpLoader" , "Arguments" , "/platform:anycpu32bitpreferred" , ConfigPath ) ;
123+ WinApi . WritePrivateProfileString ( "SharpLoader" , "AutoRun" , "false" , ConfigPath ) ;
125124
126125 Console . ForegroundColor = ConsoleColor . Red ;
127126 Console . WriteLine ( $ "-=: Default config file generated") ;
@@ -134,53 +133,43 @@ public static void Main(string[] args)
134133 Console . ForegroundColor = ConsoleColor . White ;
135134 Console . WriteLine ( "-=: Reading..." ) ;
136135
137- var baseDirectoryReadSb = new StringBuilder ( ReadBufferSize ) ;
138- var assembliesReadSb = new StringBuilder ( ReadBufferSize ) ;
139- var sourceFilesReadSb = new StringBuilder ( ReadBufferSize ) ;
140- var outputNameReadSb = new StringBuilder ( ReadBufferSize ) ;
141- var autoRunReadSb = new StringBuilder ( ReadBufferSize ) ;
136+ var userReferencesReadSb = new StringBuilder ( ReadBufferSize ) ;
137+ var baseDirectoryReadSb = new StringBuilder ( ReadBufferSize ) ;
138+ var sourceFilesReadSb = new StringBuilder ( ReadBufferSize ) ;
139+ var outputNameReadSb = new StringBuilder ( ReadBufferSize ) ;
142140 var compilerArgumentsReadSb = new StringBuilder ( ReadBufferSize ) ;
141+ var autoRunReadSb = new StringBuilder ( ReadBufferSize ) ;
143142
143+ WinApi . GetPrivateProfileString ( "SharpLoader" , "References" , string . Empty , userReferencesReadSb , ReadBufferSize , ConfigPath ) ;
144144 WinApi . GetPrivateProfileString ( "SharpLoader" , "Directory" , string . Empty , baseDirectoryReadSb , ReadBufferSize , ConfigPath ) ;
145- WinApi . GetPrivateProfileString ( "SharpLoader" , "Assemblies" , string . Empty , assembliesReadSb , ReadBufferSize , ConfigPath ) ;
146145 WinApi . GetPrivateProfileString ( "SharpLoader" , "Sources" , string . Empty , sourceFilesReadSb , ReadBufferSize , ConfigPath ) ;
147146 WinApi . GetPrivateProfileString ( "SharpLoader" , "Output" , string . Empty , outputNameReadSb , ReadBufferSize , ConfigPath ) ;
148- WinApi . GetPrivateProfileString ( "SharpLoader" , "AutoRun" , string . Empty , autoRunReadSb , ReadBufferSize , ConfigPath ) ;
149147 WinApi . GetPrivateProfileString ( "SharpLoader" , "Arguments" , string . Empty , compilerArgumentsReadSb , ReadBufferSize , ConfigPath ) ;
148+ WinApi . GetPrivateProfileString ( "SharpLoader" , "AutoRun" , string . Empty , autoRunReadSb , ReadBufferSize , ConfigPath ) ;
150149
151- var baseDirectory = baseDirectoryReadSb . ToString ( ) ;
152- var userAssemblies = assembliesReadSb . ToString ( ) . Split ( new [ ] { ';' } , StringSplitOptions . RemoveEmptyEntries ) ;
153- string [ ] sourceFiles ;
154- var outputName = $ "{ outputNameReadSb } -{ DateTime . Now : dd-MM-yyyy} .exe";
155- var autoRun = autoRunReadSb . ToString ( ) . Equals ( "true" , StringComparison . OrdinalIgnoreCase ) ;
150+ var userReferences = userReferencesReadSb . ToString ( ) . Split ( new [ ] { ';' } , StringSplitOptions . RemoveEmptyEntries ) ;
151+ var baseDirectory = baseDirectoryReadSb . ToString ( ) ;
152+ string [ ] userSourcePaths ;
153+ var outputName = $ "{ outputNameReadSb } -{ DateTime . Now : dd-MM-yyyy} .exe";
156154 var compilerArguments = compilerArgumentsReadSb . ToString ( ) ;
155+ var autoRun = autoRunReadSb . ToString ( ) . Equals ( "true" , StringComparison . OrdinalIgnoreCase ) ;
157156
158157 // Drag n Drop
159- if ( dragDropSources . Count != 0 )
158+ if ( dragDropPaths . Count != 0 )
160159 {
161- sourceFiles = dragDropSources . ToArray ( ) ;
160+ userSourcePaths = dragDropPaths . ToArray ( ) ;
162161 }
163162 // Read from config
164163 else
165164 {
166- sourceFiles = sourceFilesReadSb . ToString ( ) . Split ( new [ ] { ';' } , StringSplitOptions . RemoveEmptyEntries ) ;
165+ userSourcePaths = sourceFilesReadSb . ToString ( ) . Split ( new [ ] { ';' } , StringSplitOptions . RemoveEmptyEntries ) ;
167166 }
168167
169168 // Check values
170- if ( userAssemblies . Length == 0 )
171- {
172- Console . ForegroundColor = ConsoleColor . Red ;
173- Console . WriteLine ( $ "-=: Assemblies are not given") ;
174-
175- Console . ReadKey ( ) ;
176-
177- Environment . Exit ( 2 ) ;
178- }
179-
180- if ( sourceFiles . Length == 0 )
169+ if ( userReferences . Length == 0 )
181170 {
182171 Console . ForegroundColor = ConsoleColor . Red ;
183- Console . WriteLine ( $ "-=: Sources are not given") ;
172+ Console . WriteLine ( $ "-=: References are not given") ;
184173
185174 Console . ReadKey ( ) ;
186175
@@ -198,34 +187,50 @@ public static void Main(string[] args)
198187 }
199188
200189 // Read sources
201- var userSources = new string [ sourceFiles . Length ] ;
202- for ( var i = 0 ; i < userSources . Length ; i ++ )
190+ var userSourceFiles = new List < string > ( ) ;
191+ // Add from config
192+ foreach ( var path in userSourcePaths )
203193 {
204- // Add directory to source files paths
205- if ( ! string . IsNullOrWhiteSpace ( baseDirectory ) )
206- {
207- sourceFiles [ i ] = Path . Combine ( baseDirectory , sourceFiles [ i ] ) ;
208- }
209-
210- if ( ! File . Exists ( sourceFiles [ i ] ) )
194+ if ( ! File . Exists ( path ) )
211195 {
212196 Console . ForegroundColor = ConsoleColor . Red ;
213- Console . WriteLine ( $ "-=: Source file not found ({ sourceFiles [ i ] } )") ;
197+ Console . WriteLine ( $ "-=: Source file not found ({ path } )") ;
214198
215199 Console . ReadKey ( ) ;
216200
217201 Environment . Exit ( 5 ) ;
218202 }
219203
220- userSources [ i ] = File . ReadAllText ( sourceFiles [ i ] ) ;
204+ if ( path . EndsWith ( ".cs" ) )
205+ {
206+ userSourceFiles . Add ( File . ReadAllText ( path ) ) ;
207+ }
208+ }
209+ // Add from directory
210+ if ( ! string . IsNullOrWhiteSpace ( baseDirectory ) )
211+ {
212+ userSourceFiles . AddRange ( from path in GetFilesFromDirectory ( baseDirectory ) where path . EndsWith ( ".cs" ) select File . ReadAllText ( path ) ) ;
213+ }
214+
215+ if ( userSourceFiles . Count == 0 )
216+ {
217+ Console . ForegroundColor = ConsoleColor . Red ;
218+ Console . WriteLine ( $ "-=: Source files not found") ;
219+
220+ Console . ReadKey ( ) ;
221+
222+ Environment . Exit ( 2 ) ;
221223 }
222224
223225 Console . ForegroundColor = ConsoleColor . White ;
224226 Console . WriteLine ( "-=: Randomizing..." ) ;
225227
226- for ( var i = 0 ; i < userSources . Length ; i ++ )
228+ // Randomize
229+ for ( var i = 0 ; i < userSourceFiles . Count ; i ++ )
227230 {
228- randomizer . Randomize ( ref userSources [ i ] ) ;
231+ var tmp = userSourceFiles [ i ] ;
232+ randomizer . Randomize ( ref tmp ) ;
233+ userSourceFiles [ i ] = tmp ;
229234 }
230235 for ( var i = 0 ; i < randomizer . InjectSources . Count ; i ++ )
231236 {
@@ -235,8 +240,8 @@ public static void Main(string[] args)
235240 }
236241
237242 // Inject sources
238- var compileSources = userSources . ToList ( ) ;
239- compileSources . AddRange ( randomizer . InjectSources ) ;
243+ var compileSourceFiles = userSourceFiles . ToList ( ) ;
244+ compileSourceFiles . AddRange ( randomizer . InjectSources ) ;
240245
241246 // Inject bytes
242247 if ( randomizer . InjectBytes . Count > 0 )
@@ -249,7 +254,7 @@ public static void Main(string[] args)
249254 output . Remove ( output . Length - 1 , 1 ) ;
250255 output . Append ( "}" ) ;
251256
252- compileSources . Add ( $ "namespace { randomizer . InjectBytesNamespace } " +
257+ compileSourceFiles . Add ( $ "namespace { randomizer . InjectBytesNamespace } " +
253258 $ "{{" +
254259 $ "public static class { randomizer . InjectBytesClass } " +
255260 $ "{{" +
@@ -269,7 +274,7 @@ public static void Main(string[] args)
269274 output . Remove ( output . Length - 1 , 1 ) ;
270275 output . Append ( "}" ) ;
271276
272- compileSources . Add ( $ "namespace { randomizer . InjectBoolsNamespace } " +
277+ compileSourceFiles . Add ( $ "namespace { randomizer . InjectBoolsNamespace } " +
273278 $ "{{" +
274279 $ "public static class { randomizer . InjectBoolsClass } " +
275280 $ "{{" +
@@ -289,7 +294,7 @@ public static void Main(string[] args)
289294 output . Remove ( output . Length - 1 , 1 ) ;
290295 output . Append ( "}" ) ;
291296
292- compileSources . Add ( $ "namespace { randomizer . InjectIntsNamespace } " +
297+ compileSourceFiles . Add ( $ "namespace { randomizer . InjectIntsNamespace } " +
293298 $ "{{" +
294299 $ "public static class { randomizer . InjectIntsClass } " +
295300 $ "{{" +
@@ -309,7 +314,7 @@ public static void Main(string[] args)
309314 output . Remove ( output . Length - 1 , 1 ) ;
310315 output . Append ( "}" ) ;
311316
312- compileSources . Add ( $ "namespace { randomizer . InjectStringsNamespace } " +
317+ compileSourceFiles . Add ( $ "namespace { randomizer . InjectStringsNamespace } " +
313318 $ "{{" +
314319 $ "public static class { randomizer . InjectStringsClass } " +
315320 $ "{{" +
@@ -318,20 +323,20 @@ public static void Main(string[] args)
318323 $ "}}") ;
319324 }
320325
321- // Inject assemblies
322- var compileAssemblies = userAssemblies . ToList ( ) ;
326+ // Inject references
327+ var compileReferences = userReferences . ToList ( ) ;
323328 foreach ( var t in randomizer . InjectAssemblies )
324329 {
325- if ( compileAssemblies . All ( a => a != t ) )
330+ if ( compileReferences . All ( a => a != t ) )
326331 {
327- compileAssemblies . Add ( t ) ;
332+ compileReferences . Add ( t ) ;
328333 }
329334 }
330335
331336 Console . ForegroundColor = ConsoleColor . White ;
332337 Console . WriteLine ( "-=: Compiling..." ) ;
333338
334- compiler . Compile ( outputName , compilerArguments , compileAssemblies . ToArray ( ) , compileSources . ToArray ( ) ) ;
339+ compiler . Compile ( outputName , compilerArguments , compileReferences . ToArray ( ) , compileSourceFiles . ToArray ( ) ) ;
335340
336341 if ( autoRun && File . Exists ( outputName ) )
337342 {
@@ -346,7 +351,7 @@ public static void Main(string[] args)
346351 Environment . Exit ( 0 ) ;
347352 }
348353
349- private static List < string > GetFilesFromDirectory ( string directory )
354+ private static IEnumerable < string > GetFilesFromDirectory ( string directory )
350355 {
351356 var dir = new DirectoryInfo ( directory ) ;
352357
0 commit comments