Skip to content

Commit

Permalink
move all comparable name checks into Name property
Browse files Browse the repository at this point in the history
  • Loading branch information
tomysshadow committed Jun 4, 2024
1 parent c794c3f commit 5cdd36c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
15 changes: 7 additions & 8 deletions FlashpointSecurePlayer/RegistryStates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1544,11 +1544,10 @@ private void ModificationAdded(RegistryTraceData registryTraceData) {
//if (!modificationsElement.ElementInformation.IsPresent) {
//return;
//}

// comparable names, since registry key/value names shouldn't have null bytes in them according to Win32

RegistryStateElement registryStateElement = new RegistryStateElement {
KeyName = GetComparableName(registryTraceData.KeyName),
ValueName = GetComparableName(registryTraceData.ValueName)
KeyName = registryTraceData.KeyName,
ValueName = registryTraceData.ValueName
};

// KeyHandle is meant to be a uint32, so we discard the rest
Expand Down Expand Up @@ -1741,8 +1740,8 @@ private void ModificationRemoved(RegistryTraceData registryTraceData) {

// create filler element to get name
RegistryStateElement registryStateElement = new RegistryStateElement {
KeyName = GetComparableName(registryTraceData.KeyName),
ValueName = GetComparableName(registryTraceData.ValueName)
KeyName = registryTraceData.KeyName,
ValueName = registryTraceData.ValueName
};

ulong safeKeyHandle = registryTraceData.KeyHandle & 0x00000000FFFFFFFF;
Expand Down Expand Up @@ -1796,7 +1795,7 @@ private void KCBStarted(RegistryTraceData registryTraceData) {
kcbModificationKeyNames = new Dictionary<ulong, string>();
}

kcbModificationKeyNames[safeKeyHandle] = GetComparableName(registryTraceData.KeyName);
kcbModificationKeyNames[safeKeyHandle] = registryTraceData.KeyName;
}

private void KCBStopped(RegistryTraceData registryTraceData) {
Expand Down Expand Up @@ -1855,7 +1854,7 @@ private void KCBStopped(RegistryTraceData registryTraceData) {
registryStateElement = registryStateElements[j];

keyName = GetRedirectedKeyValueName(
GetKeyValueNameFromKernelRegistryString(GetComparableName(registryTraceData.KeyName) + "\\" + registryStateElement.KeyName),
GetKeyValueNameFromKernelRegistryString(registryTraceData.KeyName + "\\" + registryStateElement.KeyName),
modificationsElement.RegistryStates.BinaryType
);

Expand Down
22 changes: 11 additions & 11 deletions FlashpointSecurePlayer/Shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,15 @@ public static HttpClient HttpClient {
// (preferably, no more than eight at a time)
private static SemaphoreSlim downloadSemaphoreSlim = new SemaphoreSlim(1, 1);

public static string GetComparableName(string name) {
if (name == null) {
return name;
}

int comparableNameLength = name.IndexOf('\0');
return comparableNameLength == -1 ? name : name.Substring(0, comparableNameLength);
}

// it'd be nice to move all the configuration, template, section stuff to their own class one day
// http://social.msdn.microsoft.com/Forums/vstudio/en-US/0f3557ee-16bd-4a36-a4f3-00efbeae9b0d/app-config-multiple-sections-in-sectiongroup-with-same-name?forum=csharpgeneral
private static FlashpointSecurePlayerSection flashpointSecurePlayerSection = null;
Expand Down Expand Up @@ -1640,13 +1649,13 @@ public string _ValueExpanded {
// delimiter for a primary key (value names can contain them)
public string Name {
get {
string keyName = KeyName;
string keyName = GetComparableName(KeyName);

if (!String.IsNullOrEmpty(keyName)) {
keyName = keyName.ToUpperInvariant();
}

string valueName = ValueName;
string valueName = GetComparableName(ValueName);

if (!String.IsNullOrEmpty(valueName)) {
valueName = valueName.ToUpperInvariant();
Expand Down Expand Up @@ -2054,15 +2063,6 @@ public string this[string shortPath] {
public PathNamesLong Long { get; } = new PathNamesLong();
}

public static string GetComparableName(string name) {
if (name == null) {
return name;
}

int comparableNameLength = name.IndexOf('\0');
return comparableNameLength == -1 ? name : name.Substring(0, comparableNameLength);
}

public static string GetEnvironmentVariablePreference(List<string> names) {
string preferenceString = null;

Expand Down

0 comments on commit 5cdd36c

Please sign in to comment.