From 7dd1875e1d28778a9ff7a2ba5d7054a48b4fe3c6 Mon Sep 17 00:00:00 2001 From: Brady McDermott Date: Sat, 28 Oct 2023 22:15:24 -0600 Subject: [PATCH] i hate this --- progmgr/group.c | 39 ++++++++++++++++++++++++++++++++++++--- progmgr/group.h | 1 + progmgr/registry.c | 11 +++-------- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/progmgr/group.c b/progmgr/group.c index 7a689a0..18e9c7e 100644 --- a/progmgr/group.c +++ b/progmgr/group.c @@ -392,6 +392,7 @@ BOOL LoadItems(_In_ HWND hWndGroup) \* * * */ BOOL RemoveItem(_In_ PITEM pi) { + // TODO: implement this // return NULL if we can't get to the group if (pi == NULL) return FALSE; @@ -456,6 +457,40 @@ VOID UpdateGroup(_In_ PGROUP pg) return; } +/* * * *\ + VerifyGroup - + Verifies that a group contains the + correct information about itself. + ABSTRACT - + This function will check the checksum, + verify the number of items, check other + parts of the strucutre. If requested, + it will repair the group if it is damaged. + RETURNS - + TRUE if group appears to be fine + FALSE if the group is damaged +\* * * */ +BOOL VerifyGroup(_In_ PGROUP pg, _In_ BOOL bRepair) +{ + if (pg->dwSignature != GRP_SIGNATURE) + return FALSE; + + // if (pg->wVersion != GRP_VERSION) + // some sort of version difference handling + + if (pg->wChecksum == 1234) + // TODO: calculate checksum function + return FALSE; + + // TODO: use ftlastwrite to throw an error + // if system clock is in the future + + // calculate the size of the group based on item of numbers + + // TODO: change to return a dword error value + return TRUE; +} + /* * * *\ CalculateGroupMemory - Calculates the memory needed by a group. @@ -472,9 +507,7 @@ UINT CalculateGroupMemory(_In_ PGROUP pGroup, _In_ UINT cItems, _In_ BOOL bLean) // first add the size of a group strucutre cbGroupSize += sizeof(GROUP); - // calculate the total amount of items wanted, set - // to 16 if there's less than 16 items so we always - // have some memory ready + // calculate the total amount of items wanted cItemBlock = pGroup->cItemArray + cItems; if (!bLean) diff --git a/progmgr/group.h b/progmgr/group.h index 2915dc0..f95cd47 100644 --- a/progmgr/group.h +++ b/progmgr/group.h @@ -85,6 +85,7 @@ BOOL RemoveItem(_In_ PITEM pi); BOOL ExecuteItem(_In_ PITEM pi); // Save/Load helper functions VOID UpdateGroup(_In_ PGROUP pg); +BOOL VerifyGroup(_In_ PGROUP pg, _In_ BOOL bRepair); // Helper functions UINT CalculateGroupMemory(_In_ PGROUP pGroup, _In_ UINT cItems, _In_ BOOL bLean); // Group Window diff --git a/progmgr/registry.c b/progmgr/registry.c index 02290b1..0670bd7 100644 --- a/progmgr/registry.c +++ b/progmgr/registry.c @@ -129,7 +129,7 @@ DWORD RegistrySaveGroup(_In_ PGROUP pg) // Save group UpdateGroup(pg); if (!RegSetValueEx(hKeyProgramGroups, pg->szName, 0, REG_BINARY, - (const BYTE*)pg, sizeof(*pg)) == ERROR_SUCCESS) + (LPBYTE)pg, CalculateGroupMemory(pg, 0, 1)) == ERROR_SUCCESS) dwConfigStatus = dwConfigStatus && RCE_GROUPS; return dwConfigStatus; @@ -148,8 +148,6 @@ DWORD RegistryLoadGroup(_Inout_ PGROUP pg, _Out_ DWORD dwBufferSize) dwBufferSize = 0; - // TODO: rethink this - // If the pointers are invalid then fail out if (pg == NULL) return RCE_FAILURE; @@ -209,10 +207,7 @@ DWORD SaveConfig(_In_ BOOL bSettings, _In_ BOOL bPos, _In_ BOOL bGroups, _In_ BO { HWND hWndGroup = NULL; - // TODO: Get list of groups, iterate through, - // save each one as an individual subkey based - // on the name of the group - + // Save each group that exists as a window EnumChildWindows(hWndMDIClient, &SaveWindowEnumProc, (LPARAM)bExit); } @@ -348,7 +343,7 @@ DWORD LoadConfig(_In_ BOOL bSettings, _In_ BOOL bPos, _In_ BOOL bGroups) // get the group dwTemp = RegQueryValueEx(hKeyProgramGroups, szValueName, NULL, - &dwType, pGroup, &cbGroup); + &dwType, (LPBYTE)pGroup, &cbGroup); // verify part of the group is valid // TODO: use checksums instead of/alongside signatures