Permalink
Browse files

Cleanup of uses of GetFileName to fix issue #10.

  • Loading branch information...
tyranid committed Nov 6, 2018
1 parent 9333d73 commit 65a4ae8de5aaa75394acfb0c8b5bcb5447600e65
@@ -88,19 +88,19 @@ public class COMAppIDServiceEntry : IXmlSerializable
DisplayName = service.DisplayName;
Name = service.ServiceName;
ServiceType = service.ServiceType;
ServiceDll = String.Empty;
ImagePath = String.Empty;
UserName = String.Empty;
ServiceDll = string.Empty;
ImagePath = string.Empty;
UserName = string.Empty;
if (key != null)
{
UserName = COMUtilities.ReadStringFromKey(key, null, "ObjectName");
ImagePath = COMUtilities.ReadStringFromKey(key, null, "ImagePath");
ServiceDll = COMUtilities.ReadStringFromKey(key, "Parameters", "ServiceDll");
if (String.IsNullOrEmpty(ServiceDll))
UserName = key.ReadString(null, "ObjectName");
ImagePath = key.ReadString(null, "ImagePath");
ServiceDll = key.ReadString("Parameters", "ServiceDll");
if (string.IsNullOrEmpty(ServiceDll))
{
ServiceDll = COMUtilities.ReadStringFromKey(key, null, "ServiceDll");
ServiceDll = key.ReadString(null, "ServiceDll");
}
ProtectionLevel = (ServiceProtectionLevel) COMUtilities.ReadIntFromKey(key, null, "LaunchProtected");
ProtectionLevel = (ServiceProtectionLevel) COMUtilities.ReadInt(key, null, "LaunchProtected");
}
}
@@ -56,8 +56,8 @@ public class COMCLSIDElevationEntry : IXmlSerializable
internal COMCLSIDElevationEntry(RegistryKey key, RegistryKey vso_key, bool auto_approval)
{
Enabled = COMUtilities.ReadIntFromKey(key, null, "Enabled") != 0;
IconReference = COMUtilities.ReadStringFromKey(key, null, "IconReference");
Enabled = COMUtilities.ReadInt(key, null, "Enabled") != 0;
IconReference = COMUtilities.ReadString(key, null, "IconReference");
HashSet<Guid> vsos = new HashSet<Guid>();
if (vso_key != null)
{
@@ -136,10 +136,10 @@ internal COMCLSIDServerDotNetEntry()
internal COMCLSIDServerDotNetEntry(RegistryKey key)
{
AssemblyName = COMUtilities.ReadStringFromKey(key, null, "Assembly");
ClassName = COMUtilities.ReadStringFromKey(key, null, "Class");
CodeBase = COMUtilities.ReadStringFromKey(key, null, "CodeBase");
RuntimeVersion = COMUtilities.ReadStringFromKey(key, null, "RuntimeVersion");
AssemblyName = COMUtilities.ReadString(key, null, "Assembly");
ClassName = COMUtilities.ReadString(key, null, "Class");
CodeBase = COMUtilities.ReadString(key, null, "CodeBase");
RuntimeVersion = COMUtilities.ReadString(key, null, "RuntimeVersion");
}
XmlSchema IXmlSerializable.GetSchema()
@@ -305,34 +305,32 @@ private static string ProcessFileName(string filename, bool process_command_line
private static COMThreadingModel ReadThreadingModel(RegistryKey key)
{
string threading_model = key.GetValue("ThreadingModel") as string;
if (threading_model != null)
string threading_model = key.ReadString(valueName: "ThreadingModel");
switch (threading_model.ToLower())
{
switch (threading_model.ToLower())
{
case "both":
return COMThreadingModel.Both;
case "free":
return COMThreadingModel.Free;
case "neutral":
return COMThreadingModel.Neutral;
case "apartment":
return COMThreadingModel.Apartment;
}
case "both":
return COMThreadingModel.Both;
case "free":
return COMThreadingModel.Free;
case "neutral":
return COMThreadingModel.Neutral;
case "apartment":
return COMThreadingModel.Apartment;
default:
return COMThreadingModel.None;
}
return COMThreadingModel.None;
}
internal COMCLSIDServerEntry(COMServerType server_type, string server)
{
Server = server;
CommandLine = String.Empty;
CommandLine = string.Empty;
ServerType = server_type;
ThreadingModel = COMThreadingModel.Apartment;
}
internal COMCLSIDServerEntry(COMServerType server_type)
: this(server_type, String.Empty)
: this(server_type, string.Empty)
{
}
@@ -343,22 +341,22 @@ internal COMCLSIDServerEntry() : this(COMServerType.UnknownServer)
internal COMCLSIDServerEntry(RegistryKey key, COMServerType server_type)
: this(server_type)
{
string server_string = key.GetValue(null) as string;
RawServer = key.GetValue(null, null, RegistryValueOptions.DoNotExpandEnvironmentNames) as string;
string server_string = key.ReadString();
RawServer = key.ReadString(options: RegistryValueOptions.DoNotExpandEnvironmentNames);
if (String.IsNullOrWhiteSpace(server_string))
if (string.IsNullOrWhiteSpace(server_string))
{
// TODO: Support weird .NET registration which registers a .NET version string.
return;
}
bool process_command_line = false;
CommandLine = String.Empty;
CommandLine = string.Empty;
if (server_type == COMServerType.LocalServer32)
{
string executable = key.GetValue("ServerExecutable") as string;
if (executable != null)
string executable = key.ReadString(valueName: "ServerExecutable");
if (!string.IsNullOrWhiteSpace(executable))
{
server_string = executable;
}
@@ -581,22 +579,22 @@ private void LoadFromKey(RegistryKey key)
if (fake_name && inproc_server != null && inproc_server.HasDotNet)
{
Name = String.Format("{0}, {1}", inproc_server.DotNet.ClassName, inproc_server.DotNet.AssemblyName);
Name = string.Format("{0}, {1}", inproc_server.DotNet.ClassName, inproc_server.DotNet.AssemblyName);
}
AppID = COMUtilities.ReadGuidFromKey(key, null, "AppID");
AppID = COMUtilities.ReadGuid(key, null, "AppID");
if (AppID == Guid.Empty)
{
AppID = COMUtilities.ReadGuidFromKey(Registry.ClassesRoot,
String.Format(@"AppID\{0}", Path.GetFileName(DefaultServer)), "AppID");
AppID = COMUtilities.ReadGuid(Registry.ClassesRoot,
string.Format(@"AppID\{0}", COMUtilities.GetFileName(DefaultServer)), "AppID");
}
if (AppID != Guid.Empty && !servers.ContainsKey(COMServerType.LocalServer32))
{
servers.Add(COMServerType.LocalServer32, new COMCLSIDServerEntry(COMServerType.LocalServer32, "<APPID HOSTED>"));
}
TypeLib = COMUtilities.ReadGuidFromKey(key, "TypeLib", null);
TypeLib = COMUtilities.ReadGuid(key, "TypeLib", null);
if (key.HasSubkey("Control"))
{
categories.Add(COMCategory.CATID_Control);
@@ -630,7 +628,7 @@ private void LoadFromKey(RegistryKey key)
}
Categories = categories.ToList().AsReadOnly();
TreatAs = COMUtilities.ReadGuidFromKey(key, "TreatAs", null);
TreatAs = COMUtilities.ReadGuid(key, "TreatAs", null);
using (RegistryKey elev_key = key.OpenSubKey("Elevation"),
vso_key = key.OpenSubKey("VirtualServerObjects"))
@@ -640,7 +638,7 @@ private void LoadFromKey(RegistryKey key)
using (var base_key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine,
Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Default))
{
int auto_approval = COMUtilities.ReadIntFromKey(base_key,
int auto_approval = COMUtilities.ReadInt(base_key,
@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\UAC\COMAutoApprovalList", Clsid.ToString("B"));
Elevation = new COMCLSIDElevationEntry(elev_key, vso_key, auto_approval != 0);
}
@@ -62,17 +62,17 @@ private void LoadFromKey(RegistryKey key)
Name = Iid.FormatGuidDefault();
}
ProxyClsid = COMUtilities.ReadGuidFromKey(key, "ProxyStubCLSID32", null);
NumMethods = COMUtilities.ReadIntFromKey(key, "NumMethods", null);
ProxyClsid = COMUtilities.ReadGuid(key, "ProxyStubCLSID32", null);
NumMethods = COMUtilities.ReadInt(key, "NumMethods", null);
if (NumMethods < 3)
{
NumMethods = 3;
}
TypeLib = COMUtilities.ReadGuidFromKey(key, "TypeLib", null);
TypeLibVersion = COMUtilities.ReadStringFromKey(key, "TypeLib", "Version");
Base = COMUtilities.ReadStringFromKey(key, "BaseInterface", null);
TypeLib = COMUtilities.ReadGuid(key, "TypeLib", null);
TypeLibVersion = COMUtilities.ReadString(key, "TypeLib", "Version");
Base = COMUtilities.ReadString(key, "BaseInterface", null);
if (Base.Length == 0)
{
Base = "IUnknown";
@@ -875,7 +875,7 @@ private void LoadProgIDs(RegistryKey rootKey)
{
using (RegistryKey regKey = rootKey.OpenSubKey(key))
{
Guid clsid = COMUtilities.ReadGuidFromKey(regKey, "CLSID", null);
Guid clsid = COMUtilities.ReadGuid(regKey, "CLSID", null);
if (clsid != Guid.Empty)
{
COMProgIDEntry entry = new COMProgIDEntry(this, key, clsid, regKey);
@@ -2108,7 +2108,7 @@ private void viewProxyDefinitionToolStripMenuItem_Click(object sender, EventArgs
using (var resolver = EntryPoint.GetProxyParserSymbolResolver())
{
EntryPoint.GetMainForm(m_registry).HostControl(new TypeLibControl(m_registry,
Path.GetFileName(clsid.DefaultServer),
COMUtilities.GetFileName(clsid.DefaultServer),
COMProxyInstance.GetFromCLSID(clsid, resolver), selected_iid));
}
}
@@ -68,7 +68,7 @@ public string DllName
{
return string.Empty;
}
return Path.GetFileName(DllPath);
return COMUtilities.GetFileName(DllPath);
}
}
public string PackageId { get; private set; }
@@ -136,15 +136,15 @@ public Type RuntimeType
private void LoadFromKey(RegistryKey key)
{
Clsid = COMUtilities.ReadGuidFromKey(key, null, "CLSID");
ActivationType = (ActivationType)COMUtilities.ReadIntFromKey(key, null, "ActivationType");
TrustLevel = (TrustLevel)COMUtilities.ReadIntFromKey(key, null, "TrustLevel");
Threading = (ThreadingType)COMUtilities.ReadIntFromKey(key, null, "Threading");
DllPath = COMUtilities.ReadStringFromKey(key, null, "DllPath");
Server = COMUtilities.ReadStringFromKey(key, null, "Server");
Clsid = COMUtilities.ReadGuid(key, null, "CLSID");
ActivationType = (ActivationType)COMUtilities.ReadInt(key, null, "ActivationType");
TrustLevel = (TrustLevel)COMUtilities.ReadInt(key, null, "TrustLevel");
Threading = (ThreadingType)COMUtilities.ReadInt(key, null, "Threading");
DllPath = COMUtilities.ReadString(key, null, "DllPath");
Server = COMUtilities.ReadString(key, null, "Server");
byte[] permissions = key.GetValue("Permissions", new byte[0]) as byte[];
Permissions = COMSecurity.GetStringSDForSD(permissions);
ActivateInSharedBroker = COMUtilities.ReadIntFromKey(key, null, "ActivateInSharedBroker") != 0;
ActivateInSharedBroker = COMUtilities.ReadInt(key, null, "ActivateInSharedBroker") != 0;
}
internal COMRuntimeClassEntry(COMRegistry registry, string package_id, string name)
@@ -42,10 +42,10 @@ private void LoadFromKey(RegistryKey key)
}
}
CustomProperties = custom_properties;
Description = COMUtilities.ReadStringFromKey(key, null, "Description");
DisplayName = COMUtilities.ReadStringFromKey(key, null, "DisplayName");
Icon = COMUtilities.ReadStringFromKey(key, null, "Icon");
Vendor = COMUtilities.ReadStringFromKey(key, null, "Vendor");
Description = COMUtilities.ReadString(key, null, "Description");
DisplayName = COMUtilities.ReadString(key, null, "DisplayName");
Icon = COMUtilities.ReadString(key, null, "Icon");
Vendor = COMUtilities.ReadString(key, null, "Vendor");
}
#endregion
@@ -82,12 +82,12 @@ public bool HasPermission
private void LoadFromKey(RegistryKey key)
{
IdentityType = (IdentityType)COMUtilities.ReadIntFromKey(key, null, "IdentityType");
ServerType = (ServerType)COMUtilities.ReadIntFromKey(key, null, "ServerType");
InstancingType = (InstancingType)COMUtilities.ReadIntFromKey(key, null, "InstancingType");
Identity = COMUtilities.ReadStringFromKey(key, null, "Identity");
ServiceName = COMUtilities.ReadStringFromKey(key, null, "ServiceName");
ExePath = COMUtilities.ReadStringFromKey(key, null, "ExePath");
IdentityType = (IdentityType)COMUtilities.ReadInt(key, null, "IdentityType");
ServerType = (ServerType)COMUtilities.ReadInt(key, null, "ServerType");
InstancingType = (InstancingType)COMUtilities.ReadInt(key, null, "InstancingType");
Identity = COMUtilities.ReadString(key, null, "Identity");
ServiceName = COMUtilities.ReadString(key, null, "ServiceName");
ExePath = COMUtilities.ReadString(key, null, "ExePath");
Permissions = string.Empty;
byte[] permissions = key.GetValue("Permissions", new byte[0]) as byte[];
Permissions = COMSecurity.GetStringSDForSD(permissions);
@@ -529,7 +529,7 @@ static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs ar
return null;
}
public static string ReadStringFromKey(RegistryKey rootKey, string keyName, string valueName)
public static string ReadString(this RegistryKey rootKey, string keyName = null, string valueName = null, RegistryValueOptions options = RegistryValueOptions.None)
{
RegistryKey key = rootKey;
@@ -543,14 +543,20 @@ public static string ReadStringFromKey(RegistryKey rootKey, string keyName, stri
string valueString = string.Empty;
if (key != null)
{
object valueObject = key.GetValue(valueName);
object valueObject = key.GetValue(valueName, null, options);
if (valueObject != null)
{
valueString = valueObject.ToString();
}
}
return valueString.TrimEnd('\0');
int first_nul = valueString.IndexOf('\0');
if (first_nul >= 0)
{
valueString = valueString.Substring(0, first_nul);
}
return valueString;
}
finally
{
@@ -561,9 +567,9 @@ public static string ReadStringFromKey(RegistryKey rootKey, string keyName, stri
}
}
public static int ReadIntFromKey(RegistryKey rootKey, string keyName, string valueName)
public static int ReadInt(this RegistryKey rootKey, string keyName, string valueName)
{
string value = ReadStringFromKey(rootKey, keyName, valueName);
string value = rootKey.ReadString(keyName, valueName);
if (value != null)
{
int ret;
@@ -575,9 +581,9 @@ public static int ReadIntFromKey(RegistryKey rootKey, string keyName, string val
return 0;
}
public static Guid ReadGuidFromKey(RegistryKey rootKey, string keyName, string valueName)
public static Guid ReadGuid(this RegistryKey rootKey, string keyName, string valueName)
{
string guid = ReadStringFromKey(rootKey, keyName, valueName);
string guid = rootKey.ReadString(keyName, valueName);
Guid ret = Guid.Empty;
if (guid != null && Guid.TryParse(guid, out ret))
{
@@ -606,7 +606,8 @@ private void viewProxyDefinitionToolStripMenuItem_Click(object sender, EventArgs
using (var resolver = EntryPoint.GetProxyParserSymbolResolver())
{
EntryPoint.GetMainForm(m_registry).HostControl(new TypeLibControl(m_registry,
Path.GetFileName(clsid.DefaultServer), COMProxyInstance.GetFromCLSID(clsid, resolver), intf.Item1.Iid));
COMUtilities.GetFileName(clsid.DefaultServerName),
COMProxyInstance.GetFromCLSID(clsid, resolver), intf.Item1.Iid));
}
}
}

0 comments on commit 65a4ae8

Please sign in to comment.