Skip to content

Commit 911d086

Browse files
Got bat file working with .NET v2 now, which should make it more likely to be compatible in most environs.
The Visual Studio likes to update the SLN file Version numbers and MSBuild can only due 7.0-9.0 if your using .NET 2.0. Keep an eye out for that. Changed code so scripts go to memory when downloaded rather than disk. AV was detecting when they hit disk but not anymore =)
1 parent 9cea1b8 commit 911d086

12 files changed

+105
-120
lines changed

.gitignore

+16
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,19 @@ ModelManifest.xml
254254
/PowerLine/PowerLineTemplate/Functions.cs
255255
/PowerLine/PowerLine.exe
256256
/PowerLine/funcs_save.txt
257+
/PowerLine/xjis.nlp
258+
/PowerLine/sorttbls.nlp
259+
/PowerLine/sortkey.nlp
260+
/PowerLine/prcp.nlp
261+
/PowerLine/prc.nlp
262+
/PowerLine/PLBuilder.vshost.exe.manifest
263+
/PowerLine/PLBuilder.vshost.exe
264+
/PowerLine/PLBuilder.exe
265+
/PowerLine/normnfkd.nlp
266+
/PowerLine/normnfkc.nlp
267+
/PowerLine/normnfd.nlp
268+
/PowerLine/normnfc.nlp
269+
/PowerLine/normidna.nlp
270+
/PowerLine/ksc.nlp
271+
/PowerLine/bopomofo.nlp
272+
/PowerLine/big5.nlp
File renamed without changes.

PowerLine/PLBuilderMain.cs

+58-57
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
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;
89

