Skip to content

Commit

Permalink
remaining workaround msvc uninitialized stack bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jxy-s committed Dec 26, 2024
1 parent eb4430e commit f6c7493
Show file tree
Hide file tree
Showing 33 changed files with 269 additions and 130 deletions.
9 changes: 5 additions & 4 deletions SystemInformer/actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -2376,7 +2376,7 @@ BOOLEAN PhUiRestartProcess(
processHandle = NULL;

// Start the process.
//
//
// Use the existing process as the parent, and restarting the process will inherit most of the process configuration from itself (dmex)

status = PhOpenProcess(
Expand Down Expand Up @@ -2920,7 +2920,7 @@ BOOLEAN PhUiSetEcoModeProcess(
PhSetProcessPriorityClass(processHandle, PROCESS_PRIORITY_CLASS_IDLE);

//
// Turn PROCESS_EXECUTION_SPEED throttling on.
// Turn PROCESS_EXECUTION_SPEED throttling on.
//
status = PhSetProcessPowerThrottlingState(
processHandle,
Expand Down Expand Up @@ -4097,7 +4097,7 @@ static NTSTATUS PhpCheckServiceStatus(
}
else if ((NtGetTickCount64() - serviceTicks) > serviceStatus.dwWaitHint)
{
// Service doesn't report progress.
// Service doesn't report progress.
}
}

Expand Down Expand Up @@ -6304,6 +6304,7 @@ BOOLEAN PhUiFlushHeapProcesses(
{
BOOLEAN success = TRUE;
ULONG i;
LARGE_INTEGER timeout;

for (i = 0; i < NumberOfProcesses; i++)
{
Expand All @@ -6319,7 +6320,7 @@ BOOLEAN PhUiFlushHeapProcesses(

if (NT_SUCCESS(status))
{
status = PhFlushProcessHeapsRemote(processHandle, PhTimeoutFromMillisecondsEx(4000));
status = PhFlushProcessHeapsRemote(processHandle, PhTimeoutFromMilliseconds(&timeout, 4000));
NtClose(processHandle);
}

Expand Down
3 changes: 0 additions & 3 deletions SystemInformer/include/phplug.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ typedef struct _PH_PROCESS_PROVIDER_UPDATED_EVENT
ULONG RunCount;
} PH_PROCESS_PROVIDER_UPDATED_EVENT, *PPH_PROCESS_PROVIDER_UPDATED_EVENT;

#define PH_PROCESS_PROVIDER_UPDATED_EVENT_PTR(RunCount) \
&(PH_PROCESS_PROVIDER_UPDATED_EVENT){ (RunCount) }

// Plugin events

typedef struct _PH_PLUGIN_GET_HIGHLIGHTING_COLOR
Expand Down
6 changes: 4 additions & 2 deletions SystemInformer/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ INT WINAPI wWinMain(
PhSetProcessPowerThrottlingState(
NtCurrentProcess(),
PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION,
0 // Disable synthetic timer resolution.
0 // Disable synthetic timer resolution.
);
}
}
Expand Down Expand Up @@ -1078,7 +1078,9 @@ BOOLEAN PhInitializeTimerPolicy(
VOID
)
{
SetUserObjectInformation(NtCurrentProcess(), UOI_TIMERPROC_EXCEPTION_SUPPRESSION, &(BOOL){ FALSE }, sizeof(BOOL));
static BOOL timerSuppression = FALSE;

SetUserObjectInformation(NtCurrentProcess(), UOI_TIMERPROC_EXCEPTION_SUPPRESSION, &timerSuppression, sizeof(BOOL));

return TRUE;
}
Expand Down
3 changes: 2 additions & 1 deletion SystemInformer/memsrch.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ PVOID PhAllocateForMemorySearch(
_In_ SIZE_T Size
)
{
static ULONG heapCompatibility = HEAP_COMPATIBILITY_LFH;
PVOID memory;

PhAcquireQueuedLockExclusive(&PhMemorySearchHeapLock);
Expand All @@ -116,7 +117,7 @@ PVOID PhAllocateForMemorySearch(
RtlSetHeapInformation(
PhMemorySearchHeap,
HeapCompatibilityInformation,
&(ULONG){ HEAP_COMPATIBILITY_LFH },
&heapCompatibility,
sizeof(ULONG)
);

Expand Down
16 changes: 12 additions & 4 deletions SystemInformer/netlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ BEGIN_SORT_FUNCTION(LocalAddress)
{
SOCKADDR_IN6 localAddress1;
SOCKADDR_IN6 localAddress2;
SCOPE_ID scopeId1;
SCOPE_ID scopeId2;

memset(&localAddress1, 0, sizeof(SOCKADDR_IN6)); // memset for zero padding (dmex)
memset(&localAddress2, 0, sizeof(SOCKADDR_IN6));
Expand All @@ -437,7 +439,8 @@ BEGIN_SORT_FUNCTION(LocalAddress)
}
else if (networkItem1->LocalEndpoint.Address.Type == PH_IPV6_NETWORK_TYPE)
{
IN6ADDR_SETSOCKADDR(&localAddress1, &networkItem1->LocalEndpoint.Address.In6Addr, (SCOPE_ID){ .Value = networkItem1->LocalScopeId }, 0);
scopeId1.Value = networkItem1->LocalScopeId;
IN6ADDR_SETSOCKADDR(&localAddress1, &networkItem1->LocalEndpoint.Address.In6Addr, scopeId1, 0);
}

if (networkItem2->LocalEndpoint.Address.Type == PH_IPV4_NETWORK_TYPE)
Expand All @@ -449,7 +452,8 @@ BEGIN_SORT_FUNCTION(LocalAddress)
}
else if (networkItem2->LocalEndpoint.Address.Type == PH_IPV6_NETWORK_TYPE)
{
IN6ADDR_SETSOCKADDR(&localAddress2, &networkItem2->LocalEndpoint.Address.In6Addr, (SCOPE_ID){ .Value = networkItem2->LocalScopeId }, 0);
scopeId2.Value = networkItem2->LocalScopeId;
IN6ADDR_SETSOCKADDR(&localAddress2, &networkItem2->LocalEndpoint.Address.In6Addr, scopeId2, 0);
}

sortResult = memcmp(&localAddress1, &localAddress2, sizeof(SOCKADDR_IN6));
Expand All @@ -472,6 +476,8 @@ BEGIN_SORT_FUNCTION(RemoteAddress)
{
SOCKADDR_IN6 remoteAddress1;
SOCKADDR_IN6 remoteAddress2;
SCOPE_ID scopeId1;
SCOPE_ID scopeId2;

memset(&remoteAddress1, 0, sizeof(SOCKADDR_IN6)); // memset for zero padding (dmex)
memset(&remoteAddress2, 0, sizeof(SOCKADDR_IN6));
Expand All @@ -485,7 +491,8 @@ BEGIN_SORT_FUNCTION(RemoteAddress)
}
else if (networkItem1->RemoteEndpoint.Address.Type == PH_IPV6_NETWORK_TYPE)
{
IN6ADDR_SETSOCKADDR(&remoteAddress1, &networkItem1->RemoteEndpoint.Address.In6Addr, (SCOPE_ID){ .Value = networkItem1->RemoteScopeId }, 0);
scopeId1.Value = networkItem1->RemoteScopeId;
IN6ADDR_SETSOCKADDR(&remoteAddress1, &networkItem1->RemoteEndpoint.Address.In6Addr, scopeId1, 0);
}

if (networkItem2->RemoteEndpoint.Address.Type == PH_IPV4_NETWORK_TYPE)
Expand All @@ -497,7 +504,8 @@ BEGIN_SORT_FUNCTION(RemoteAddress)
}
else if (networkItem2->RemoteEndpoint.Address.Type == PH_IPV6_NETWORK_TYPE)
{
IN6ADDR_SETSOCKADDR(&remoteAddress2, &networkItem2->RemoteEndpoint.Address.In6Addr, (SCOPE_ID){ .Value = networkItem2->RemoteScopeId }, 0);
scopeId2.Value = networkItem2->RemoteScopeId;
IN6ADDR_SETSOCKADDR(&remoteAddress2, &networkItem2->RemoteEndpoint.Address.In6Addr, scopeId2, 0);
}

sortResult = memcmp(&remoteAddress1, &remoteAddress2, sizeof(SOCKADDR_IN6));
Expand Down
4 changes: 3 additions & 1 deletion SystemInformer/notifico.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ VOID PhNfUninitialization(
)
{
#ifdef PH_NF_ENABLE_WORKQUEUE
//LARGE_INTEGER timeout;

if (PhpTrayIconEventHandle)
NtSetEvent(PhpTrayIconEventHandle, NULL);
#endif
Expand All @@ -423,7 +425,7 @@ VOID PhNfUninitialization(
//#ifdef PH_NF_ENABLE_WORKQUEUE
// if (PhpTrayIconThreadHandle)
// {
// NtWaitForSingleObject(PhpTrayIconThreadHandle, FALSE, PhTimeoutFromMillisecondsEx(1000));
// NtWaitForSingleObject(PhpTrayIconThreadHandle, FALSE, PhTimeoutFromMilliseconds(&timeout, 1000));
// }
//#endif
}
Expand Down
6 changes: 4 additions & 2 deletions SystemInformer/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,9 @@ NTSTATUS PhpSetSilentProcessNotifyEnabled(
{
static PH_STRINGREF processExitKeyName = PH_STRINGREF_INIT(L"Software\\Microsoft\\Windows NT\\CurrentVersion\\SilentProcessExit");
static PH_STRINGREF valueModeName = PH_STRINGREF_INIT(L"ReportingMode");
static ULONG valueMode = 4;
//static PH_STRINGREF valueSelfName = PH_STRINGREF_INIT(L"IgnoreSelfExits");
//static ULONG valueSelf = 1;
//static PH_STRINGREF valueMonitorName = PH_STRINGREF_INIT(L"MonitorProcess");
static PH_STRINGREF valueGlobalName = PH_STRINGREF_INIT(L"GlobalFlag");
NTSTATUS status = STATUS_UNSUCCESSFUL;
Expand Down Expand Up @@ -1262,14 +1264,14 @@ NTSTATUS PhpSetSilentProcessNotifyEnabled(
keyFilenameHandle,
&valueModeName,
REG_DWORD,
&(ULONG){ 4 },
&valueMode,
sizeof(ULONG)
);

if (!NT_SUCCESS(status))
goto CleanupExit;

//PhSetValueKey(keyFilenameHandle, &valueSelfName, REG_DWORD, &(ULONG){ 1 }, sizeof(ULONG));
//PhSetValueKey(keyFilenameHandle, &valueSelfName, REG_DWORD, &valueSelf, sizeof(ULONG));
//PhSetValueKey(keyFilenameHandle, &valueMonitorName, REG_SZ, filename->Buffer, (ULONG)filename->Length + sizeof(UNICODE_NULL));

if (NT_SUCCESS(status))
Expand Down
3 changes: 2 additions & 1 deletion SystemInformer/phsvc/clapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ NTSTATUS PhSvcConnectToServer(
_In_opt_ SIZE_T PortSectionSize
)
{
static ULONG heapCompatibility = HEAP_COMPATIBILITY_LFH;
NTSTATUS status;
HANDLE sectionHandle;
LARGE_INTEGER sectionSize;
Expand Down Expand Up @@ -110,7 +111,7 @@ NTSTATUS PhSvcConnectToServer(
RtlSetHeapInformation(
PhSvcClPortHeap,
HeapCompatibilityInformation,
&(ULONG){ HEAP_COMPATIBILITY_LFH },
&heapCompatibility,
sizeof(ULONG)
);

Expand Down
2 changes: 1 addition & 1 deletion SystemInformer/procprv.c
Original file line number Diff line number Diff line change
Expand Up @@ -3225,7 +3225,7 @@ VOID PhProcessProviderUpdate(
}
}

PhInvokeCallback(PhGetGeneralCallback(GeneralCallbackProcessProviderUpdatedEvent), PH_PROCESS_PROVIDER_UPDATED_EVENT_PTR(runCount));
PhInvokeCallback(PhGetGeneralCallback(GeneralCallbackProcessProviderUpdatedEvent), &runCount);
runCount++;
}

Expand Down
8 changes: 4 additions & 4 deletions SystemInformer/runas.c
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ NTSTATUS PhRunAsExecuteParentCommand(
}

status = PhSetDesktopWinStaAccess(WindowHandle);

if (!NT_SUCCESS(status))
goto CleanupExit;

Expand Down Expand Up @@ -1134,7 +1134,7 @@ VOID PhRunAsExecuteCommmand(
createInfo.DesktopName = PhGetString(desktopName);

status = PhSetDesktopWinStaAccess(Context->WindowHandle);

if (!NT_SUCCESS(status))
goto CleanupAsUserExit;

Expand Down Expand Up @@ -2076,7 +2076,7 @@ NTSTATUS PhInvokeRunAsService(
ULONG flags;

status = PhSetDesktopWinStaAccess(Parameters->WindowHandle);

if (!NT_SUCCESS(status))
return status;

Expand Down Expand Up @@ -2507,7 +2507,7 @@ NTSTATUS RunAsCreateProcessThread(
status = PhUpdateProcThreadAttribute(
attributeList,
PROC_THREAD_ATTRIBUTE_PARENT_PROCESS,
&(HANDLE){ processHandle },
&processHandle,
sizeof(HANDLE)
);

Expand Down
5 changes: 3 additions & 2 deletions SystemInformer/syssccpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,7 @@ BOOLEAN PhIsCoreParked(
)
{
static ULONG initialBufferSize = 0;
static HANDLE processHandle = NULL;
NTSTATUS status;
ULONG returnLength;
BOOLEAN isParked;
Expand Down Expand Up @@ -1976,7 +1977,7 @@ BOOLEAN PhIsCoreParked(

status = NtQuerySystemInformationEx(
SystemCpuSetInformation,
&(HANDLE){NULL},
&processHandle,
sizeof(HANDLE),
cpuSetInfo,
returnLength,
Expand All @@ -1992,7 +1993,7 @@ BOOLEAN PhIsCoreParked(

status = NtQuerySystemInformationEx(
SystemCpuSetInformation,
&(HANDLE){NULL},
&processHandle,
sizeof(HANDLE),
cpuSetInfo,
returnLength,
Expand Down
15 changes: 10 additions & 5 deletions phlib/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ PSID PhSeAdministratorsSid( // WinBuiltinAdministratorsSid (dmex)
{
static PH_INITONCE initOnce = PH_INITONCE_INIT;
static UCHAR administratorsSidBuffer[FIELD_OFFSET(SID, SubAuthority) + sizeof(ULONG[2])];
static SID_IDENTIFIER_AUTHORITY authority = SECURITY_NT_AUTHORITY;
PSID administratorsSid = (PSID)administratorsSidBuffer;

if (PhBeginInitOnce(&initOnce))
{
PhInitializeSid(administratorsSid, &(SID_IDENTIFIER_AUTHORITY){ SECURITY_NT_AUTHORITY }, 2);
PhInitializeSid(administratorsSid, &authority, 2);
*PhSubAuthoritySid(administratorsSid, 0) = SECURITY_BUILTIN_DOMAIN_RID;
*PhSubAuthoritySid(administratorsSid, 1) = DOMAIN_ALIAS_RID_ADMINS;

Expand All @@ -67,11 +68,12 @@ PSID PhSeUsersSid( // WinBuiltinUsersSid (dmex)
{
static PH_INITONCE initOnce = PH_INITONCE_INIT;
static UCHAR usersSidBuffer[FIELD_OFFSET(SID, SubAuthority) + sizeof(ULONG[2])];
static SID_IDENTIFIER_AUTHORITY authority = SECURITY_NT_AUTHORITY;
PSID usersSid = (PSID)usersSidBuffer;

if (PhBeginInitOnce(&initOnce))
{
PhInitializeSid(usersSid, &(SID_IDENTIFIER_AUTHORITY){ SECURITY_NT_AUTHORITY }, 2);
PhInitializeSid(usersSid, &authority, 2);
*PhSubAuthoritySid(usersSid, 0) = SECURITY_BUILTIN_DOMAIN_RID;
*PhSubAuthoritySid(usersSid, 1) = DOMAIN_ALIAS_RID_USERS;

Expand All @@ -89,11 +91,12 @@ PSID PhSeAnyPackageSid( // WinBuiltinAnyPackageSid (dmex)
{
static PH_INITONCE initOnce = PH_INITONCE_INIT;
static UCHAR anyAppPackagesSidBuffer[FIELD_OFFSET(SID, SubAuthority) + sizeof(ULONG[2])];
static SID_IDENTIFIER_AUTHORITY authority = SECURITY_APP_PACKAGE_AUTHORITY;
PSID anyAppPackagesSid = (PSID)anyAppPackagesSidBuffer;

if (PhBeginInitOnce(&initOnce))
{
PhInitializeSid(anyAppPackagesSid, &(SID_IDENTIFIER_AUTHORITY){ SECURITY_APP_PACKAGE_AUTHORITY }, SECURITY_BUILTIN_APP_PACKAGE_RID_COUNT);
PhInitializeSid(anyAppPackagesSid, &authority, SECURITY_BUILTIN_APP_PACKAGE_RID_COUNT);
*PhSubAuthoritySid(anyAppPackagesSid, 0) = SECURITY_APP_PACKAGE_BASE_RID;
*PhSubAuthoritySid(anyAppPackagesSid, 1) = SECURITY_BUILTIN_PACKAGE_ANY_PACKAGE;

Expand All @@ -111,11 +114,12 @@ PSID PhSeInternetExplorerSid( // S-1-15-3-4096 (dmex)
{
static PH_INITONCE initOnce = PH_INITONCE_INIT;
static UCHAR internetExplorerSidBuffer[FIELD_OFFSET(SID, SubAuthority) + sizeof(ULONG[2])];
static SID_IDENTIFIER_AUTHORITY authority = SECURITY_APP_PACKAGE_AUTHORITY;
PSID internetExplorerSid = (PSID)internetExplorerSidBuffer;

if (PhBeginInitOnce(&initOnce))
{
PhInitializeSid(internetExplorerSid, &(SID_IDENTIFIER_AUTHORITY){ SECURITY_APP_PACKAGE_AUTHORITY }, SECURITY_BUILTIN_APP_PACKAGE_RID_COUNT);
PhInitializeSid(internetExplorerSid, &authority, SECURITY_BUILTIN_APP_PACKAGE_RID_COUNT);
*PhSubAuthoritySid(internetExplorerSid, 0) = SECURITY_CAPABILITY_BASE_RID;
*PhSubAuthoritySid(internetExplorerSid, 1) = SECURITY_CAPABILITY_INTERNET_EXPLORER;

Expand All @@ -133,11 +137,12 @@ PSID PhSeCloudActiveDirectorySid( // S-1-12-1 (dmex)
{
static PH_INITONCE initOnce = PH_INITONCE_INIT;
static UCHAR activeDirectorySidBuffer[FIELD_OFFSET(SID, SubAuthority) + sizeof(ULONG[1])];
static SID_IDENTIFIER_AUTHORITY authority = { 0, 0, 0, 0, 0, 12 };
PSID activeDirectorySid = (PSID)activeDirectorySidBuffer;

if (PhBeginInitOnce(&initOnce))
{
PhInitializeSid(activeDirectorySid, &(SID_IDENTIFIER_AUTHORITY){ 0, 0, 0, 0, 0, 12 }, 1);
PhInitializeSid(activeDirectorySid, &authority, 1);
*PhSubAuthoritySid(activeDirectorySid, 0) = 1;

PhEndInitOnce(&initOnce);
Expand Down
4 changes: 3 additions & 1 deletion phlib/global.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ BOOLEAN PhHeapInitialization(

if (!PhHeapHandle)
{
static ULONG heapCompatibility = HEAP_COMPATIBILITY_LFH;

PhHeapHandle = RtlCreateHeap(
HEAP_GROWABLE | HEAP_CLASS_1,
NULL,
Expand All @@ -336,7 +338,7 @@ BOOLEAN PhHeapInitialization(
RtlSetHeapInformation(
PhHeapHandle,
HeapCompatibilityInformation,
&(ULONG){ HEAP_COMPATIBILITY_LFH },
&heapCompatibility,
sizeof(ULONG)
);
}
Expand Down
Loading

0 comments on commit f6c7493

Please sign in to comment.