Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions FlashpointSecurePlayer/ActiveXControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,45 +26,46 @@ public class ActiveXControl {
[DllImport("KERNEL32.DLL", CallingConvention = CallingConvention.StdCall)]
private static extern IntPtr GetProcAddress(IntPtr moduleHandle, [MarshalAs(UnmanagedType.LPStr)] string procName);

private IntPtr ModuleHandle = IntPtr.Zero;
private IntPtr moduleHandle = IntPtr.Zero;

private readonly DllRegisterServerDelegate DllRegisterServer;
private readonly DllRegisterServerDelegate DllUnregisterServer;

public ActiveXControl(string libFileName) {
ModuleHandle = LoadLibrary(libFileName);
moduleHandle = LoadLibrary(libFileName);

if (ModuleHandle == IntPtr.Zero) {
throw new DllNotFoundException();
if (moduleHandle == IntPtr.Zero) {
throw new DllNotFoundException("The library " + libFileName + " could not be found.");
}

IntPtr dllRegisterServerProcAddress = IntPtr.Zero;
dllRegisterServerProcAddress = GetProcAddress(ModuleHandle, "DllRegisterServer");
dllRegisterServerProcAddress = GetProcAddress(moduleHandle, "DllRegisterServer");

if (dllRegisterServerProcAddress == IntPtr.Zero) {
throw new InvalidActiveXControlException();
throw new InvalidActiveXControlException("The library does not have a DllRegisterServer export.");
}

IntPtr dllUnregisterServerProcAddress = IntPtr.Zero;
dllUnregisterServerProcAddress = GetProcAddress(ModuleHandle, "DllUnregisterServer");
dllUnregisterServerProcAddress = GetProcAddress(moduleHandle, "DllUnregisterServer");

if (dllUnregisterServerProcAddress == IntPtr.Zero) {
throw new InvalidActiveXControlException();
throw new InvalidActiveXControlException("The library does not have a DllUnregisterServer export.");
}

DllRegisterServer = Marshal.GetDelegateForFunctionPointer(dllRegisterServerProcAddress, typeof(DllRegisterServerDelegate)) as DllRegisterServerDelegate;
DllUnregisterServer = Marshal.GetDelegateForFunctionPointer(dllUnregisterServerProcAddress, typeof(DllRegisterServerDelegate)) as DllRegisterServerDelegate;
}

~ActiveXControl() {
if (ModuleHandle != IntPtr.Zero) {
FreeLibrary(ModuleHandle);
ModuleHandle = IntPtr.Zero;
if (moduleHandle != IntPtr.Zero) {
FreeLibrary(moduleHandle);
moduleHandle = IntPtr.Zero;
}
}

private void RegisterServer(DllRegisterServerDelegate DllRegisterServer) {
if (DllRegisterServer() != 0) {
throw new Win32Exception();
throw new Win32Exception("Failed to register the DLL Server.");
}
}

Expand Down
16 changes: 7 additions & 9 deletions FlashpointSecurePlayer/CustomSecurityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,22 @@ public CustomSecurityManager(WebBrowser _WebBrowser) {
int err = webBrowserServiceProviderInterface.QueryService(ref InternetInterfaces.SID_SProfferService, ref InternetInterfaces.IID_IProfferService, out profferServiceInterfacePointer);

if (err != S_OK) {
throw new Win32Exception();
throw new Win32Exception("Failed to query the Web Browser Service.");
}

InternetInterfaces.IProfferService profferServiceInterface = Marshal.GetObjectForIUnknown(profferServiceInterfacePointer) as InternetInterfaces.IProfferService;

if (profferServiceInterface == null) {
throw new Win32Exception();

if (!(Marshal.GetObjectForIUnknown(profferServiceInterfacePointer) is InternetInterfaces.IProfferService profferServiceInterface)) {
throw new Win32Exception("Failed to get the Proffer Service Interface.");
}

err = profferServiceInterface.ProfferService(ref InternetInterfaces.IID_IInternetSecurityManager, this, out int cookie);

if (err != S_OK) {
throw new Win32Exception();
throw new Win32Exception("Failed to proffer the Internet Security Manager Service.");
}
} catch (SEHException) {
throw new Win32Exception();
throw new Win32Exception("An SEH Exception was encountered while creating the Custom Security Manager.");
} catch (ExternalException) {
throw new Win32Exception();
throw new Win32Exception("An External Exception was encountered while creating the Custom Security Manager.");
}
}

Expand Down
20 changes: 14 additions & 6 deletions FlashpointSecurePlayer/DownloadsBefore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace FlashpointSecurePlayer {
class DownloadsBefore : Modifications {
public DownloadsBefore(Form Form) : base(Form) { }
public DownloadsBefore(Form form) : base(form) { }

private void Activate() { }

Expand All @@ -28,13 +28,21 @@ public async Task ActivateAsync(string name, List<string> downloadsBeforeNames)
// we know the file downloaded all the way before the
// server/software starts
//DownloadBeforeElement downloadBeforeElement = null;
List<Task> downloadTasks = new List<Task>();
ProgressManager.CurrentGoal.Start(downloadsBeforeNames.Count);

for (int i = 0;i < downloadsBeforeNames.Count;i++) {
downloadTasks.Add(DownloadAsync(downloadsBeforeNames[i]));
}
try {
Task[] downloadTasks = new Task[downloadsBeforeNames.Count];

for (int i = 0;i < downloadsBeforeNames.Count;i++) {
downloadTasks[i] = DownloadAsync(downloadsBeforeNames[i]).ContinueWith(delegate (Task task) {
ProgressManager.CurrentGoal.Steps++;
}, TaskScheduler.FromCurrentSynchronizationContext());
}

await Task.WhenAll(downloadTasks.ToArray()).ConfigureAwait(false);
await Task.WhenAll(downloadTasks).ConfigureAwait(false);
} finally {
ProgressManager.CurrentGoal.Stop();
}
}
}
}
124 changes: 70 additions & 54 deletions FlashpointSecurePlayer/EnvironmentVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace FlashpointSecurePlayer {
class EnvironmentVariables : Modifications {
const string COMPATIBILITY_LAYER_NAME = "__COMPAT_LAYER";

public EnvironmentVariables(Form Form) : base(Form) { }
public EnvironmentVariables(Form form) : base(form) { }

public void Activate(string name, string server, string applicationMutexName) {
base.Activate(name);
Expand All @@ -28,48 +28,56 @@ public void Activate(string name, string server, string applicationMutexName) {
try {
compatibilityLayerValue = Environment.GetEnvironmentVariable(COMPATIBILITY_LAYER_NAME);
} catch (ArgumentException) {
throw new EnvironmentVariablesFailedException();
throw new EnvironmentVariablesFailedException("Failed to get the " + COMPATIBILITY_LAYER_NAME + " Environment Variable.");
} catch (SecurityException) {
throw new TaskRequiresElevationException();
throw new TaskRequiresElevationException("Getting the " + COMPATIBILITY_LAYER_NAME + " Environment Variable requires elevation.");
}

EnvironmentVariablesElement environmentVariablesElement = null;
ProgressManager.CurrentGoal.Start(modificationsElement.EnvironmentVariables.Count);

for (int i = 0;i < modificationsElement.EnvironmentVariables.Count;i++) {
environmentVariablesElement = modificationsElement.EnvironmentVariables.Get(i) as EnvironmentVariablesElement;

if (environmentVariablesElement == null) {
throw new EnvironmentVariablesFailedException();
}
try {
EnvironmentVariablesElement environmentVariablesElement = null;

value = environmentVariablesElement.Value;
for (int i = 0;i < modificationsElement.EnvironmentVariables.Count;i++) {
environmentVariablesElement = modificationsElement.EnvironmentVariables.Get(i) as EnvironmentVariablesElement;

try {
Environment.SetEnvironmentVariable(environmentVariablesElement.Name, RemoveVariablesFromLengthenedValue(value) as string);
} catch (ArgumentException) {
throw new EnvironmentVariablesFailedException();
} catch (SecurityException) {
throw new TaskRequiresElevationException();
}
if (environmentVariablesElement == null) {
throw new System.Configuration.ConfigurationErrorsException("The Environment Variables Element (" + i + ") is null.");
}

// if this is the compatibility layer variable
// and the value is not what we want to set it to
// and we're in server mode...
if (environmentVariablesElement.Name == COMPATIBILITY_LAYER_NAME && !String.IsNullOrEmpty(server)) {
values = new List<string>();
value = environmentVariablesElement.Value;

if (compatibilityLayerValue != null) {
compatibilityLayerValues = compatibilityLayerValue.ToUpper().Split(' ').ToList();
try {
Environment.SetEnvironmentVariable(environmentVariablesElement.Name, RemoveVariablesFromLengthenedValue(value) as string);
} catch (ArgumentException) {
throw new EnvironmentVariablesFailedException("Failed to set the " + environmentVariablesElement.Name + " Environment Variable.");
} catch (SecurityException) {
throw new TaskRequiresElevationException("Setting the " + environmentVariablesElement.Name + " Environment Variable requires elevation.");
}

if (value != null) {
values = value.ToUpper().Split(' ').ToList();
}

if (values.Except(compatibilityLayerValues).Any()) {
throw new CompatibilityLayersException();
// if this is the compatibility layer variable
// and the value is not what we want to set it to
// and we're in server mode...
if (environmentVariablesElement.Name == COMPATIBILITY_LAYER_NAME && !String.IsNullOrEmpty(server)) {
values = new List<string>();

if (compatibilityLayerValue != null) {
compatibilityLayerValues = compatibilityLayerValue.ToUpper().Split(' ').ToList();
}

if (value != null) {
values = value.ToUpper().Split(' ').ToList();
}

if (values.Except(compatibilityLayerValues).Any()) {
throw new CompatibilityLayersException("The Compatibility Layers (" + String.Join(", ", compatibilityLayerValues) + ") cannot be set.");
}
}

ProgressManager.CurrentGoal.Steps++;
}
} finally {
ProgressManager.CurrentGoal.Stop();
}
}

Expand All @@ -94,43 +102,51 @@ public void Deactivate(string server) {
try {
compatibilityLayerValue = Environment.GetEnvironmentVariable(COMPATIBILITY_LAYER_NAME);
} catch (ArgumentException) {
throw new EnvironmentVariablesFailedException();
throw new EnvironmentVariablesFailedException("Failed to get the " + COMPATIBILITY_LAYER_NAME + " Environment Variable.");
} catch (SecurityException) {
throw new TaskRequiresElevationException();
throw new TaskRequiresElevationException("Getting the " + COMPATIBILITY_LAYER_NAME + " Environment Variable requires elevation.");
}

if (compatibilityLayerValue != null) {
compatibilityLayerValues = compatibilityLayerValue.ToUpper().Split(' ').ToList();
}

EnvironmentVariablesElement environmentVariablesElement = null;
ProgressManager.CurrentGoal.Start(modificationsElement.EnvironmentVariables.Count);

for (int i = 0;i < modificationsElement.EnvironmentVariables.Count;i++) {
environmentVariablesElement = modificationsElement.EnvironmentVariables.Get(i) as EnvironmentVariablesElement;
try {
EnvironmentVariablesElement environmentVariablesElement = null;

if (environmentVariablesElement == null) {
throw new EnvironmentVariablesFailedException();
}
for (int i = 0;i < modificationsElement.EnvironmentVariables.Count;i++) {
environmentVariablesElement = modificationsElement.EnvironmentVariables.Get(i) as EnvironmentVariablesElement;

value = environmentVariablesElement.Value;
values = new List<string>();
if (environmentVariablesElement == null) {
throw new System.Configuration.ConfigurationErrorsException("The Environment Variables Element (" + i + ") is null.");
}

if (value != null) {
values = value.ToUpper().Split(' ').ToList();
}
value = environmentVariablesElement.Value;
values = new List<string>();

// if this isn't the compatibility layer variable
// or the value isn't what we want to set it to
// or we're not in server mode...
if (environmentVariablesElement.Name != COMPATIBILITY_LAYER_NAME || values.Except(compatibilityLayerValues).Any() || String.IsNullOrEmpty(server)) {
try {
Environment.SetEnvironmentVariable(environmentVariablesElement.Name, null);
} catch (ArgumentException) {
throw new EnvironmentVariablesFailedException();
} catch (SecurityException) {
throw new TaskRequiresElevationException();
if (value != null) {
values = value.ToUpper().Split(' ').ToList();
}

// if this isn't the compatibility layer variable
// or the value isn't what we want to set it to
// or we're not in server mode...
if (environmentVariablesElement.Name != COMPATIBILITY_LAYER_NAME || values.Except(compatibilityLayerValues).Any() || String.IsNullOrEmpty(server)) {
try {
Environment.SetEnvironmentVariable(environmentVariablesElement.Name, null);
} catch (ArgumentException) {
throw new EnvironmentVariablesFailedException("Failed to set the " + environmentVariablesElement.Name + " Environment Variable.");
} catch (SecurityException) {
throw new TaskRequiresElevationException("Getting the " + COMPATIBILITY_LAYER_NAME + " Environment Variable requires elevation.");
}
}

ProgressManager.CurrentGoal.Steps++;
}
} finally {
ProgressManager.CurrentGoal.Stop();
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions FlashpointSecurePlayer/FlashpointProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private static void GetSystemProxy(ref INTERNET_PER_CONN_OPTION_LIST internetPer
int internetPerConnOptionListSize = Marshal.SizeOf(internetPerConnOptionList);

if (internetPerConnOptionListOptions.Length < 2) {
throw new ArgumentException();
throw new ArgumentException("The Internet Per Connection Option List Options cannot have a Length of less than two.");
}

// set flags
Expand Down Expand Up @@ -152,7 +152,7 @@ private static void GetSystemProxy(ref INTERNET_PER_CONN_OPTION_LIST internetPer
bool result = InternetQueryOption(IntPtr.Zero, INTERNET_OPTION.INTERNET_OPTION_PER_CONNECTION_OPTION, ref internetPerConnOptionList, ref internetPerConnOptionListSize);

if (!result) {
throw new FlashpointProxyException();
throw new FlashpointProxyException("Could not query the Internet Options.");
}
}

Expand Down Expand Up @@ -213,12 +213,12 @@ public static void Enable(string proxyServer) {
Marshal.FreeCoTaskMem(internetPerConnOptionListPointer);

if (!InternetCloseHandle(internetHandle)) {
throw new FlashpointProxyException();
throw new FlashpointProxyException("Could not close the Internet Handle.");
}

// throw an exception if this operation failed
if (!result) {
throw new FlashpointProxyException();
throw new FlashpointProxyException("Could not set the Internet Options.");
}
}

Expand Down Expand Up @@ -263,11 +263,11 @@ public static void Disable() {
}

if (!InternetCloseHandle(internetHandle)) {
throw new FlashpointProxyException();
throw new FlashpointProxyException("Could not close the Internet Handle.");
}

if (!result) {
throw new FlashpointProxyException();
throw new FlashpointProxyException("Could not set the Internet Options.");
}
}
}
Expand Down
Loading