Skip to content

Commit

Permalink
handle for null bytes in registry key names (RegHide)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomysshadow committed Jun 4, 2024
1 parent c1ed19d commit c794c3f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
9 changes: 0 additions & 9 deletions FlashpointSecurePlayer/EnvironmentVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ public class EnvironmentVariables : Modifications {

public EnvironmentVariables(EventHandler importStart, EventHandler importStop) : base(importStart, importStop) { }

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

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

private string GetFlashpointProxyName(string name, out string comparableName) {
comparableName = null;

Expand Down
13 changes: 7 additions & 6 deletions FlashpointSecurePlayer/RegistryStates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1545,9 +1545,10 @@ private void ModificationAdded(RegistryTraceData registryTraceData) {
//return;
//}

// comparable names, since registry key/value names shouldn't have null bytes in them according to Win32
RegistryStateElement registryStateElement = new RegistryStateElement {
KeyName = registryTraceData.KeyName,
ValueName = registryTraceData.ValueName
KeyName = GetComparableName(registryTraceData.KeyName),
ValueName = GetComparableName(registryTraceData.ValueName)
};

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

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

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

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

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

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

Expand Down
9 changes: 9 additions & 0 deletions FlashpointSecurePlayer/Shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2054,6 +2054,15 @@ 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 c794c3f

Please sign in to comment.