1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-11-30 05:19:53 +03:00
SoftEtherVPN/src/BuildUtil/Win32BuildUtil.cs

1351 lines
49 KiB
C#
Raw Normal View History

2017-10-19 05:48:23 +03:00
// SoftEther VPN Source Code - Developer Edition Master Branch
2014-01-04 17:00:08 +04:00
// Build Utility
using System;
using System.Threading;
using System.Text;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Security.Cryptography;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Diagnostics;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using CoreUtil;
namespace BuildUtil
{
// Build utility for Win32
public static class Win32BuildUtil
{
// Generate vpnweb.ocx
public static void GenerateVpnWebOcxCab(string dstFileName, string ocxFileName)
{
int versionMajor, versionMinor, versionBuild;
2014-01-04 17:00:08 +04:00
string name;
DateTime date;
ReadBuildInfoFromTextFile(out versionMajor, out versionMinor, out versionBuild, out name, out date);
2014-01-04 17:00:08 +04:00
string cabVer = string.Format("{0},{1},0,{2}", versionMajor, versionMinor, versionBuild);
2014-01-04 17:00:08 +04:00
string cabFileName = IO.CreateTempFileNameByExt(".cab");
Mutex m = new Mutex(false, "cabtmp_mutex");
m.WaitOne();
try
{
// Building the cab
string cabTmpDir = Path.Combine(Paths.TmpDirName, "cabtmp");
IO.MakeDir(cabTmpDir);
IO.DeleteFilesAndSubDirsInDir(cabTmpDir);
File.Copy(Path.Combine(Paths.BinDirName, ocxFileName), Path.Combine(cabTmpDir, "vpnweb.ocx"));
string infText = File.ReadAllText(Path.Combine(Path.Combine(Paths.BaseDirName, @"BuildFiles\OcxCabInf"), "vpnweb.inf"));
infText = Str.ReplaceStr(infText, "$CAB_VERSION$", cabVer);
File.WriteAllText(Path.Combine(cabTmpDir, "vpnweb.inf"), infText);
Win32BuildUtil.ExecCommand(Path.Combine(Paths.BaseDirName, @"BuildFiles\Utility\cabarc.exe"),
string.Format(@"-s 6144 n {0}\vpnweb.cab {0}\vpnweb.ocx {0}\vpnweb.inf", cabTmpDir));
File.Copy(Path.Combine(cabTmpDir, "vpnweb.cab"), cabFileName, true);
}
finally
{
m.ReleaseMutex();
}
CodeSign.SignFile(cabFileName, cabFileName, "VPN Software", false);
File.Copy(cabFileName, dstFileName, true);
}
// Generate a version information resource
2015-05-31 13:02:35 +03:00
public static void GenerateVersionInfoResource(string targetExeName, string outName, string rc_name, string product_name)
2014-01-04 17:00:08 +04:00
{
int versionMajor, versionMinor, versionBuild;
2014-01-04 17:00:08 +04:00
string name;
DateTime date;
ReadBuildInfoFromTextFile(out versionMajor, out versionMinor, out versionBuild, out name, out date);
2014-01-04 17:00:08 +04:00
if (Str.IsEmptyStr(rc_name))
{
rc_name = "ver.rc";
}
string templateFileName = Path.Combine(Paths.BaseDirName, @"BuildFiles\VerScript\" + rc_name);
string body = Str.ReadTextFile(templateFileName);
string exeFileName = Path.GetFileName(targetExeName);
string internalName = Path.GetFileNameWithoutExtension(exeFileName);
#if !BU_SOFTETHER
2018-11-27 06:48:46 +03:00
body = Str.ReplaceStr(body, "${PROJECT_NAME}", "PacketiX VPN");
2014-01-04 17:00:08 +04:00
#else
2018-11-27 06:48:46 +03:00
body = Str.ReplaceStr(body, "${PROJECT_NAME}", "SoftEther VPN");
2014-01-04 17:00:08 +04:00
#endif
2018-11-27 06:48:46 +03:00
body = Str.ReplaceStr(body, "${COMPONENT_NAME}", product_name);
body = Str.ReplaceStr(body, "${COMPONENT_INTERNAL_NAME}", internalName);
body = Str.ReplaceStr(body, "${DATE_YEAR}", date.Year.ToString());
body = Str.ReplaceStr(body, "${COMPONENT_FILE_NAME}", exeFileName);
body = Str.ReplaceStr(body, "${PROJECT_VERSION_MAJOR}", versionMajor.ToString());
body = Str.ReplaceStr(body, "${PROJECT_VERSION_MINOR}", versionMinor.ToString());
body = Str.ReplaceStr(body, "${PROJECT_VERSION_PATCH}", versionBuild.ToString());
2014-01-04 17:00:08 +04:00
IO f = IO.CreateTempFileByExt(".rc");
string filename = f.Name;
f.Write(Str.AsciiEncoding.GetBytes(body));
f.Close();
ExecCommand(Paths.RcFilename, "\"" + filename + "\"");
string rcDir = Path.GetDirectoryName(filename);
string rcFilename = Path.GetFileName(filename);
string rcFilename2 = Path.GetFileNameWithoutExtension(rcFilename);
string resFilename = Path.Combine(rcDir, rcFilename2) + ".res";
IO.MakeDirIfNotExists(Path.GetDirectoryName(outName));
IO.FileCopy(resFilename, outName, true, false);
}
// Flush to disk
public static void Flush()
{
string txt = IO.CreateTempFileNameByExt(".txt");
byte[] ret = Secure.Rand(64);
FileStream f = File.Create(txt);
f.Write(ret, 0, ret.Length);
f.Flush();
f.Close();
File.Delete(txt);
}
// Increment the build number
public static void IncrementBuildNumber()
{
int versionMajor, versionMinor, versionBuild;
2014-01-04 17:00:08 +04:00
string name;
DateTime date;
ReadBuildInfoFromTextFile(out versionMajor, out versionMinor, out versionBuild, out name, out date);
versionBuild++;
2014-01-04 17:00:08 +04:00
WriteBuildInfoToTextFile(versionMajor, versionMinor, versionBuild, name, date);
2014-01-04 17:00:08 +04:00
SetNowDate();
Con.WriteLine("New build number: {0}", versionBuild);
2014-01-04 17:00:08 +04:00
}
// Set the date and time
public static void SetNowDate()
{
int versionMajor, versionMinor, versionBuild;
2014-01-04 17:00:08 +04:00
string name;
DateTime date;
ReadBuildInfoFromTextFile(out versionMajor, out versionMinor, out versionBuild, out name, out date);
2014-01-04 17:00:08 +04:00
date = DateTime.Now;
WriteBuildInfoToTextFile(versionMajor, versionMinor, versionBuild, name, date);
2014-01-04 17:00:08 +04:00
}
// Write the build number and the version number in the text file
public static void WriteBuildInfoToTextFile(int versionMajor, int versionMinor, int versionBuild, string name, DateTime date)
2014-01-04 17:00:08 +04:00
{
string filename = Path.Combine(Paths.BaseDirName, "CurrentBuild.txt");
WriteBuildInfoToTextFile(versionMajor, versionMinor, versionBuild, name, date, filename);
2014-01-04 17:00:08 +04:00
}
public static void WriteBuildInfoToTextFile(int versionMajor, int versionMinor, int versionBuild, string name, DateTime date, string filename)
2014-01-04 17:00:08 +04:00
{
using (StreamWriter w = new StreamWriter(filename))
{
w.WriteLine("VERSION_MAJOR {0}", versionMajor);
w.WriteLine("VERSION_MINOR {0}", versionMinor);
w.WriteLine("VERSION_BUILD {0}", versionBuild);
2014-01-04 17:00:08 +04:00
w.WriteLine("BUILD_NAME {0}", name);
w.WriteLine("BUILD_DATE {0}", Str.DateTimeToStrShort(date));
w.Flush();
w.Close();
}
}
// Read the build number and the version number from a text file
public static void ReadBuildInfoFromTextFile(out int versionMajor, out int versionMinor, out int versionBuild, out string name, out DateTime date)
2014-01-04 17:00:08 +04:00
{
string filename = Path.Combine(Paths.BaseDirName, "CurrentBuild.txt");
ReadBuildInfoFromTextFile(out versionMajor, out versionMinor, out versionBuild, out name, out date, filename);
2014-01-04 17:00:08 +04:00
}
public static void ReadBuildInfoFromTextFile(out int versionMajor, out int versionMinor, out int versionBuild, out string name, out DateTime date, string filename)
2014-01-04 17:00:08 +04:00
{
char[] seps = { '\t', ' ', };
name = "";
date = new DateTime(0);
using (StreamReader r = new StreamReader(filename))
{
versionBuild = versionMinor = versionMajor = 0;
2014-01-04 17:00:08 +04:00
while (true)
{
string line = r.ReadLine();
if (line == null)
{
break;
}
string[] tokens = line.Split(seps, StringSplitOptions.RemoveEmptyEntries);
if (tokens.Length == 2)
{
if (tokens[0].Equals("VERSION_MAJOR", StringComparison.InvariantCultureIgnoreCase))
2014-01-04 17:00:08 +04:00
{
versionMajor = int.Parse(tokens[1]);
2014-01-04 17:00:08 +04:00
}
if (tokens[0].Equals("VERSION_MINOR", StringComparison.InvariantCultureIgnoreCase))
2014-01-04 17:00:08 +04:00
{
versionMinor = int.Parse(tokens[1]);
}
if (tokens[0].Equals("VERSION_BUILD", StringComparison.InvariantCultureIgnoreCase))
{
versionBuild = int.Parse(tokens[1]);
2014-01-04 17:00:08 +04:00
}
if (tokens[0].Equals("BUILD_NAME", StringComparison.InvariantCultureIgnoreCase))
{
name = tokens[1];
name = Str.ReplaceStr(name, "-", "_");
}
if (tokens[0].Equals("BUILD_DATE", StringComparison.InvariantCultureIgnoreCase))
{
date = Str.StrToDateTime(tokens[1]);
}
}
}
r.Close();
if (versionBuild == 0 || versionMinor == 0 || versionMajor == 0 || Str.IsEmptyStr(name) || date.Ticks == 0)
2014-01-04 17:00:08 +04:00
{
throw new ApplicationException(string.Format("Wrong file data: '{0}'", filename));
}
}
}
// Normalize the build information
public static void NormalizeBuildInfo()
{
SetNowDate();
int versionMajor, versionMinor, versionBuild;
2014-01-04 17:00:08 +04:00
string name;
DateTime date;
ReadBuildInfoFromTextFile(out versionMajor, out versionMinor, out versionBuild, out name, out date);
2014-01-04 17:00:08 +04:00
string username = Env.UserName;
string pcname = Env.MachineName;
NormalizeSourceCode(versionMajor, versionMinor, versionBuild, username, pcname, date);
2014-01-04 17:00:08 +04:00
}
// Apply build number, version number, user name, and PC name to the source code
public static void NormalizeSourceCode(int versionMajor, int versionMinor, int versionBuild, string userName, string pcName, DateTime date)
2014-01-04 17:00:08 +04:00
{
DateTime now = date;
char[] seps = { '\t', ' ', };
int i = pcName.IndexOf(".");
if (i != -1)
{
pcName = pcName.Substring(0, i);
}
userName = userName.ToLower();
pcName = pcName.ToLower();
string[] files = Util.CombineArray<string>(
Directory.GetFiles(Paths.BaseDirName, "*.h", SearchOption.AllDirectories));
foreach (string file in files)
{
string dir = Path.GetDirectoryName(file);
if (Str.InStr(dir, @"\.svn\") == false &&
Str.InStr(IO.GetRelativeFileName(file, Paths.BaseDirName), @"tmp\") == false)
{
byte[] srcData = File.ReadAllBytes(file);
int bomSize;
Encoding enc = Str.GetEncoding(srcData, out bomSize);
if (enc == null)
{
enc = Str.Utf8Encoding;
}
StringReader r = new StringReader(enc.GetString(Util.ExtractByteArray(srcData, bomSize, srcData.Length - bomSize)));
StringWriter w = new StringWriter();
bool somethingChanged = false;
while (true)
{
string line = r.ReadLine();
if (line == null)
{
break;
}
string newLine = null;
string[] tokens = line.Split(seps, StringSplitOptions.RemoveEmptyEntries);
if (tokens.Length >= 1)
{
if (file.EndsWith(".h", StringComparison.InvariantCultureIgnoreCase))
{
if (tokens.Length == 3)
{
// Build number portion of the source code
if (tokens[0].Equals("//") && tokens[1].Equals("Build") && Str.IsNumber(tokens[2]))
{
newLine = line.Replace(tokens[2], versionBuild.ToString());
2014-01-04 17:00:08 +04:00
}
}
}
if (file.EndsWith(".h", StringComparison.InvariantCultureIgnoreCase))
{
if (tokens.Length == 3)
{
// String part of the version information of Cedar.h
if (tokens[0].Equals("#define") && tokens[1].Equals("CEDAR_VERSION_MAJOR"))
{
newLine = line.Replace(tokens[2], versionMajor.ToString());
}
if (tokens[0].Equals("#define") && tokens[1].Equals("CEDAR_VERSION_MINOR"))
2014-01-04 17:00:08 +04:00
{
newLine = line.Replace(tokens[2], versionMinor.ToString());
2014-01-04 17:00:08 +04:00
}
if (tokens[0].Equals("#define") && tokens[1].Equals("CEDAR_VERSION_BUILD"))
2014-01-04 17:00:08 +04:00
{
newLine = line.Replace(tokens[2], versionBuild.ToString());
2014-01-04 17:00:08 +04:00
}
if (tokens[0].Equals("#define") && tokens[1].Equals("BUILDER_NAME"))
{
newLine = line.Replace(tokens[2], "\"" + userName + "\"");
}
if (tokens[0].Equals("#define") && tokens[1].Equals("BUILD_PLACE"))
{
newLine = line.Replace(tokens[2], "\"" + pcName + "\"");
}
if (tokens[0].Equals("#define") && tokens[1].Equals("BUILD_DATE_Y"))
{
newLine = line.Replace(tokens[2], date.Year.ToString());
}
if (tokens[0].Equals("#define") && tokens[1].Equals("BUILD_DATE_M"))
{
newLine = line.Replace(tokens[2], date.Month.ToString());
}
if (tokens[0].Equals("#define") && tokens[1].Equals("BUILD_DATE_D"))
{
newLine = line.Replace(tokens[2], date.Day.ToString());
}
if (tokens[0].Equals("#define") && tokens[1].Equals("BUILD_DATE_HO"))
{
newLine = line.Replace(tokens[2], date.Hour.ToString());
}
if (tokens[0].Equals("#define") && tokens[1].Equals("BUILD_DATE_MI"))
{
newLine = line.Replace(tokens[2], date.Minute.ToString());
}
if (tokens[0].Equals("#define") && tokens[1].Equals("BUILD_DATE_SE"))
{
newLine = line.Replace(tokens[2], date.Second.ToString());
}
}
if (tokens.Length >= 3)
{
if (tokens[0].Equals("#define") && tokens[1].Equals("SUPPORTED_WINDOWS_LIST"))
{
newLine = "#define\tSUPPORTED_WINDOWS_LIST\t\t\"" + OSList.Windows.OSSimpleList + "\"";
}
}
}
}
if (newLine == null || newLine == line)
{
w.WriteLine(line);
}
else
{
w.WriteLine(newLine);
somethingChanged = true;
}
}
if (somethingChanged)
{
byte[] retData = Str.ConvertEncoding(Str.Utf8Encoding.GetBytes(w.ToString()), enc, bomSize != 0);
File.WriteAllBytes(file, retData);
Con.WriteLine("Modified: '{0}'.", file);
}
}
}
}
// Get the DebugSnapshot directory name
public static string GetDebugSnapstotDirName()
{
return Path.Combine(Paths.DebugSnapshotBaseDir, Str.DateTimeToStrShort(BuildSoftwareList.ListCreatedDateTime));
}
// Copy DebugSnapshot
public static void CopyDebugSnapshot()
{
string snapDir = GetDebugSnapstotDirName();
CopyDebugSnapshot(snapDir);
}
public static void CopyDebugSnapshot(string snapDir, params string[] exclude_exts)
{
IO.CopyDir(Paths.BaseDirName, Path.Combine(snapDir, "Main"),
delegate(FileInfo fi)
{
string srcPath = fi.FullName;
string[] exts_default =
{
".ncb", ".aps", ".suo", ".old", ".scc", ".vssscc", ".vspscc", ".cache", ".psess", ".tmp", ".dmp",
};
List<string> exts = new List<string>();
foreach (string ext in exts_default)
{
exts.Add(ext);
}
foreach (string ext in exclude_exts)
{
exts.Add(ext);
}
if (Str.InStr(srcPath, @"\.svn\", false))
{
return false;
}
if (Str.InStr(srcPath.Substring(3), @"\tmp\", false))
{
return false;
}
if (Str.InStr(srcPath, @"_log\", false))
{
return false;
}
if (Str.InStr(srcPath, @"\backup.vpn_", false))
{
return false;
}
foreach (string ext in exts)
{
if (srcPath.EndsWith(ext, StringComparison.InvariantCultureIgnoreCase))
{
return false;
}
}
if (Str.InStr(srcPath, @"\hamcore\", false))
{
return true;
}
if (Str.InStr(srcPath, @"\hamcore_", false))
{
return true;
}
return true;
},
false, true, false, false);
}
// Execute building in Visual Studio
public static void BuildMain()
{
Mutex x = new Mutex(false, "VpnBuilderWin32_BuildMain");
x.WaitOne();
try
{
// Generate the contents of the batch file
string batFileName = Path.Combine(Paths.TmpDirName, "vc_build.cmd");
StreamWriter bat = new StreamWriter(batFileName, false, Str.ShiftJisEncoding);
bat.WriteLine("call \"{0}\"", Paths.VisualStudioVCBatchFileName);
bat.WriteLine("echo on");
2018-06-17 11:02:58 +03:00
bat.WriteLine("\"{0}\" /toolsversion:3.5 /target:Clean /property:Configuration=Release /property:Platform=Win32 \"{1}\"",
2014-01-04 17:00:08 +04:00
Paths.MSBuildFileName, Paths.VPN4SolutionFileName);
bat.WriteLine("IF ERRORLEVEL 1 GOTO LABEL_ERROR");
2018-06-17 11:02:58 +03:00
bat.WriteLine("\"{0}\" /toolsversion:3.5 /target:Clean /property:Configuration=Release /property:Platform=x64 \"{1}\"",
2014-01-04 17:00:08 +04:00
Paths.MSBuildFileName, Paths.VPN4SolutionFileName);
bat.WriteLine("IF ERRORLEVEL 1 GOTO LABEL_ERROR");
2018-06-17 11:02:58 +03:00
bat.WriteLine("\"{0}\" /toolsversion:3.5 /target:Rebuild /property:Configuration=Release /property:Platform=Win32 \"{1}\"",
2014-01-04 17:00:08 +04:00
Paths.MSBuildFileName, Paths.VPN4SolutionFileName);
bat.WriteLine("IF ERRORLEVEL 1 GOTO LABEL_ERROR");
2018-06-17 11:02:58 +03:00
bat.WriteLine("\"{0}\" /toolsversion:3.5 /target:Rebuild /property:Configuration=Release /property:Platform=x64 \"{1}\"",
2014-01-04 17:00:08 +04:00
Paths.MSBuildFileName, Paths.VPN4SolutionFileName);
bat.WriteLine("IF ERRORLEVEL 1 GOTO LABEL_ERROR");
bat.WriteLine(":LABEL_ERROR");
bat.WriteLine("EXIT %ERRORLEVEL%");
bat.Close();
ExecCommand(Paths.CmdFileName, string.Format("/C \"{0}\"", batFileName));
BuildReplaceHeader();
}
finally
{
x.ReleaseMutex();
}
}
// Generate the Replace.h
public static void BuildReplaceHeader()
{
List<string> o = new List<string>();
int maxLen = 0;
// Read the map file
string[] lines = File.ReadAllLines(Path.Combine(Paths.BaseDirName, @"DebugFiles\map\Win32_Release\vpnserver.map"));
char[] sps = { ' ', '\t', };
foreach (string line in lines)
{
string[] tokens = line.Trim().Split(sps, StringSplitOptions.RemoveEmptyEntries);
if (tokens.Length == 5)
{
if (tokens[0].StartsWith("0001:", StringComparison.InvariantCultureIgnoreCase))
{
if (tokens[0].Length == 13)
{
if (tokens[2].Length == 8)
{
if (tokens[3].Equals("f", StringComparison.InvariantCultureIgnoreCase))
{
if (tokens[4].StartsWith("Mayaqua:", StringComparison.InvariantCultureIgnoreCase) ||
tokens[4].StartsWith("Cedar:", StringComparison.InvariantCultureIgnoreCase))
{
string name = tokens[1];
if (name.Length >= 2)
{
if (Str.InStr(name, "mktime") == false &&
Str.InStr(name, "gmtime") == false &&
Str.InStr(name, "stdin") == false &&
Str.InStr(name, "stdout") == false &&
Str.InStr(name, "@") == false &&
Str.InStr(name, "localtime") == false)
{
string tmp = tokens[4].Split(':')[1];
if (tmp[0] >= 'A' && tmp[0] <= 'Z' &&
Str.InStr(tmp, "_") == false)
{
o.Add(name.Substring(1));
maxLen = Math.Max(maxLen, name.Length);
}
}
}
}
}
}
}
}
}
}
o.Sort();
// Generate the Replace.h
string filename = Path.Combine(Paths.BaseDirName, @"DebugFiles\Replace.h");
StreamWriter w = new StreamWriter(filename);
w.WriteLine("// PacketiX VPN Function Name Replacement Header File");
w.WriteLine("//");
w.WriteLine("// Copyright (c) SoftEther Corporation.");
w.WriteLine("// All Rights Reserved.");
w.WriteLine("//");
w.WriteLine("// SoftEther Confidential");
w.WriteLine("//");
w.WriteLine();
foreach (string name in o)
{
if (Str.StrCmpi(name, "VLanGetPacketAdapter") == false)
{
string tmp = Str.ByteToHex(Secure.HashMD5(Str.Utf8Encoding.GetBytes("xx" + name)), "");
string tmp2 = "VPN_" + tmp.Substring(0, 12).ToUpper();
w.WriteLine("#define {0,-" + maxLen.ToString() + "} {1}",
name, tmp2);
}
}
w.WriteLine();
w.Flush();
w.Close();
}
// Command execution
public static void ExecCommand(string exe, string arg)
{
ExecCommand(exe, arg, false);
}
public static void ExecCommand(string exe, string arg, bool shell_execute)
{
Process p = new Process();
p.StartInfo.FileName = exe;
p.StartInfo.Arguments = arg;
p.StartInfo.UseShellExecute = shell_execute;
if (shell_execute)
{
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
}
Con.WriteLine("Executing '{0} {1}'...", exe, arg);
p.Start();
p.WaitForExit();
int ret = p.ExitCode;
if (ret != 0)
{
throw new ApplicationException(string.Format("Child process '{0}' returned error code {1}.", exe, ret));
}
Kernel.SleepThread(50);
}
// Get whether the specified fileis a target of signature
public static bool IsFileSignable(string fileName)
{
if (fileName.IndexOf(@".svn", StringComparison.InvariantCultureIgnoreCase) != -1 ||
fileName.StartsWith(".svn", StringComparison.InvariantCultureIgnoreCase))
{
return false;
}
if (fileName.EndsWith("vpn16.exe", StringComparison.InvariantCultureIgnoreCase))
{
return false;
}
if (fileName.EndsWith("BuildUtil.exe", StringComparison.InvariantCultureIgnoreCase))
{
return false;
}
if (fileName.EndsWith("BuildUtilTmp.exe", StringComparison.InvariantCultureIgnoreCase))
{
return false;
}
if (fileName.EndsWith("CoreUtil.dll", StringComparison.InvariantCultureIgnoreCase))
{
return false;
}
if (fileName.EndsWith("npptools.dll", StringComparison.InvariantCultureIgnoreCase))
{
return false;
}
if (fileName.EndsWith("winpcap_installer.exe", StringComparison.InvariantCultureIgnoreCase))
{
return false;
}
if (fileName.EndsWith("winpcap_installer_win9x.exe", StringComparison.InvariantCultureIgnoreCase))
{
return false;
}
if (fileName.EndsWith("VpnGatePlugin_x64.dll", StringComparison.InvariantCultureIgnoreCase))
{
return false;
}
if (fileName.EndsWith("VpnGatePlugin_x86.dll", StringComparison.InvariantCultureIgnoreCase))
{
return false;
}
2015-05-31 13:02:35 +03:00
if (Str.InStr(fileName, "DriverPackages", false))
{
return false;
}
2014-01-04 17:00:08 +04:00
if (Str.InStr(fileName, "_nosign", false))
{
return false;
}
if (fileName.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase) ||
fileName.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) ||
fileName.EndsWith(".ocx", StringComparison.InvariantCultureIgnoreCase) ||
fileName.EndsWith(".sys", StringComparison.InvariantCultureIgnoreCase))
{
return true;
}
return false;
}
// Create and sign the Inf file and the catalog file for SeLow
public static void SignSeLowInfFiles(string cpu)
{
int versionMajor, versionMinor, versionBuild;
2014-01-04 17:00:08 +04:00
string name;
DateTime date;
ReadBuildInfoFromTextFile(out versionMajor, out versionMinor, out versionBuild, out name, out date);
2014-01-04 17:00:08 +04:00
string hamcore = Path.Combine(Paths.BinDirName, "hamcore");
string sys_src = Path.Combine(hamcore, "SeLow_" + cpu + ".sys");
string inf_src = Path.Combine(hamcore, "SeLow_" + cpu + ".inf");
Con.WriteLine("Generating INF Files for SeLow...");
string dst_dir = Path.Combine(hamcore, @"inf\selow_" + cpu);
if (ExeSignChecker.CheckFileDigitalSignature(sys_src) == false ||
ExeSignChecker.IsKernelModeSignedFile(sys_src) == false)
{
throw new ApplicationException(sys_src + " is not signed.");
}
generateINFFilesForPlatform(inf_src, sys_src, null, dst_dir, versionMajor, versionMinor, versionBuild, date, true);
2014-01-04 17:00:08 +04:00
Con.WriteLine("Generating INF Files for SeLow Ok.");
}
// Create Inf file for Windows 8
public static void GenerateINFFilesForWindows8(string cpu)
{
int versionMajor, versionMinor, versionBuild;
2014-01-04 17:00:08 +04:00
string name;
DateTime date;
ReadBuildInfoFromTextFile(out versionMajor, out versionMinor, out versionBuild, out name, out date);
2014-01-04 17:00:08 +04:00
string hamcore = Path.Combine(Paths.BinDirName, "hamcore");
string inf_src_x86 = Path.Combine(hamcore, "vpn_driver.inf");
string inf_src_x64 = Path.Combine(hamcore, "vpn_driver_x64.inf");
string sys_src_x86 = Path.Combine(hamcore, "vpn_driver.sys");
string sys_src_x64 = Path.Combine(hamcore, "vpn_driver_x64.sys");
string sys6_src_x86 = Path.Combine(hamcore, "vpn_driver6.sys");
string sys6_src_x64 = Path.Combine(hamcore, "vpn_driver6_x64.sys");
Con.WriteLine("Generating INF Files for Windows 8...");
string dst_x86 = Path.Combine(hamcore, @"inf\x86");
string dst_x64 = Path.Combine(hamcore, @"inf\x64");
if (Str.StrCmpi(cpu, "x64"))
{
if (ExeSignChecker.CheckFileDigitalSignature(sys_src_x64) == false || ExeSignChecker.IsKernelModeSignedFile(sys_src_x64) == false)
{
throw new ApplicationException(sys_src_x64 + " is not signed.");
}
generateINFFilesForPlatform(inf_src_x64, sys_src_x64, sys6_src_x64, dst_x64, versionMajor, versionMinor, versionBuild, date, false);
2014-01-04 17:00:08 +04:00
}
else
{
if (ExeSignChecker.CheckFileDigitalSignature(sys_src_x86) == false || ExeSignChecker.IsKernelModeSignedFile(sys_src_x86) == false)
{
throw new ApplicationException(sys_src_x86 + " is not signed.");
}
generateINFFilesForPlatform(inf_src_x86, sys_src_x86, sys6_src_x86, dst_x86, versionMajor, versionMinor, versionBuild, date, false);
2014-01-04 17:00:08 +04:00
}
Con.WriteLine("Generating INF Files for Windows 8 Ok.");
}
static void generateINFFilesForPlatform(string inf, string sys, string sys6, string dstDir, int versionMajor, int versionMinor, int versionBuild, DateTime date, bool selow)
2014-01-04 17:00:08 +04:00
{
string cdfFileName = Path.Combine(dstDir, "inf.cdf");
2015-05-31 13:02:35 +03:00
string cdfFileName2 = Path.Combine(dstDir, "inf2.cdf");
2014-01-04 17:00:08 +04:00
string catFileName = Path.Combine(dstDir, "inf.cat");
2015-05-31 13:02:35 +03:00
string catFileName2 = Path.Combine(dstDir, "inf2.cat");
2014-01-04 17:00:08 +04:00
StringWriter sw = new StringWriter();
2015-05-31 13:02:35 +03:00
StringWriter sw2 = new StringWriter();
2014-01-04 17:00:08 +04:00
string txt = File.ReadAllText(inf, Str.ShiftJisEncoding);
IO.DeleteFilesAndSubDirsInDir(dstDir);
IO.MakeDirIfNotExists(dstDir);
2015-05-31 13:02:35 +03:00
string utility_dirname = Path.Combine(Paths.BaseDirName, @"BuildFiles\Utility");
string makecat1 = Path.Combine(dstDir, "makecat.exe");
string makecat2 = Path.Combine(dstDir, "makecat.exe.manifest");
string makecat3 = Path.Combine(dstDir, "Microsoft.Windows.Build.Signing.wintrust.dll.manifest");
string makecat4 = Path.Combine(dstDir, "wintrust.dll");
File.Copy(Path.Combine(utility_dirname, "makecat.exe"), makecat1, true);
File.Copy(Path.Combine(utility_dirname, "makecat.exe.manifest"), makecat2, true);
File.Copy(Path.Combine(utility_dirname, "Microsoft.Windows.Build.Signing.wintrust.dll.manifest"), makecat3, true);
File.Copy(Path.Combine(utility_dirname, "wintrust.dll"), makecat4, true);
2014-01-04 17:00:08 +04:00
string dst_sys_name = Path.Combine(dstDir, Path.GetFileName(sys));
File.Copy(sys, dst_sys_name, true);
string dst_sys6_name = null;
if (sys6 != null)
{
dst_sys6_name = Path.Combine(dstDir, Path.GetFileName(sys6));
File.Copy(sys6, dst_sys6_name, true);
}
sw.WriteLine("[CatalogHeader]");
2015-05-31 13:02:35 +03:00
sw2.WriteLine("[CatalogHeader]");
2014-01-04 17:00:08 +04:00
sw.WriteLine("name=inf.cat");
2015-05-31 13:02:35 +03:00
sw2.WriteLine("name=inf2.cat");
sw2.WriteLine("CatalogVersion=2");
sw2.WriteLine("HashAlgorithms=SHA256");
sw2.WriteLine("PageHashes=true");
2014-01-04 17:00:08 +04:00
sw.WriteLine();
2015-05-31 13:02:35 +03:00
sw2.WriteLine();
2014-01-04 17:00:08 +04:00
sw.WriteLine("[CatalogFiles]");
2015-05-31 13:02:35 +03:00
sw2.WriteLine("[CatalogFiles]");
2014-01-04 17:00:08 +04:00
sw.WriteLine("<hash>{0}={0}", Path.GetFileName(dst_sys_name));
2015-05-31 13:02:35 +03:00
sw2.WriteLine("<hash>{0}={0}", Path.GetFileName(dst_sys_name));
2014-01-04 17:00:08 +04:00
if (sys6 != null)
{
sw.WriteLine("<hash>{0}={0}", Path.GetFileName(dst_sys6_name));
2015-05-31 13:02:35 +03:00
sw2.WriteLine("<hash>{0}={0}", Path.GetFileName(dst_sys6_name));
2014-01-04 17:00:08 +04:00
}
int i;
for (i = 1; i < 128; i++)
{
string name = "VPN";
if (i >= 2)
{
name += i.ToString();
}
if (selow)
{
name = "selow";
}
//string mac = "00AC0011" + i.ToString("X2") + "01";
string mac = "000001000001";
string sys_name = "Neo_" + name + ".sys";
string body = txt;
body = Str.ReplaceStr(body, "$TAG_SYS_NAME$", sys_name);
body = Str.ReplaceStr(body, "$TAG_INSTANCE_NAME$", name);
body = Str.ReplaceStr(body, "$TAG_MAC_ADDRESS$", mac);
body = Str.ReplaceStr(body, "$YEAR$", date.Year.ToString("D4"));
body = Str.ReplaceStr(body, "$MONTH$", date.Month.ToString("D2"));
body = Str.ReplaceStr(body, "$DAY$", date.Day.ToString("D2"));
body = Str.ReplaceStr(body, "$VER_MAJOR$", versionMajor.ToString());
body = Str.ReplaceStr(body, "$VER_MINOR$", versionMinor.ToString());
body = Str.ReplaceStr(body, "$VER_BUILD$", versionBuild.ToString());
2014-01-04 17:00:08 +04:00
body = Str.ReplaceStr(body, "[Manufacturer]", "CatalogFile.NT\t\t\t\t= inf_" + name + ".cat\r\n\r\n[Manufacturer]");
string dst_inf_name = Path.Combine(dstDir, "INF_" + name + ".inf");
if (selow)
{
dst_inf_name = Path.Combine(dstDir, Path.GetFileName(inf));
}
if (selow)
{
body += "\r\n; Auto Generated " + Str.DateTimeToStrShortWithMilliSecs(DateTime.Now) + "\r\n\r\n";
}
File.WriteAllText(dst_inf_name, body, Str.ShiftJisEncoding);
sw.WriteLine("<hash>{0}={0}", Path.GetFileName(dst_inf_name));
2015-05-31 13:02:35 +03:00
sw2.WriteLine("<hash>{0}={0}", Path.GetFileName(dst_inf_name));
2014-01-04 17:00:08 +04:00
if (selow)
{
break;
}
}
sw.WriteLine();
2015-05-31 13:02:35 +03:00
sw2.WriteLine();
2014-01-04 17:00:08 +04:00
File.WriteAllText(cdfFileName, sw.ToString());
2015-05-31 13:02:35 +03:00
File.WriteAllText(cdfFileName2, sw2.ToString());
2014-01-04 17:00:08 +04:00
// generate catalog file
Directory.SetCurrentDirectory(dstDir);
ExecCommand(Paths.MakeCatFilename, string.Format("\"{0}\"", cdfFileName));
2015-05-31 13:02:35 +03:00
ExecCommand(makecat1, string.Format("\"{0}\"", cdfFileName2));
2014-01-04 17:00:08 +04:00
// sign catalog file
CodeSign.SignFile(catFileName, catFileName, "Catalog File", false);
2015-05-31 13:02:35 +03:00
CodeSign.SignFile(catFileName2, catFileName2, "Catalog File", false);
2014-01-04 17:00:08 +04:00
// delete cdf file
File.Delete(cdfFileName);
2015-05-31 13:02:35 +03:00
File.Delete(cdfFileName2);
2014-01-04 17:00:08 +04:00
// delete sys file
File.Delete(dst_sys_name);
2015-05-31 13:02:35 +03:00
File.Delete(makecat1);
File.Delete(makecat2);
File.Delete(makecat3);
File.Delete(makecat4);
2014-01-04 17:00:08 +04:00
if (sys6 != null)
{
File.Delete(dst_sys6_name);
}
}
static string process_inf_file(string src_inf_txt, int versionMajor, int versionMinor, int versionBuild, DateTime date, string sys_name, string name, string catfile, bool replace_mac_address)
2015-05-31 13:02:35 +03:00
{
string body = src_inf_txt;
if (Str.IsEmptyStr(sys_name) == false)
{
body = Str.ReplaceStr(body, "$TAG_SYS_NAME$", sys_name);
}
if (Str.IsEmptyStr(name) == false)
{
body = Str.ReplaceStr(body, "$TAG_INSTANCE_NAME$", name);
}
if (replace_mac_address)
{
body = Str.ReplaceStr(body, "$TAG_MAC_ADDRESS$", "000001000001");
}
body = Str.ReplaceStr(body, "$YEAR$", date.Year.ToString("D4"));
body = Str.ReplaceStr(body, "$MONTH$", date.Month.ToString("D2"));
body = Str.ReplaceStr(body, "$DAY$", date.Day.ToString("D2"));
body = Str.ReplaceStr(body, "$VER_MAJOR$", versionMajor.ToString());
body = Str.ReplaceStr(body, "$VER_MINOR$", versionMinor.ToString());
body = Str.ReplaceStr(body, "$VER_BUILD$", versionBuild.ToString());
2015-05-31 13:02:35 +03:00
if (Str.IsEmptyStr(catfile) == false)
{
body = Str.ReplaceStr(body, "$CATALOG_FILENAME$", catfile);
body = Str.ReplaceStr(body, ";CatalogFile.NT", "CatalogFile.NT");
}
body += "\r\n; Auto Generated " + Str.DateTimeToStrShortWithMilliSecs(DateTime.Now) + "\r\n\r\n";
return body;
}
static void make_cat_file(string dir, string[] filename_list, string catname, bool win8, bool no_sign)
{
string utility_dirname = Path.Combine(Paths.BaseDirName, @"BuildFiles\Utility");
string makecat1 = Path.Combine(dir, "makecat.exe");
string makecat2 = Path.Combine(dir, "makecat.exe.manifest");
string makecat3 = Path.Combine(dir, "Microsoft.Windows.Build.Signing.wintrust.dll.manifest");
string makecat4 = Path.Combine(dir, "wintrust.dll");
File.Copy(Path.Combine(utility_dirname, "makecat.exe"), makecat1, true);
File.Copy(Path.Combine(utility_dirname, "makecat.exe.manifest"), makecat2, true);
File.Copy(Path.Combine(utility_dirname, "Microsoft.Windows.Build.Signing.wintrust.dll.manifest"), makecat3, true);
File.Copy(Path.Combine(utility_dirname, "wintrust.dll"), makecat4, true);
StringWriter sw2 = new StringWriter();
sw2.WriteLine("[CatalogHeader]");
sw2.WriteLine("name=" + catname);
if (win8)
{
sw2.WriteLine("CatalogVersion=2");
sw2.WriteLine("HashAlgorithms=SHA256");
sw2.WriteLine("PageHashes=true");
}
sw2.WriteLine();
sw2.WriteLine("[CatalogFiles]");
foreach (string filename in filename_list)
{
sw2.WriteLine("<hash>{0}={0}", filename);
}
sw2.WriteLine();
string cdf_file_name = catname + ".cdf";
Directory.SetCurrentDirectory(dir);
File.WriteAllText(cdf_file_name, sw2.ToString());
ExecCommand(makecat1, string.Format("\"{0}\"", cdf_file_name));
if (no_sign == false)
{
CodeSign.SignFile(catname, catname, "Catalog File", false);
}
File.Delete(cdf_file_name);
File.Delete(makecat1);
File.Delete(makecat2);
File.Delete(makecat3);
File.Delete(makecat4);
}
public static void MakeDriverPackage()
{
int versionMajor, versionMinor, versionBuild;
2015-05-31 13:02:35 +03:00
string buildname;
DateTime date;
int i;
ReadBuildInfoFromTextFile(out versionMajor, out versionMinor, out versionBuild, out buildname, out date);
2015-05-31 13:02:35 +03:00
date = date.AddDays(-1);
string dst_dir = Path.Combine(Paths.BaseDirName, @"tmp\MakeDriverPackage");
string src_dir = Path.Combine(Paths.BaseDirName, @"BuiltDriverPackages");
IO.DeleteFilesAndSubDirsInDir(dst_dir);
IO.MakeDirIfNotExists(dst_dir);
// Neo9x x86
IO.MakeDir(Path.Combine(dst_dir, @"Neo9x\x86"));
IO.WriteAllTextWithEncoding(Path.Combine(dst_dir, @"Neo9x\x86\Neo9x_x86.inf"),
process_inf_file(IO.ReadAllTextWithAutoGetEncoding(Path.Combine(src_dir, @"Neo9x\x86\Neo9x_x86.inf")), versionMajor, versionMinor, versionBuild, date, null, null, null, false), Str.ShiftJisEncoding, false);
2015-05-31 13:02:35 +03:00
IO.FileCopy(Path.Combine(src_dir, @"Neo9x\x86\Neo9x_x86.sys"), Path.Combine(dst_dir, @"Neo9x\x86\Neo9x_x86.sys"));
// Neo x86
IO.MakeDir(Path.Combine(dst_dir, @"Neo\x86"));
IO.WriteAllTextWithEncoding(Path.Combine(dst_dir, @"Neo\x86\Neo_x86.inf"),
process_inf_file(IO.ReadAllTextWithAutoGetEncoding(Path.Combine(src_dir, @"Neo\x86\Neo_x86.inf")), versionMajor, versionMinor, versionBuild, date, null, null, null, false), Str.ShiftJisEncoding, false);
2015-05-31 13:02:35 +03:00
IO.FileCopy(Path.Combine(src_dir, @"Neo\x86\Neo_x86.sys"), Path.Combine(dst_dir, @"Neo\x86\Neo_x86.sys"));
// Neo x64
IO.MakeDir(Path.Combine(dst_dir, @"Neo\x64"));
IO.WriteAllTextWithEncoding(Path.Combine(dst_dir, @"Neo\x64\Neo_x64.inf"),
process_inf_file(IO.ReadAllTextWithAutoGetEncoding(Path.Combine(src_dir, @"Neo\x64\Neo_x64.inf")), versionMajor, versionMinor, versionBuild, date, null, null, null, false), Str.ShiftJisEncoding, false);
2015-05-31 13:02:35 +03:00
IO.FileCopy(Path.Combine(src_dir, @"Neo\x64\Neo_x64.sys"), Path.Combine(dst_dir, @"Neo\x64\Neo_x64.sys"));
// Neo6 x86
IO.MakeDir(Path.Combine(dst_dir, @"Neo6\x86"));
IO.WriteAllTextWithEncoding(Path.Combine(dst_dir, @"Neo6\x86\Neo6_x86.inf"),
process_inf_file(IO.ReadAllTextWithAutoGetEncoding(Path.Combine(src_dir, @"Neo6\x86\Neo6_x86.inf")), versionMajor, versionMinor, versionBuild, date, null, null, null, false), Str.ShiftJisEncoding, false);
2015-05-31 13:02:35 +03:00
IO.FileCopy(Path.Combine(src_dir, @"Neo6\x86\Neo6_x86.sys"), Path.Combine(dst_dir, @"Neo6\x86\Neo6_x86.sys"));
// Neo6 x64
IO.MakeDir(Path.Combine(dst_dir, @"Neo6\x64"));
IO.WriteAllTextWithEncoding(Path.Combine(dst_dir, @"Neo6\x64\Neo6_x64.inf"),
process_inf_file(IO.ReadAllTextWithAutoGetEncoding(Path.Combine(src_dir, @"Neo6\x64\Neo6_x64.inf")), versionMajor, versionMinor, versionBuild, date, null, null, null, false), Str.ShiftJisEncoding, false);
2015-05-31 13:02:35 +03:00
IO.FileCopy(Path.Combine(src_dir, @"Neo6\x64\Neo6_x64.sys"), Path.Combine(dst_dir, @"Neo6\x64\Neo6_x64.sys"));
// Neo6 for Windows 8 x86
IO.MakeDir(Path.Combine(dst_dir, @"Neo6_Win8\x86"));
List<string> cat_src_filename = new List<string>();
cat_src_filename.Add("Neo6_x86.sys");
for (i = 1; i < 128; i++)
{
string name = "VPN";
if (i >= 2)
{
name += i.ToString();
}
string sys_name = "Neo_" + name + ".sys";
IO.WriteAllTextWithEncoding(Path.Combine(dst_dir, @"Neo6_Win8\x86\Neo6_x86_" + name + ".inf"),
process_inf_file(IO.ReadAllTextWithAutoGetEncoding(Path.Combine(src_dir, @"Neo6\x86\Neo6_x86.inf")), versionMajor, versionMinor, versionBuild, date, sys_name, name, string.Format("inf_{0}.cat", name), true), Str.ShiftJisEncoding, false);
2015-05-31 13:02:35 +03:00
cat_src_filename.Add("Neo6_x86_" + name + ".inf");
}
IO.FileCopy(Path.Combine(src_dir, @"Neo6\x86\Neo6_x86.sys"), Path.Combine(dst_dir, @"Neo6_Win8\x86\Neo6_x86.sys"));
make_cat_file(Path.Combine(dst_dir, @"Neo6_Win8\x86"), cat_src_filename.ToArray(), "inf.cat", false, false);
make_cat_file(Path.Combine(dst_dir, @"Neo6_Win8\x86"), cat_src_filename.ToArray(), "inf2.cat", true, false);
// Neo6 for Windows 8 x64
IO.MakeDir(Path.Combine(dst_dir, @"Neo6_Win8\x64"));
cat_src_filename = new List<string>();
cat_src_filename.Add("Neo6_x64.sys");
for (i = 1; i < 128; i++)
{
string name = "VPN";
if (i >= 2)
{
name += i.ToString();
}
string sys_name = "Neo_" + name + ".sys";
IO.WriteAllTextWithEncoding(Path.Combine(dst_dir, @"Neo6_Win8\x64\Neo6_x64_" + name + ".inf"),
process_inf_file(IO.ReadAllTextWithAutoGetEncoding(Path.Combine(src_dir, @"Neo6\x64\Neo6_x64.inf")), versionMajor, versionMinor, versionBuild, date, sys_name, name, string.Format("inf_{0}.cat", name), true), Str.ShiftJisEncoding, false);
2015-05-31 13:02:35 +03:00
cat_src_filename.Add("Neo6_x64_" + name + ".inf");
}
IO.FileCopy(Path.Combine(src_dir, @"Neo6\x64\Neo6_x64.sys"), Path.Combine(dst_dir, @"Neo6_Win8\x64\Neo6_x64.sys"));
make_cat_file(Path.Combine(dst_dir, @"Neo6_Win8\x64"), cat_src_filename.ToArray(), "inf.cat", false, false);
make_cat_file(Path.Combine(dst_dir, @"Neo6_Win8\x64"), cat_src_filename.ToArray(), "inf2.cat", true, false);
// Neo6 for Windows 10 x86
IO.MakeDir(Path.Combine(dst_dir, @"Neo6_Win10\x86"));
for (i = 1; i < 128; i++)
{
string name = "VPN";
if (i >= 2)
{
name += i.ToString();
}
cat_src_filename = new List<string>();
cat_src_filename.Add("Neo6_x86_" + name + ".sys");
string sys_name = "Neo6_x86_" + name + ".sys";
IO.WriteAllTextWithEncoding(Path.Combine(dst_dir, @"Neo6_Win10\x86\Neo6_x86_" + name + ".inf"),
process_inf_file(IO.ReadAllTextWithAutoGetEncoding(Path.Combine(src_dir, @"Neo6\x86\Neo6_x86.inf")), versionMajor, versionMinor, versionBuild, date, sys_name, name, string.Format("Neo6_x86_{0}.cat", name), true), Str.ShiftJisEncoding, false);
2015-05-31 13:02:35 +03:00
cat_src_filename.Add("Neo6_x86_" + name + ".inf");
2015-09-15 08:22:53 +03:00
IO.FileCopy(Path.Combine(src_dir, @"Neo6\x86\Neo6_x86_win10.sys"), Path.Combine(dst_dir, @"Neo6_Win10\x86\Neo6_x86_" + name + ".sys"));
2015-05-31 13:02:35 +03:00
make_cat_file(Path.Combine(dst_dir, @"Neo6_Win10\x86"), cat_src_filename.ToArray(), "Neo6_x86_" + name + ".cat", true, true);
}
// Neo6 for Windows 10 x64
IO.MakeDir(Path.Combine(dst_dir, @"Neo6_Win10\x64"));
for (i = 1; i < 128; i++)
{
string name = "VPN";
if (i >= 2)
{
name += i.ToString();
}
cat_src_filename = new List<string>();
cat_src_filename.Add("Neo6_x64_" + name + ".sys");
string sys_name = "Neo6_x64_" + name + ".sys";
IO.WriteAllTextWithEncoding(Path.Combine(dst_dir, @"Neo6_Win10\x64\Neo6_x64_" + name + ".inf"),
process_inf_file(IO.ReadAllTextWithAutoGetEncoding(Path.Combine(src_dir, @"Neo6\x64\Neo6_x64.inf")), versionMajor, versionMinor, versionBuild, date, sys_name, name, string.Format("Neo6_x64_{0}.cat", name), true), Str.ShiftJisEncoding, false);
2015-05-31 13:02:35 +03:00
cat_src_filename.Add("Neo6_x64_" + name + ".inf");
2015-09-15 08:22:53 +03:00
IO.FileCopy(Path.Combine(src_dir, @"Neo6\x64\Neo6_x64_win10.sys"), Path.Combine(dst_dir, @"Neo6_Win10\x64\Neo6_x64_" + name + ".sys"));
2015-05-31 13:02:35 +03:00
make_cat_file(Path.Combine(dst_dir, @"Neo6_Win10\x64"), cat_src_filename.ToArray(), "Neo6_x64_" + name + ".cat", true, true);
}
IO.CopyDir(Path.Combine(src_dir, "See"), Path.Combine(dst_dir, "See"), null, false, false);
// SeLow x86 for Windows 8.1
IO.MakeDir(Path.Combine(dst_dir, @"SeLow_Win8\x86"));
cat_src_filename = new List<string>();
cat_src_filename.Add("SeLow_x86.sys");
cat_src_filename.Add("SeLow_x86.inf");
IO.WriteAllTextWithEncoding(Path.Combine(dst_dir, @"SeLow_Win8\x86\SeLow_x86.inf"),
process_inf_file(IO.ReadAllTextWithAutoGetEncoding(Path.Combine(src_dir, @"SeLow\x86\SeLow_x86.inf")), versionMajor, versionMinor, versionBuild, date, null, null, "SeLow_Win8_x86.cat", false), Str.ShiftJisEncoding, false);
2015-05-31 13:02:35 +03:00
IO.FileCopy(Path.Combine(src_dir, @"SeLow\x86\SeLow_x86.sys"), Path.Combine(dst_dir, @"SeLow_Win8\x86\SeLow_x86.sys"));
make_cat_file(Path.Combine(dst_dir, @"SeLow_Win8\x86"), cat_src_filename.ToArray(), "inf.cat", false, false);
make_cat_file(Path.Combine(dst_dir, @"SeLow_Win8\x86"), cat_src_filename.ToArray(), "inf2.cat", true, false);
// SeLow x64 for Windows 8.1
IO.MakeDir(Path.Combine(dst_dir, @"SeLow_Win8\x64"));
cat_src_filename = new List<string>();
cat_src_filename.Add("SeLow_x64.sys");
cat_src_filename.Add("SeLow_x64.inf");
IO.WriteAllTextWithEncoding(Path.Combine(dst_dir, @"SeLow_Win8\x64\SeLow_x64.inf"),
process_inf_file(IO.ReadAllTextWithAutoGetEncoding(Path.Combine(src_dir, @"SeLow\x64\SeLow_x64.inf")), versionMajor, versionMinor, versionBuild, date, null, null, "SeLow_Win8_x64.cat", false), Str.ShiftJisEncoding, false);
2015-05-31 13:02:35 +03:00
IO.FileCopy(Path.Combine(src_dir, @"SeLow\x64\SeLow_x64.sys"), Path.Combine(dst_dir, @"SeLow_Win8\x64\SeLow_x64.sys"));
make_cat_file(Path.Combine(dst_dir, @"SeLow_Win8\x64"), cat_src_filename.ToArray(), "inf.cat", false, false);
make_cat_file(Path.Combine(dst_dir, @"SeLow_Win8\x64"), cat_src_filename.ToArray(), "inf2.cat", true, false);
// SeLow x86 for Windows 10
IO.MakeDir(Path.Combine(dst_dir, @"SeLow_Win10\x86"));
cat_src_filename = new List<string>();
cat_src_filename.Add("SeLow_x86.sys");
cat_src_filename.Add("SeLow_x86.inf");
IO.WriteAllTextWithEncoding(Path.Combine(dst_dir, @"SeLow_Win10\x86\SeLow_x86.inf"),
process_inf_file(IO.ReadAllTextWithAutoGetEncoding(Path.Combine(src_dir, @"SeLow\x86\SeLow_x86.inf")), versionMajor, versionMinor, versionBuild, date, null, null, "SeLow_Win10_x86.cat", false), Str.ShiftJisEncoding, false);
2015-09-15 08:22:53 +03:00
IO.FileCopy(Path.Combine(src_dir, @"SeLow\x86\SeLow_x86_win10.sys"), Path.Combine(dst_dir, @"SeLow_Win10\x86\SeLow_x86.sys"));
2015-05-31 13:02:35 +03:00
make_cat_file(Path.Combine(dst_dir, @"SeLow_Win10\x86"), cat_src_filename.ToArray(), "SeLow_Win10_x86.cat", true, false);
// SeLow x64 for Windows 10
IO.MakeDir(Path.Combine(dst_dir, @"SeLow_Win10\x64"));
cat_src_filename = new List<string>();
cat_src_filename.Add("SeLow_x64.sys");
cat_src_filename.Add("SeLow_x64.inf");
IO.WriteAllTextWithEncoding(Path.Combine(dst_dir, @"SeLow_Win10\x64\SeLow_x64.inf"),
process_inf_file(IO.ReadAllTextWithAutoGetEncoding(Path.Combine(src_dir, @"SeLow\x64\SeLow_x64.inf")), versionMajor, versionMinor, versionBuild, date, null, null, "SeLow_Win10_x64.cat", false), Str.ShiftJisEncoding, false);
2015-09-15 08:22:53 +03:00
IO.FileCopy(Path.Combine(src_dir, @"SeLow\x64\SeLow_x64_win10.sys"), Path.Combine(dst_dir, @"SeLow_Win10\x64\SeLow_x64.sys"));
2015-05-31 13:02:35 +03:00
make_cat_file(Path.Combine(dst_dir, @"SeLow_Win10\x64"), cat_src_filename.ToArray(), "SeLow_Win10_x64.cat", true, false);
// Wfp x86
IO.MakeDir(Path.Combine(dst_dir, @"Wfp\x86"));
cat_src_filename = new List<string>();
cat_src_filename.Add("pxwfp_x86.sys");
cat_src_filename.Add("pxwfp_x86.inf");
IO.WriteAllTextWithEncoding(Path.Combine(dst_dir, @"Wfp\x86\pxwfp_x86.inf"),
process_inf_file(IO.ReadAllTextWithAutoGetEncoding(Path.Combine(src_dir, @"Wfp\x86\pxwfp_x86.inf")), versionMajor, versionMinor, versionBuild, date, null, null, "pxwfp_x86.cat", false), Str.ShiftJisEncoding, false);
2015-05-31 13:02:35 +03:00
IO.FileCopy(Path.Combine(src_dir, @"Wfp\x86\pxwfp_x86.sys"), Path.Combine(dst_dir, @"Wfp\x86\pxwfp_x86.sys"));
make_cat_file(Path.Combine(dst_dir, @"Wfp\x86"), cat_src_filename.ToArray(), "inf.cat", false, false);
make_cat_file(Path.Combine(dst_dir, @"Wfp\x86"), cat_src_filename.ToArray(), "inf2.cat", true, false);
// Wfp x64
IO.MakeDir(Path.Combine(dst_dir, @"Wfp\x64"));
cat_src_filename = new List<string>();
cat_src_filename.Add("pxwfp_x64.sys");
cat_src_filename.Add("pxwfp_x64.inf");
IO.WriteAllTextWithEncoding(Path.Combine(dst_dir, @"Wfp\x64\pxwfp_x64.inf"),
process_inf_file(IO.ReadAllTextWithAutoGetEncoding(Path.Combine(src_dir, @"Wfp\x64\pxwfp_x64.inf")), versionMajor, versionMinor, versionBuild, date, null, null, "pxwfp_x64.cat", false), Str.ShiftJisEncoding, false);
2015-05-31 13:02:35 +03:00
IO.FileCopy(Path.Combine(src_dir, @"Wfp\x64\pxwfp_x64.sys"), Path.Combine(dst_dir, @"Wfp\x64\pxwfp_x64.sys"));
make_cat_file(Path.Combine(dst_dir, @"Wfp\x64"), cat_src_filename.ToArray(), "inf.cat", false, false);
make_cat_file(Path.Combine(dst_dir, @"Wfp\x64"), cat_src_filename.ToArray(), "inf2.cat", true, false);
// Wfp x86 for Windows 10
IO.MakeDir(Path.Combine(dst_dir, @"Wfp_Win10\x86"));
cat_src_filename = new List<string>();
cat_src_filename.Add("pxwfp_x86.sys");
cat_src_filename.Add("pxwfp_x86.inf");
IO.WriteAllTextWithEncoding(Path.Combine(dst_dir, @"Wfp_Win10\x86\pxwfp_x86.inf"),
process_inf_file(IO.ReadAllTextWithAutoGetEncoding(Path.Combine(src_dir, @"Wfp\x86\pxwfp_x86.inf")), versionMajor, versionMinor, versionBuild, date, null, null, "pxwfp_Win10_x86.cat", false), Str.ShiftJisEncoding, false);
2015-09-15 08:22:53 +03:00
IO.FileCopy(Path.Combine(src_dir, @"Wfp\x86\pxwfp_x86_win10.sys"), Path.Combine(dst_dir, @"Wfp_Win10\x86\pxwfp_x86.sys"));
2015-05-31 13:02:35 +03:00
make_cat_file(Path.Combine(dst_dir, @"Wfp_Win10\x86"), cat_src_filename.ToArray(), "pxwfp_Win10_x86.cat", true, false);
// Wfp x64 for Windows 10
IO.MakeDir(Path.Combine(dst_dir, @"Wfp_Win10\x64"));
cat_src_filename = new List<string>();
cat_src_filename.Add("pxwfp_x64.sys");
cat_src_filename.Add("pxwfp_x64.inf");
IO.WriteAllTextWithEncoding(Path.Combine(dst_dir, @"Wfp_Win10\x64\pxwfp_x64.inf"),
process_inf_file(IO.ReadAllTextWithAutoGetEncoding(Path.Combine(src_dir, @"Wfp\x64\pxwfp_x64.inf")), versionMajor, versionMinor, versionBuild, date, null, null, "pxwfp_Win10_x64.cat", false), Str.ShiftJisEncoding, false);
2015-09-15 08:22:53 +03:00
IO.FileCopy(Path.Combine(src_dir, @"Wfp\x64\pxwfp_x64_win10.sys"), Path.Combine(dst_dir, @"Wfp_Win10\x64\pxwfp_x64.sys"));
2015-05-31 13:02:35 +03:00
make_cat_file(Path.Combine(dst_dir, @"Wfp_Win10\x64"), cat_src_filename.ToArray(), "pxwfp_Win10_x64.cat", true, false);
string tmp_body = IO.ReadAllTextWithAutoGetEncoding(Path.Combine(src_dir, "make_whql_submission.cm_"));
tmp_body = Str.ReplaceStr(tmp_body, "test_tag", Str.DateTimeToStrShort(DateTime.Now) + "_Build_" + versionBuild.ToString());
2015-05-31 13:02:35 +03:00
IO.WriteAllTextWithEncoding(Path.Combine(dst_dir, "make_whql_submission.cmd"), tmp_body, Str.ShiftJisEncoding);
IO.FileCopy(Path.Combine(src_dir, "2_merge_whql_sign.cm_"), Path.Combine(dst_dir, "2_merge_whql_sign.cm_"));
tmp_body = IO.ReadAllTextWithAutoGetEncoding(Path.Combine(src_dir, "Memo.txt"));
tmp_body = Str.ReplaceStr(tmp_body, "tag_ver", versionMajor.ToString() + "." + versionMinor.ToString());
tmp_body = Str.ReplaceStr(tmp_body, "tag_build", versionBuild.ToString());
2015-05-31 13:02:35 +03:00
IO.WriteAllTextWithEncoding(Path.Combine(dst_dir, "Memo.txt"), tmp_body, Str.ShiftJisEncoding);
Kernel.Run(Path.Combine(Env.WindowsDir, "explorer.exe"), "\"" + dst_dir + "\"");
}
2014-01-04 17:00:08 +04:00
// Sign for all binary files (series mode)
public static void SignAllBinaryFilesSerial()
{
string[] files = Directory.GetFiles(Paths.BinDirName, "*", SearchOption.AllDirectories);
foreach (string file in files)
{
if (IsFileSignable(file))
{
bool isDriver = file.EndsWith(".sys", StringComparison.InvariantCultureIgnoreCase);
// Check whether this file is signed
bool isSigned = ExeSignChecker.CheckFileDigitalSignature(file);
if (isSigned && isDriver)
{
isSigned = ExeSignChecker.IsKernelModeSignedFile(file);
}
Con.WriteLine("The file '{0}': {1}.", file, isSigned ? "Already signed" : "Not yet signed");
if (isSigned == false)
{
Con.WriteLine("Signing...");
CodeSign.SignFile(file, file, "VPN Software", isDriver);
}
}
}
}
// Sign for all binary files (parallel mode)
public static void SignAllBinaryFiles()
{
string[] files = Directory.GetFiles(Paths.BinDirName, "*", SearchOption.AllDirectories);
List<string> filename_list = new List<string>();
foreach (string file in files)
{
if (IsFileSignable(file))
{
bool isDriver = file.EndsWith(".sys", StringComparison.InvariantCultureIgnoreCase);
// Check whether this file is signed
bool isSigned = ExeSignChecker.CheckFileDigitalSignature(file);
if (isSigned && isDriver)
{
isSigned = ExeSignChecker.IsKernelModeSignedFile(file);
}
Con.WriteLine("The file '{0}': {1}.", file, isSigned ? "Already signed" : "Not yet signed");
if (isSigned == false)
{
filename_list.Add(file);
}
}
}
Con.WriteLine("Start ProcessWorkQueue for Signing...\n");
ThreadObj.ProcessWorkQueue(sign_thread, 40, filename_list.ToArray());
Con.WriteLine("ProcessWorkQueue for Signing completed.\n");
}
// Binary file signature thread
static void sign_thread(object param)
{
string filename = (string)param;
bool isDriver = filename.EndsWith(".sys", StringComparison.InvariantCultureIgnoreCase);
Con.WriteLine("Signing...");
CodeSign.SignFile(filename, filename, "VPN Software", isDriver);
}
}
}