910
namespace PLBuilder
1011
{
@@ -31,13 +32,15 @@ namespace PLBuilder
3132

3233
class PLBuilderMain
3334
{
35+
36+
3437
static private XmlTextReader _programConf;
3538
static private XmlTextReader _userConf;
3639
static private string _saveDir;
3740
static private List<String> _savedFiles;
3841
static private List<String> _dictionary;
3942
static private List<String> _usedWords;
40-
static private Random _randGen;
43+
static private Random _randGen;
4144

4245
static void Main(string[] args)
4346
{
@@ -75,20 +78,20 @@ static void Main(string[] args)
7578
PrintNorm("Getting Template Source Files From:" + projectFile);
7679

7780
PrintNorm("Saving Template Files");
78-
var fileNames = GetFileNames(projectFile, !projectFile.Contains(":\\"));
81+
List<string> fileNames = GetFileNames(projectFile, !projectFile.Contains(":\\"));
7982

8083
string functionsFile = "";
81-
foreach(var name in fileNames)
84+
foreach (string name in fileNames)
8285
{
83-
if(name.Contains("Functions.cs"))
86+
if (name.Contains("Functions.cs"))
8487
{
8588
functionsFile = name;
8689
break;
8790
}
8891
}
8992

90-
var remScripts = getRemoteScriptList();
91-
var localScripts = getRemoteScriptList();
93+
List<string> remScripts = getRemoteScriptList();
94+
List<string> localScripts = getRemoteScriptList();
9295

9396
PrintNorm("Building Obfuscation Dictionary From: " + dictionaryFile);
9497
buildDictionary(dictionaryFile);
@@ -114,7 +117,7 @@ static void buildDictionary(string dictionaryFile)
114117
_dictionary = new List<string>();
115118
_usedWords = new List<string>();
116119

117-
foreach(var currWord in File.ReadAllLines(dictionaryFile))
120+
foreach (string currWord in File.ReadAllLines(dictionaryFile))
118121
{
119122
_dictionary.Add(currWord);
120123
}
@@ -131,14 +134,14 @@ static List<string> GetFileNames(string projectFile, bool relative)
131134
projectFile = Path.GetFullPath(Path.Combine(folder, @projectFile));
132135
}
133136

134-
var fin = File.ReadAllLines(projectFile);
137+
string[] fin = File.ReadAllLines(projectFile);
135138

136-
string projectFolder = Path.GetDirectoryName(projectFile);
139+
System.String projectFolder = Path.GetDirectoryName(projectFile);
137140
_saveDir = Path.Combine(projectFolder, "plsave");
138141

139-
foreach (var line in fin)
142+
foreach (string line in fin)
140143
{
141-
if(line.Contains(".cs"))
144+
if (line.Contains(".cs"))
142145
{
143146
string fileNameCurr = line.Split('"')[1];
144147
string fileNamePath = Path.Combine(projectFolder, fileNameCurr);
@@ -185,7 +188,7 @@ static void DirectoryCopy(string sourceDirName, string destDirName, bool copySub
185188
foreach (FileInfo file in files)
186189
{
187190
string temppath = Path.Combine(destDirName, file.Name);
188-
file.CopyTo(temppath,true);
191+
file.CopyTo(temppath, true);
189192
}
190193

191194
// If copying subdirectories, copy them and their contents to new location.
@@ -229,16 +232,16 @@ static bool writeFunctionFile(string functionsFile, List<string> remScripts, Lis
229232
{
230233
//make this better at some point
231234

232-
var fin = System.IO.File.ReadAllLines(functionsFile);
235+
string[] fin = File.ReadAllLines(functionsFile);
233236

234237
StreamWriter fout = new StreamWriter(functionsFile, false);
235238

236239
int idx = 0;
237240

238-
foreach(var line in fin)
241+
foreach (string line in fin)
239242
{
240243
idx++;
241-
if(line.Contains("$$$"))
244+
if (line.Contains("$$$"))
242245
{
243246
break;
244247
}
@@ -247,42 +250,45 @@ static bool writeFunctionFile(string functionsFile, List<string> remScripts, Lis
247250
}
248251

249252
//write the XOR key
250-
byte dKey = Convert.ToByte( GetLetter() );
251-
fout.WriteLine("\t\t\tdKey = \'" + (char) dKey + "\';");
253+
byte dKey = Convert.ToByte(GetLetter());
254+
fout.WriteLine("\t\t\tdKey = \'" + (char)dKey + "\';");
252255

253256
PrintNorm("Importing and Encoding Scripts");
254257

255-
foreach(var script in remScripts)
258+
foreach (string script in remScripts)
256259
{
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())
259262
{
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))))
266264
{
267-
bytes[i] ^= dKey;
268-
}
269265

270-
string b64XorScript = Convert.ToBase64String(bytes);
266+
Console.WriteLine("\t" + script + "\r\n");
267+
byte[] bytes = mStream.ToArray();
271268

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+
}
275274

276-
for (int i =0; i < moduleName.Length; i++)
277-
{
278-
outModuleName[i] = (byte)(moduleName[i] ^ dKey);
279-
}
275+
string b64XorScript = Convert.ToBase64String(bytes);
280276

281-
fout.WriteLine("\t\t\tFuncs.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\tFuncs.Add(\"" + Convert.ToBase64String(outModuleName) + "\",\"" + b64XorScript + "\");");
287+
}
282288
}
283289
}
284290

285-
for(int i = idx; i < fin.Length; i++)
291+
for (int i = idx; i < fin.Length; i++)
286292
{
287293
fout.WriteLine(fin[i]);
288294
}
@@ -294,27 +300,22 @@ static bool writeFunctionFile(string functionsFile, List<string> remScripts, Lis
294300
string currPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
295301
string fullPath = Path.Combine(Path.GetDirectoryName(functionsFile), "PowerLineTemplate.sln");
296302

297-
Console.Out.Flush();
298-
299303
Process cmd = new Process();
300304
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";
304307
cmd.StartInfo.UseShellExecute = false;
305308
cmd.Start();
306309
cmd.WaitForExit();
307310

308-
return(cmd.ExitCode == 0);
309-
//Console.WriteLine(cmd.StandardOutput.ReadToEnd());
310-
//Console.WriteLine(cmd.StandardError.ReadToEnd());
311+
return (cmd.ExitCode == 0);
311312
}
312313

313314
public static void restoreFiles()
314315
{
315316
string[] splitVal = new string[] { "$$$" };
316-
317-
foreach(var name in _savedFiles)
317+
318+
foreach (string name in _savedFiles)
318319
{
319320
string destPath = name.Split(splitVal, StringSplitOptions.RemoveEmptyEntries)[0];
320321
string srcPath = name.Split(splitVal, StringSplitOptions.RemoveEmptyEntries)[1];
@@ -338,7 +339,7 @@ public static string GetWord()
338339
while (true)
339340
{
340341
int num = _randGen.Next(0, _dictionary.Count - 1);
341-
if ( !_usedWords.Contains( _dictionary[num] ) )
342+
if (!_usedWords.Contains(_dictionary[num]))
342343
{
343344
_usedWords.Add(_dictionary[num]);
344345
return _dictionary[num];
@@ -363,5 +364,5 @@ public static void PrintError(string msg)
363364

364365
Console.ResetColor();
365366
}
366-
}
367+
}
367368
}

PowerLine/PowerLineSave.csproj PowerLine/PowerLine.csproj

+14-41
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project ToolsVersion="2.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
66
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7-
<ProjectGuid>{6507E3D4-0DD7-4F6B-ADEC-897B045BE599}</ProjectGuid>
7+
<ProjectGuid>{05B57AFC-134D-4495-94DF-F9E721772572}</ProjectGuid>
88
<OutputType>Exe</OutputType>
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>PowerLine</RootNamespace>
11-
<AssemblyName>PLBuild</AssemblyName>
11+
<AssemblyName>PLBuilder</AssemblyName>
1212
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
14-
<NuGetPackageImportStamp>
15-
</NuGetPackageImportStamp>
16-
<TargetFrameworkProfile />
1714
</PropertyGroup>
1815
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1916
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -25,59 +22,35 @@
2522
<ErrorReport>prompt</ErrorReport>
2623
<WarningLevel>4</WarningLevel>
2724
</PropertyGroup>
28-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29-
<PlatformTarget>AnyCPU</PlatformTarget>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
26+
<PlatformTarget>x64</PlatformTarget>
3027
<DebugType>pdbonly</DebugType>
3128
<Optimize>true</Optimize>
32-
<OutputPath>bin\Release\</OutputPath>
33-
<DefineConstants>TRACE</DefineConstants>
34-
<ErrorReport>prompt</ErrorReport>
35-
<WarningLevel>4</WarningLevel>
36-
</PropertyGroup>
37-
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
38-
<DebugSymbols>true</DebugSymbols>
39-
<OutputPath>bin\x64\Debug\</OutputPath>
40-
<DefineConstants>DEBUG;TRACE</DefineConstants>
41-
<DebugType>full</DebugType>
42-
<PlatformTarget>x64</PlatformTarget>
43-
<ErrorReport>prompt</ErrorReport>
44-
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
45-
</PropertyGroup>
46-
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
4729
<OutputPath>.\</OutputPath>
4830
<DefineConstants>TRACE</DefineConstants>
49-
<Optimize>true</Optimize>
50-
<DebugType>pdbonly</DebugType>
51-
<PlatformTarget>x64</PlatformTarget>
5231
<ErrorReport>prompt</ErrorReport>
53-
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
54-
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
55-
<DebugSymbols>true</DebugSymbols>
32+
<WarningLevel>4</WarningLevel>
5633
</PropertyGroup>
5734
<PropertyGroup />
58-
<PropertyGroup />
59-
<PropertyGroup>
60-
<StartupObject />
61-
</PropertyGroup>
6235
<ItemGroup>
6336
<Compile Include="PLBuilderMain.cs" />
6437
<Compile Include="Properties\AssemblyInfo.cs" />
6538
</ItemGroup>
6639
<ItemGroup>
67-
<Content Include="CleanVars.txt" />
68-
<Content Include="ProgramConf.xml" />
69-
<Content Include="UserConf.xml" />
40+
<Reference Include="System" />
41+
<Reference Include="System.Configuration.Install" />
42+
<Reference Include="System.Management" />
43+
<Reference Include="System.XML" />
7044
</ItemGroup>
7145
<ItemGroup>
72-
<None Include="app.config" />
7346
<None Include="build.bat" />
7447
</ItemGroup>
7548
<ItemGroup>
76-
<Reference Include="System">
77-
<HintPath>..\..\..\..\..\..\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll</HintPath>
78-
</Reference>
49+
<Content Include="CleanVars.txt" />
50+
<Content Include="ProgramConf.xml" />
51+
<Content Include="UserConf.xml" />
7952
</ItemGroup>
80-
<!--<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />-->
53+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
8154
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
8255
Other similar extension points exist, see Microsoft.Common.targets.
8356
<Target Name="BeforeBuild">

PowerLine/PowerLine.sln

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

2-
Microsoft Visual Studio Solution File, Format Version 12.00
2+
Microsoft Visual Studio Solution File, Format Version 9.00
33
# Visual Studio 14
44
VisualStudioVersion = 14.0.25420.1
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PowerLineSave", "PowerLineSave.csproj", "{6507E3D4-0DD7-4F6B-ADEC-897B045BE599}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PowerLine", "PowerLine.csproj", "{05B57AFC-134D-4495-94DF-F9E721772572}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -13,14 +13,14 @@ Global
1313
Release|x64 = Release|x64
1414
EndGlobalSection
1515
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16-
{6507E3D4-0DD7-4F6B-ADEC-897B045BE599}.Debug|Any CPU.ActiveCfg = Release|x64
17-
{6507E3D4-0DD7-4F6B-ADEC-897B045BE599}.Debug|Any CPU.Build.0 = Release|x64
18-
{6507E3D4-0DD7-4F6B-ADEC-897B045BE599}.Debug|x64.ActiveCfg = Debug|x64
19-
{6507E3D4-0DD7-4F6B-ADEC-897B045BE599}.Debug|x64.Build.0 = Debug|x64
20-
{6507E3D4-0DD7-4F6B-ADEC-897B045BE599}.Release|Any CPU.ActiveCfg = Release|Any CPU
21-
{6507E3D4-0DD7-4F6B-ADEC-897B045BE599}.Release|Any CPU.Build.0 = Release|Any CPU
22-
{6507E3D4-0DD7-4F6B-ADEC-897B045BE599}.Release|x64.ActiveCfg = Release|x64
23-
{6507E3D4-0DD7-4F6B-ADEC-897B045BE599}.Release|x64.Build.0 = Release|x64
16+
{05B57AFC-134D-4495-94DF-F9E721772572}.Debug|Any CPU.ActiveCfg = Release|Any CPU
17+
{05B57AFC-134D-4495-94DF-F9E721772572}.Debug|Any CPU.Build.0 = Release|Any CPU
18+
{05B57AFC-134D-4495-94DF-F9E721772572}.Debug|x64.ActiveCfg = Debug|x64
19+
{05B57AFC-134D-4495-94DF-F9E721772572}.Debug|x64.Build.0 = Debug|x64
20+
{05B57AFC-134D-4495-94DF-F9E721772572}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{05B57AFC-134D-4495-94DF-F9E721772572}.Release|Any CPU.Build.0 = Release|Any CPU
22+
{05B57AFC-134D-4495-94DF-F9E721772572}.Release|x64.ActiveCfg = Release|x64
23+
{05B57AFC-134D-4495-94DF-F9E721772572}.Release|x64.Build.0 = Release|x64
2424
EndGlobalSection
2525
GlobalSection(SolutionProperties) = preSolution
2626
HideSolutionNode = FALSE

PowerLine/PowerLineTemplate/Functions.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ class Functions
1010
public static void InitDictionary()
1111
{
1212
Funcs = new Dictionary<string, string>();
13-
//Lots-o-space below, don't change the dollar sign line
13+
//Don't change the dollar sign line
1414
//$$$
15-
16-
1715
}
1816
}
19-
}
17+
}

0 commit comments

Comments
 (0)