bool PathReadWriter::RemoveFromPath(const CStdString& sSubPath) { if (!DoesPathExist(sSubPath)) return true; return RemovePathFromRegistry(sSubPath); }
bool PathReadWriter::AppendToPath(const CStdString& sSubPath) { if (!CGeneral::DirectoryExists(sSubPath)) return false; if (DoesPathExist(sSubPath)) return true; return AppendToPathInRegistry(sSubPath); }
NTSTATUS SetupCreateDirectory( PWCHAR PathName) { PWCHAR PathBuffer = NULL; PWCHAR Ptr, EndPtr; ULONG BackslashCount; ULONG Size; NTSTATUS Status = STATUS_SUCCESS; Size = (wcslen(PathName) + 1) * sizeof(WCHAR); PathBuffer = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, Size); if (PathBuffer == NULL) return STATUS_INSUFFICIENT_RESOURCES; wcscpy(PathBuffer, PathName); EndPtr = PathBuffer + wcslen(PathName); Ptr = PathBuffer; /* Skip the '\Device\HarddiskX\PartitionY\ part */ BackslashCount = 0; while (Ptr < EndPtr && BackslashCount < 4) { if (*Ptr == L'\\') BackslashCount++; Ptr++; } while (Ptr < EndPtr) { if (*Ptr == L'\\') { *Ptr = 0; DPRINT("PathBuffer: %S\n", PathBuffer); if (!DoesPathExist(PathBuffer)) { DPRINT("Create: %S\n", PathBuffer); Status = SetupCreateSingleDirectory(PathBuffer); if (!NT_SUCCESS(Status)) goto done; } *Ptr = L'\\'; } Ptr++; } if (!DoesPathExist(PathBuffer)) { DPRINT("Create: %S\n", PathBuffer); Status = SetupCreateSingleDirectory(PathBuffer); if (!NT_SUCCESS(Status)) goto done; } done: DPRINT("Done.\n"); if (PathBuffer != NULL) RtlFreeHeap(RtlGetProcessHeap(), 0, PathBuffer); return Status; }
// // TODO: Instead of returning TRUE/FALSE, it would be nice to return // a flag indicating: // - whether the installation is actually valid; // - if it's broken or not (aka. needs for repair, or just upgrading). // static BOOLEAN IsValidNTOSInstallationByHandle( IN HANDLE SystemRootDirectory) { BOOLEAN Success = FALSE; PCWSTR PathName; USHORT i; UNICODE_STRING VendorName; WCHAR VendorNameBuffer[MAX_PATH]; /* Check for the existence of \SystemRoot\System32 */ PathName = L"System32\\"; if (!DoesPathExist(SystemRootDirectory, PathName)) { // DPRINT1("Failed to open directory '%S', Status 0x%08lx\n", PathName, Status); return FALSE; } /* Check for the existence of \SystemRoot\System32\drivers */ PathName = L"System32\\drivers\\"; if (!DoesPathExist(SystemRootDirectory, PathName)) { // DPRINT1("Failed to open directory '%S', Status 0x%08lx\n", PathName, Status); return FALSE; } /* Check for the existence of \SystemRoot\System32\config */ PathName = L"System32\\config\\"; if (!DoesPathExist(SystemRootDirectory, PathName)) { // DPRINT1("Failed to open directory '%S', Status 0x%08lx\n", PathName, Status); return FALSE; } #if 0 /* * Check for the existence of SYSTEM and SOFTWARE hives in \SystemRoot\System32\config * (but we don't check here whether they are actually valid). */ PathName = L"System32\\config\\SYSTEM"; if (!DoesFileExist(SystemRootDirectory, PathName)) { // DPRINT1("Failed to open file '%S', Status 0x%08lx\n", PathName, Status); return FALSE; } PathName = L"System32\\config\\SOFTWARE"; if (!DoesFileExist(SystemRootDirectory, PathName)) { // DPRINT1("Failed to open file '%S', Status 0x%08lx\n", PathName, Status); return FALSE; } #endif RtlInitEmptyUnicodeString(&VendorName, VendorNameBuffer, sizeof(VendorNameBuffer)); /* Check for the existence of \SystemRoot\System32\ntoskrnl.exe and retrieves its vendor name */ PathName = L"System32\\ntoskrnl.exe"; Success = CheckForValidPEAndVendor(SystemRootDirectory, PathName, &VendorName); if (!Success) DPRINT1("Kernel executable '%S' is either not a PE file, or does not have any vendor?\n", PathName); /* The kernel gives the OS its flavour */ if (Success) { for (i = 0; i < ARRAYSIZE(KnownVendors); ++i) { Success = !!FindSubStrI(VendorName.Buffer, KnownVendors[i]); if (Success) { /* We have found a correct vendor combination */ DPRINT1("IsValidNTOSInstallation: We've got an NTOS installation from %S !\n", KnownVendors[i]); break; } } } /* OPTIONAL: Check for the existence of \SystemRoot\System32\ntkrnlpa.exe */ /* Check for the existence of \SystemRoot\System32\ntdll.dll and retrieves its vendor name */ PathName = L"System32\\ntdll.dll"; Success = CheckForValidPEAndVendor(SystemRootDirectory, PathName, &VendorName); if (!Success) DPRINT1("User-mode DLL '%S' is either not a PE file, or does not have any vendor?\n", PathName); if (Success) { for (i = 0; i < ARRAYSIZE(KnownVendors); ++i) { if (!!FindSubStrI(VendorName.Buffer, KnownVendors[i])) { /* We have found a correct vendor combination */ DPRINT1("IsValidNTOSInstallation: The user-mode DLL '%S' is from %S\n", PathName, KnownVendors[i]); break; } } } return Success; }