Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
delayRemove.c File Reference
#include <windows.h>
#include <stdio.h>

Go to the source code of this file.

Defines

#define MAX_BUF   1024
#define LEN_DELAYED_DELETE_PREFIX   lstrlen("\\??\\")

Functions

void PrintSpecial (char *string, int stringBufSize)
void RemoveDelayedDeleteFileEntries (const char *aPathToMatch)
int main (argc, argv)

Define Documentation

#define LEN_DELAYED_DELETE_PREFIX   lstrlen("\\??\\")

Definition at line 5 of file delayRemove.c.

#define MAX_BUF   1024

Definition at line 4 of file delayRemove.c.


Function Documentation

int main ( argc  ,
argv   
)

Definition at line 222 of file delayRemove.c.

{
    char buf[MAX_BUF];
    DWORD bufSize = sizeof(buf);

//    MoveFileEx("c:\\windows\\system32\\mapistubs.dll", NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
    MoveFileEx("c:\\program files\\aol communicator\\phidlemon.dll", NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
//    MoveFileEx("c:\\windows\\system32\\mapistubs.dll", NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
    MoveFileEx("c:\\prOGRAM fILES\\aol COMMUNicator\\phidlemon.dll", NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
//    MoveFileEx("c:\\windows\\system32\\mapistubs.dll", NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
    MoveFileEx("srcfiletoremane.txt", "dstfilerenamed.txt", MOVEFILE_DELAY_UNTIL_REBOOT);

//    MoveFileEx("c:\\windows\\system32\\mapistubs.dll", NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
    MoveFileEx("c:\\program files\\aol communicator\\phidlemon.dll", NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
//    MoveFileEx("c:\\windows\\system32\\mapistubs.dll", NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
    MoveFileEx("c:\\program files\\aol communicator\\phidlemon.dll", NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
//    MoveFileEx("c:\\windows\\system32\\mapistubs.dll", NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
    MoveFileEx("srcfiletorename.txt", "dstfilerenamed.txt", MOVEFILE_DELAY_UNTIL_REBOOT);

    RemoveDelayedDeleteFileEntries("C:\\Program Files\\AOL Communicator\\");
}

Here is the call graph for this function:

void PrintSpecial ( char *  string,
int  stringBufSize 
)

Definition at line 9 of file delayRemove.c.

{
  int i;
  int nullCount = 0;

  printf("\nlength: %d\n", stringBufSize);
  for(i = 0; i < stringBufSize; i++)
  {
    if(string[i] == '\0')
    {
      printf("{null}");
      nullCount++;
    }
    else
      printf("%c", string[i]);
  }
}

Here is the caller graph for this function:

void RemoveDelayedDeleteFileEntries ( const char *  aPathToMatch)

Definition at line 27 of file delayRemove.c.

{
  HKEY  hkResult;
  DWORD dwErr;
  DWORD dwType = REG_NONE;
  DWORD oldMaxValueLen = 0;
  DWORD newMaxValueLen = 0;
  DWORD lenToEnd = 0;
  char  *multiStr = NULL;
  const char key[] = "SYSTEM\\CurrentControlSet\\Control\\Session Manager";
  const char name[] = "PendingFileRenameOperations";
  char  *pathToMatch;
  char  *lcName;
  char  *pName;
  char  *pRename;
  int   nameLen, renameLen;

  if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, key, 0, KEY_READ|KEY_WRITE, &hkResult) != ERROR_SUCCESS)
    return;

  dwErr = RegQueryValueEx(hkResult, name, 0, &dwType, NULL, &oldMaxValueLen);
  if (dwErr != ERROR_SUCCESS || oldMaxValueLen == 0 || dwType != REG_MULTI_SZ)
  {
    /* no value, no data, or wrong type */
    return;
  }

  multiStr = calloc(oldMaxValueLen, sizeof(BYTE));
  if (!multiStr)
    return;

  pathToMatch = strdup(aPathToMatch);
  if (!pathToMatch)
  {
      free(multiStr);
      return;
  }

  if (RegQueryValueEx(hkResult, name, 0, NULL, multiStr, &oldMaxValueLen) == ERROR_SUCCESS)
  {
       PrintSpecial(multiStr, oldMaxValueLen);
      // The registry value consists of name/newname pairs of null-terminated
      // strings, with a final extra null termination. We're only interested
      // in files to be deleted, which are indicated by a null newname.
      _mbslwr(pathToMatch);
      lenToEnd = newMaxValueLen = oldMaxValueLen;
      pName = multiStr;
      while(*pName && lenToEnd > 0)
      {
          // find the locations and lengths of the current pair. Count the
          // nulls,  we need to know how much data to skip or move
          nameLen = strlen(pName) + 1;
          pRename = pName + nameLen;
          renameLen = strlen(pRename) + 1;

          // How much remains beyond the current pair
          lenToEnd -= (nameLen + renameLen);

          if (*pRename == '\0')
          {
              // No new name, it's a delete. Is it the one we want?
              lcName = strdup(pName);
              if (lcName)
              {
                _mbslwr(lcName);
                if (strstr(lcName, pathToMatch))
                {
                  // It's a match--
                  // delete this pair by moving the remainder on top
                  memmove(pName, pRename + renameLen, lenToEnd);

                  // update the total length to reflect the missing pair
                  newMaxValueLen -= (nameLen + renameLen);

                  // next pair is in place, continue w/out moving pName
                  continue;
                }
              }
          }
          // on to the next pair
          pName = pRename + renameLen;
      }

      if (newMaxValueLen != oldMaxValueLen)
      {
          PrintSpecial(multiStr, newMaxValueLen);
          // We've deleted something, save the changed data
          RegSetValueEx(hkResult, name, 0, REG_MULTI_SZ, multiStr, newMaxValueLen);
          RegFlushKey(hkResult);
      }
  }

  RegCloseKey(hkResult);
  free(multiStr);
}

Here is the call graph for this function: