1
- //using CommandLine;
2
- //using CommandLine.Text;
3
- //using System;
4
- //using System.Collections.Generic;
5
- //using System.IO;
6
- //using System.Text;
7
- //using System.Xml;
1
+
2
+ using System ;
3
+ using System . Collections . Generic ;
4
+ using System . Diagnostics ;
5
+ using System . IO ;
6
+ using System . Net ;
7
+ using System . Text ;
8
+ using System . Xml ;
8
9
9
10
namespace PLBuilder
10
11
{
@@ -31,13 +32,15 @@ namespace PLBuilder
31
32
32
33
class PLBuilderMain
33
34
{
35
+
36
+
34
37
static private XmlTextReader _programConf ;
35
38
static private XmlTextReader _userConf ;
36
39
static private string _saveDir ;
37
40
static private List < String > _savedFiles ;
38
41
static private List < String > _dictionary ;
39
42
static private List < String > _usedWords ;
40
- static private Random _randGen ;
43
+ static private Random _randGen ;
41
44
42
45
static void Main ( string [ ] args )
43
46
{
@@ -75,20 +78,20 @@ static void Main(string[] args)
75
78
PrintNorm ( "Getting Template Source Files From:" + projectFile ) ;
76
79
77
80
PrintNorm ( "Saving Template Files" ) ;
78
- var fileNames = GetFileNames ( projectFile , ! projectFile . Contains ( ":\\ " ) ) ;
81
+ List < string > fileNames = GetFileNames ( projectFile , ! projectFile . Contains ( ":\\ " ) ) ;
79
82
80
83
string functionsFile = "" ;
81
- foreach ( var name in fileNames )
84
+ foreach ( string name in fileNames )
82
85
{
83
- if ( name . Contains ( "Functions.cs" ) )
86
+ if ( name . Contains ( "Functions.cs" ) )
84
87
{
85
88
functionsFile = name ;
86
89
break ;
87
90
}
88
91
}
89
92
90
- var remScripts = getRemoteScriptList ( ) ;
91
- var localScripts = getRemoteScriptList ( ) ;
93
+ List < string > remScripts = getRemoteScriptList ( ) ;
94
+ List < string > localScripts = getRemoteScriptList ( ) ;
92
95
93
96
PrintNorm ( "Building Obfuscation Dictionary From: " + dictionaryFile ) ;
94
97
buildDictionary ( dictionaryFile ) ;
@@ -114,7 +117,7 @@ static void buildDictionary(string dictionaryFile)
114
117
_dictionary = new List < string > ( ) ;
115
118
_usedWords = new List < string > ( ) ;
116
119
117
- foreach ( var currWord in File . ReadAllLines ( dictionaryFile ) )
120
+ foreach ( string currWord in File . ReadAllLines ( dictionaryFile ) )
118
121
{
119
122
_dictionary . Add ( currWord ) ;
120
123
}
@@ -131,14 +134,14 @@ static List<string> GetFileNames(string projectFile, bool relative)
131
134
projectFile = Path . GetFullPath ( Path . Combine ( folder , @projectFile ) ) ;
132
135
}
133
136
134
- var fin = File . ReadAllLines ( projectFile ) ;
137
+ string [ ] fin = File . ReadAllLines ( projectFile ) ;
135
138
136
- string projectFolder = Path . GetDirectoryName ( projectFile ) ;
139
+ System . String projectFolder = Path . GetDirectoryName ( projectFile ) ;
137
140
_saveDir = Path . Combine ( projectFolder , "plsave" ) ;
138
141
139
- foreach ( var line in fin )
142
+ foreach ( string line in fin )
140
143
{
141
- if ( line . Contains ( ".cs" ) )
144
+ if ( line . Contains ( ".cs" ) )
142
145
{
143
146
string fileNameCurr = line . Split ( '"' ) [ 1 ] ;
144
147
string fileNamePath = Path . Combine ( projectFolder , fileNameCurr ) ;
@@ -185,7 +188,7 @@ static void DirectoryCopy(string sourceDirName, string destDirName, bool copySub
185
188
foreach ( FileInfo file in files )
186
189
{
187
190
string temppath = Path . Combine ( destDirName , file . Name ) ;
188
- file . CopyTo ( temppath , true ) ;
191
+ file . CopyTo ( temppath , true ) ;
189
192
}
190
193
191
194
// If copying subdirectories, copy them and their contents to new location.
@@ -229,16 +232,16 @@ static bool writeFunctionFile(string functionsFile, List<string> remScripts, Lis
229
232
{
230
233
//make this better at some point
231
234
232
- var fin = System . IO . File . ReadAllLines ( functionsFile ) ;
235
+ string [ ] fin = File . ReadAllLines ( functionsFile ) ;
233
236
234
237
StreamWriter fout = new StreamWriter ( functionsFile , false ) ;
235
238
236
239
int idx = 0 ;
237
240
238
- foreach ( var line in fin )
241
+ foreach ( string line in fin )
239
242
{
240
243
idx ++ ;
241
- if ( line . Contains ( "$$$" ) )
244
+ if ( line . Contains ( "$$$" ) )
242
245
{
243
246
break ;
244
247
}
@@ -247,42 +250,45 @@ static bool writeFunctionFile(string functionsFile, List<string> remScripts, Lis
247
250
}
248
251
249
252
//write the XOR key
250
- byte dKey = Convert . ToByte ( GetLetter ( ) ) ;
251
- fout . WriteLine ( "\t \t \t dKey = \' " + ( char ) dKey + "\' ;" ) ;
253
+ byte dKey = Convert . ToByte ( GetLetter ( ) ) ;
254
+ fout . WriteLine ( "\t \t \t dKey = \' " + ( char ) dKey + "\' ;" ) ;
252
255
253
256
PrintNorm ( "Importing and Encoding Scripts" ) ;
254
257
255
- foreach ( var script in remScripts )
258
+ foreach ( string script in remScripts )
256
259
{
257
- var scriptName = script . Substring ( script . LastIndexOf ( '/' ) + 1 ) ;
258
- using ( var client = new WebClient ( ) )
260
+ string scriptName = script . Substring ( script . LastIndexOf ( '/' ) + 1 ) ;
261
+ using ( WebClient client = new WebClient ( ) )
259
262
{
260
- Console . WriteLine ( "\t " + script + "\r \n " ) ;
261
- client . DownloadFile ( new Uri ( script ) , scriptName ) ;
262
- Byte [ ] bytes = File . ReadAllBytes ( scriptName ) ;
263
-
264
- //XOR "encrypt"
265
- for ( int i = 0 ; i < bytes . Length ; i ++ )
263
+ using ( MemoryStream mStream = new MemoryStream ( client . DownloadData ( new Uri ( script ) ) ) )
266
264
{
267
- bytes [ i ] ^= dKey ;
268
- }
269
265
270
- string b64XorScript = Convert . ToBase64String ( bytes ) ;
266
+ Console . WriteLine ( "\t " + script + "\r \n " ) ;
267
+ byte [ ] bytes = mStream . ToArray ( ) ;
271
268
272
- //Lop off PS1 or other file extension from scriptname
273
- Byte [ ] moduleName = Encoding . UTF8 . GetBytes ( scriptName . Split ( '.' ) [ 0 ] ) ;
274
- Byte [ ] outModuleName = new Byte [ moduleName . Length ] ;
269
+ //XOR "encrypt"
270
+ for ( int i = 0 ; i < bytes . Length ; i ++ )
271
+ {
272
+ bytes [ i ] ^= dKey ;
273
+ }
275
274
276
- for ( int i = 0 ; i < moduleName . Length ; i ++ )
277
- {
278
- outModuleName [ i ] = ( byte ) ( moduleName [ i ] ^ dKey ) ;
279
- }
275
+ string b64XorScript = Convert . ToBase64String ( bytes ) ;
280
276
281
- fout . WriteLine ( "\t \t \t Funcs.Add(\" " + Convert . ToBase64String ( outModuleName ) + "\" ,\" " + b64XorScript + "\" );" ) ;
277
+ //Lop off PS1 or other file extension from scriptname
278
+ Byte [ ] moduleName = Encoding . UTF8 . GetBytes ( scriptName . Split ( '.' ) [ 0 ] ) ;
279
+ Byte [ ] outModuleName = new Byte [ moduleName . Length ] ;
280
+
281
+ for ( int i = 0 ; i < moduleName . Length ; i ++ )
282
+ {
283
+ outModuleName [ i ] = ( byte ) ( moduleName [ i ] ^ dKey ) ;
284
+ }
285
+
286
+ fout . WriteLine ( "\t \t \t Funcs.Add(\" " + Convert . ToBase64String ( outModuleName ) + "\" ,\" " + b64XorScript + "\" );" ) ;
287
+ }
282
288
}
283
289
}
284
290
285
- for ( int i = idx ; i < fin . Length ; i ++ )
291
+ for ( int i = idx ; i < fin . Length ; i ++ )
286
292
{
287
293
fout . WriteLine ( fin [ i ] ) ;
288
294
}
@@ -294,27 +300,22 @@ static bool writeFunctionFile(string functionsFile, List<string> remScripts, Lis
294
300
string currPath = Path . GetDirectoryName ( Process . GetCurrentProcess ( ) . MainModule . FileName ) ;
295
301
string fullPath = Path . Combine ( Path . GetDirectoryName ( functionsFile ) , "PowerLineTemplate.sln" ) ;
296
302
297
- Console . Out . Flush ( ) ;
298
-
299
303
Process cmd = new Process ( ) ;
300
304
cmd . StartInfo . FileName = "cmd.exe" ;
301
- cmd . StartInfo . Arguments = "/c " + @"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe " + fullPath + @" /t:rebuild /p:Configuration=Release /p:Platform=x64" ;
302
- // cmd.StartInfo.RedirectStandardOutput = true;
303
- //cmd.StartInfo.RedirectStandardError = true;
305
+ cmd . StartInfo . CreateNoWindow = true ;
306
+ cmd . StartInfo . Arguments = "/c " + @"C:\Windows\Microsoft.NET\Framework64\v2.0.50727\MSBuild.exe " + fullPath + @" /t:rebuild /p:Configuration=Release /p:Platform=x64" ;
304
307
cmd . StartInfo . UseShellExecute = false ;
305
308
cmd . Start ( ) ;
306
309
cmd . WaitForExit ( ) ;
307
310
308
- return ( cmd . ExitCode == 0 ) ;
309
- //Console.WriteLine(cmd.StandardOutput.ReadToEnd());
310
- //Console.WriteLine(cmd.StandardError.ReadToEnd());
311
+ return ( cmd . ExitCode == 0 ) ;
311
312
}
312
313
313
314
public static void restoreFiles ( )
314
315
{
315
316
string [ ] splitVal = new string [ ] { "$$$" } ;
316
-
317
- foreach ( var name in _savedFiles )
317
+
318
+ foreach ( string name in _savedFiles )
318
319
{
319
320
string destPath = name . Split ( splitVal , StringSplitOptions . RemoveEmptyEntries ) [ 0 ] ;
320
321
string srcPath = name . Split ( splitVal , StringSplitOptions . RemoveEmptyEntries ) [ 1 ] ;
@@ -338,7 +339,7 @@ public static string GetWord()
338
339
while ( true )
339
340
{
340
341
int num = _randGen . Next ( 0 , _dictionary . Count - 1 ) ;
341
- if ( ! _usedWords . Contains ( _dictionary [ num ] ) )
342
+ if ( ! _usedWords . Contains ( _dictionary [ num ] ) )
342
343
{
343
344
_usedWords . Add ( _dictionary [ num ] ) ;
344
345
return _dictionary [ num ] ;
@@ -363,5 +364,5 @@ public static void PrintError(string msg)
363
364
364
365
Console . ResetColor ( ) ;
365
366
}
366
- }
367
+ }
367
368
}
0 commit comments