Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidXanatos committed Nov 16, 2019
1 parent e367398 commit f5f4afe
Show file tree
Hide file tree
Showing 56 changed files with 601 additions and 283 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [0.57] - 2019-11-16

### Added
- a few new tweaks
- aded windows 8 and newer address keywords
- added app context menu option to uninstall the client (remove service, autorun, event log)
- added -help command to show all available console ocmmands

### Changed
- on windows 8 and above the "Internet" address keyword is used for rules, instead of a manually assembled range
- rule lookup now properly handles the interface type parameters
- improved special address handling
- priv10 is now by default only using the windows event log when being installed as a service

### Fixed
- fixed issue with grouping combobox
- fixed issue with original rule backup



## [0.55] - 2019-11-15

### Added
Expand Down
27 changes: 0 additions & 27 deletions PrivateWin10/API/Network/NetFunc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,31 +437,4 @@ public static bool IsMultiCast(IPAddress addr)
return addressBytes[0] >= 224 && addressBytes[0] <= 239;
return false;
}

public static string GetNonLocalNet()
{
List<string> IpRanges = new List<string>();

// IPv4
IpRanges.Add("0.0.0.0-9.255.255.255");
// 10.0.0.0 - 10.255.255.255
IpRanges.Add("11.0.0.0-126.255.255.255");
// 127.0.0.0 - 127.255.255.255
IpRanges.Add("128.0.0.0-172.15.255.255");
// 172.16.0.0 - 172.31.255.255
IpRanges.Add("172.32.0.0-192.167.255.255");
// 192.168.0.0 - 192.168.255.255
IpRanges.Add("192.169.0.0-255.255.255.255");

// IPv6
// ::1
IpRanges.Add("::2-fbff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
// fc00:: - fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff - Unique local address
IpRanges.Add("fe00::-fe7f:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
// fe80:: - febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff - Link-local address
IpRanges.Add("fec0::-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");

return string.Join(",", IpRanges.ToArray());
}

}
194 changes: 147 additions & 47 deletions PrivateWin10/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public partial class App : Application
public static string[] args = null;
public static string exePath = "";
public static string mVersion = "0.0";
public static string mName = "Private WinTen";
//public static string mName = "Private WinTen";
public static string mName = "Private Win10";
public static string mAppName = "PrivateWin10";
#if DEBUG
public static string mSvcName = "priv10dbg";
Expand Down Expand Up @@ -56,8 +57,7 @@ enum StartModes
{
Normal = 0,
Service,
Engine,
Worker
Engine
}

public enum EventIDs : long
Expand Down Expand Up @@ -102,32 +102,43 @@ public static void Main(string[] args)
if (TestArg("-dbg_wait"))
MessageBox.Show("Waiting for debugger. (press ok when attached)");

Log = new AppLog(mAppName);
AppLog.ExceptionLogID = (long)EventIDs.Exception;
AppLog.ExceptionCategory = (short)EventFlags.DebugEvents;

StartModes startMode = StartModes.Normal;
StartModes startMode = StartModes.Normal; // Normal GUI Mode
if (TestArg("-svc"))
startMode = StartModes.Service;
else if (TestArg("-engine"))
startMode = StartModes.Engine;
else // Normal (GUI) mode

svc = new Service(mSvcName);

Log = new AppLog(mAppName);
AppLog.ExceptionLogID = (long)EventIDs.Exception;
AppLog.ExceptionCategory = (short)EventFlags.DebugEvents;

if (startMode == StartModes.Normal)
{
Log.EnableLogging();
Log.LoadLog();
Log.LoadLog();
}
// When running as worker we need the windows event log
else if (!Log.UsingEventLog())
Log.SetupEventLog(mAppName);

App.LogInfo("PrivateWin10 Process Started, Mode {0}.", startMode.ToString());

//Thread.CurrentThread.Name = "Main";
// execute service commands
if (ExecuteCommands())
return;

// load current version
exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(exePath);
mVersion = fvi.FileMajorPart + "." + fvi.FileMinorPart;
if (fvi.FileBuildPart != 0)
mVersion += (char)('a' + (fvi.FileBuildPart - 1));
appPath = Path.GetDirectoryName(exePath);

Translate.Load();

App.LogInfo("PrivateWin10 Process Started, Mode {0}.", startMode.ToString());

dataPath = appPath;
if (File.Exists(GetINIPath())) // if an ini exists in the app path, its considdered to be a portable run
{
Expand All @@ -153,50 +164,25 @@ public static void Main(string[] args)

mSession = Process.GetCurrentProcess().SessionId;

// setup custom assembly resolution for x86/x64 synamic compatybility
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += new ResolveEventHandler(currentDomain_AssemblyResolve);


Translate.Load();

svc = new Service(mSvcName);

if (!UwpFunc.IsWindows7OrLower)
{
Console.WriteLine("Initializing app manager...");
PkgMgr = new AppManager();
}

switch (startMode)
// is the process starting as a service/worker?
if (startMode != StartModes.Normal)
{
case StartModes.Engine:
{
engine = new Engine();
engine = new Engine();
if(startMode == StartModes.Service)
ServiceBase.Run(svc);
else
engine.Run();
return;
}
case StartModes.Service:
{
if (TestArg("-install"))
{
AppLog.Debug("Installing service...");
svc.Install(TestArg("-start"));
AppLog.Debug("... done");
}
else if (TestArg("-remove"))
{
AppLog.Debug("Removing service...");
svc.Uninstall();
AppLog.Debug("... done");
}
else
{
engine = new Engine();

ServiceBase.Run(svc);
}
return;
}
return;
}

client = new Priv10Client(mSvcName);
Expand Down Expand Up @@ -332,6 +318,121 @@ static private Assembly currentDomain_AssemblyResolve(object sender, ResolveEven
return MyAssembly;
}

static bool ExecuteCommands()
{
if (TestArg("-help") || TestArg("/?"))
{
string Message = "Available command line options\r\n";
string[] Help = {
"Available Console Commands:",
"========================================",
"",
"-state\t\t\tShow instalation state",
"-uninstall\t\tUninstall PrivateWinTen",
"",
"-svc_install\t\tInstall priv10 service (invokes -log_install)",
"-svc_remove\t\tRemove priv10 service",
"",
"-log_install\t\tInstall PrivateWin10 Custom Event Log",
"-log_remove\t\tRemove PrivateWin10 Custom Event Log",
"",
"-console\t\tShow console with debug output",
"-help\t\t\tShow this help message" };
if (!HasConsole)
MessageBox.Show(Message + string.Join("\r\n", Help));
else
{
Console.WriteLine(Message);
for (int j = 0; j < Help.Length; j++)
Console.WriteLine(" " + Help[j]);
}
return true;
}


bool bDone = false;

if (TestArg("-svc_install"))
{
AppLog.Debug("Installing Service...");
svc.Install(TestArg("-svc_start"));
bDone = true;
}

if (TestArg("-log_install") || TestArg("-svc_install")) // service needs the event log
{
AppLog.Debug("Setting up Event Log...");
Log.SetupEventLog(mAppName);
bDone = true;
}

if (TestArg("-uninstall"))
{
AppLog.Debug("Uninstalling PrivateWinTen");
bDone = true;
}

if (TestArg("-svc_remove") || (svc.IsInstalled() && TestArg("-uninstall")))
{
AppLog.Debug("Removing Service...");
svc.Uninstall();
bDone = true;
}

if (TestArg("-log_remove") || (Log.UsingEventLog() && TestArg("-uninstall")))
{
AppLog.Debug("Removing Event Log...");
Log.RemoveEventLog(mAppName);
bDone = true;
}

if (TestArg("-uninstall") && AdminFunc.IsSkipUac(mName))
{
AppLog.Debug("Removing UAC Bypass...");
AdminFunc.SkipUacEnable(mName, false);
bDone = true;
}

if (TestArg("-uninstall") && App.IsAutoStart())
{
AppLog.Debug("Removing Autostart...");
App.AutoStart(false);
bDone = true;
}

if (bDone)
AppLog.Debug("done");


if (TestArg("-state"))
{
Console.WriteLine();
Console.WriteLine("Instalation State:");
Console.WriteLine("========================="); // 25
Console.Write("Auto Start:\t");
Console.WriteLine(App.IsAutoStart());
Console.Write("UAC Bypass:\t");
Console.WriteLine(AdminFunc.IsSkipUac(mName));
Console.Write("Event Log:\t");
Console.WriteLine(Log.UsingEventLog());
Console.Write("Service:\t");
Console.WriteLine(svc.IsInstalled());
Console.WriteLine();
}

if (TestArg("-wait"))
{
Console.WriteLine();
for (int i = 10; i >= 0; i--)
{
Console.Write("\r{0}% ", i);
Thread.Sleep(1000);
}
}

return bDone;
}

static void TrayAction(object sender, TrayIcon.TrayEventArgs args)
{
switch (args.Action)
Expand Down Expand Up @@ -396,7 +497,6 @@ static public string GetArg(string name)
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Config


static public string GetConfig(string Section, string Key, string Default = "")
{
return IniReadValue(Section, Key, Default);
Expand Down
49 changes: 28 additions & 21 deletions PrivateWin10/Common/AppLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,8 @@ public LogEventArgs(LogEntry entry)
public AppLog(string LogName = null)
{
mInstance = this;

if (LogName == null)
return;

if (EventLog.Exists(LogName))
if (LogName != null && EventLog.Exists(LogName))
mLogName = LogName;
else if (AdminFunc.IsAdministrator())
{
try
{
if (!EventLog.SourceExists(LogName))
EventLog.CreateEventSource(LogName, LogName);
mLogName = LogName;
}
catch { }
}
}

public void Dispose()
Expand All @@ -111,20 +97,41 @@ public void EnableLogging()
{
mLogList = new List<LogEntry>();

if (mLogName == null)
return;
if (mLogName != null)
{
mEventWatcher = new EventLogWatcher(new EventLogQuery(mLogName, PathType.LogName));
mEventWatcher.EventRecordWritten += new EventHandler<EventRecordWrittenEventArgs>(OnLogEntry);
mEventWatcher.Enabled = true;
}
}

public bool SetupEventLog(string LogName)
{
if (mLogName != null)
return true;

mEventWatcher = new EventLogWatcher(new EventLogQuery(mLogName, PathType.LogName));
mEventWatcher.EventRecordWritten += new EventHandler<EventRecordWrittenEventArgs>(OnLogEntry);
mEventWatcher.Enabled = true;
try
{
if (!EventLog.SourceExists(LogName))
EventLog.CreateEventSource(LogName, LogName);
mLogName = LogName;
return true;
}
catch { }
return false;
}

public static void RemoveLog(string LogName)
public void RemoveEventLog(string LogName)
{
try { EventLog.Delete(LogName); } catch { }
try { EventLog.DeleteEventSource(LogName); } catch { }
}

public bool UsingEventLog()
{
return mLogName != null;
}

public static void Add(EventLogEntryType entryType, long eventID, short categoryID, string strMessage, Dictionary<string, string> Params = null/*, byte[] binData = null*/)
{
Console.WriteLine("Log: " + strMessage);
Expand Down
Loading

0 comments on commit f5f4afe

Please sign in to comment.