Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct _HARDLINK_INFO
- {
- LPCTSTR FileName;
- _SEARCH_INFO *Parent;
- _SEARCH_INFO *Sibling;
- } HARDLINK_INFO, *PHARDLINK_INFO;
- typedef struct _SEARCH_INFO
- {
- std::list<HARDLINK_INFO> HardLinkInfo;
- FILETIME CreationTime;
- FILETIME LastAccessTime;
- FILETIME LastWriteTime;
- FILETIME ChangeTime;
- ULARGE_INTEGER DataSize;
- ULARGE_INTEGER AllocatedSize;
- ULONG FileAttributes;
- _SEARCH_INFO *Child;
- } SEARCH_INFO, *PSEARCH_INFO;
- VOID
- FetchSearchInfo(
- __inout PDISKHANDLE DiskHandle,
- __in PFILE_RECORD_HEADER FileRecord,
- __out PSEARCH_INFO SearchInfo)
- {
- PATTRIBUTE Attribute = (PATTRIBUTE)((ULONG_PTR)FileRecord + FileRecord->AttributeOffset);
- while (Attribute < (PATTRIBUTE)((ULONG_PTR)FileRecord + FileRecord->BytesInUse) &&
- Attribute->AttributeType != AttributeInvalid)
- {
- if (Attribute->AttributeType == AttributeFileName)
- {
- PFILENAME_ATTRIBUTE FileName =
- (PFILENAME_ATTRIBUTE)((PUCHAR)Attribute + ((PRESIDENT_ATTRIBUTE)Attribute)->ValueOffset);
- if (FileName->NameType == POSIX_NAME || FileName->NameType == WIN32_NAME
- || FileName->NameType == WIN32DOS_NAME)
- {
- #ifndef _UNICODE
- WideCharToMultiByte(CP_ACP, 0, FileName->Name, FileName->NameLength,
- FileName->Name, FileName->NameLength, NULL, NULL);
- #endif
- HARDLINK_INFO HardLinkInfo;
- ZeroMemory(&HardLinkInfo, sizeof(HARDLINK_INFO));
- std::list<HARDLINK_INFO>::iterator Iterator;
- for (Iterator = SearchInfo->HardLinkInfo.begin();
- Iterator != SearchInfo->HardLinkInfo.end();
- ++Iterator)
- {
- if (Iterator->FileName != NULL &&
- RtlEqualMemory(FileName->Name, Iterator->FileName, FileName->NameLength))
- HardLinkInfo.FileName = Iterator->FileName;
- }
- if (HardLinkInfo.FileName == NULL)
- {
- HardLinkInfo.FileName = AllocAndCopyString(DiskHandle->HeapBlock,
- FileName->Name, FileName->NameLength);
- if (HardLinkInfo.FileName == NULL)
- {
- PRINT((TEXT("AllocAndCopyString failed\n")));
- continue;
- }
- }
- HardLinkInfo.Parent = &DiskHandle->SearchInfo[FileName->DirectoryFileReferenceNumber.LowPart];
- SearchInfo->HardLinkInfo.push_back(HardLinkInfo);
- SearchInfo->CreationTime = FileName->CreationTime;
- SearchInfo->LastAccessTime = FileName->LastAccessTime;
- SearchInfo->LastWriteTime = FileName->LastWriteTime;
- SearchInfo->ChangeTime = FileName->ChangeTime;
- SearchInfo->FileAttributes = FileName->FileAttributes;
- if (HardLinkInfo.Parent != SearchInfo)
- {
- PSEARCH_INFO *SiblingSearchInfo = &HardLinkInfo.Parent->Child;
- while(*SiblingSearchInfo != NULL)
- {
- for (Iterator = (*SiblingSearchInfo)->HardLinkInfo.begin();
- Iterator != (*SiblingSearchInfo)->HardLinkInfo.end();
- ++Iterator)
- {
- if (Iterator->Parent = HardLinkInfo.Parent)
- {
- SiblingSearchInfo = &Iterator->Sibling;
- break;
- }
- }
- }
- *SiblingSearchInfo = SearchInfo;
- }
- if (FileRecord->BaseFileRecord.QuadPart != 0)
- {
- PSEARCH_INFO ParentSearchInfo = &DiskHandle->SearchInfo[FileRecord->BaseFileRecord.LowPart];
- CopyMemory(ParentSearchInfo, SearchInfo, sizeof(SEARCH_INFO));
- // We don't need this node when searching files
- for (Iterator = SearchInfo->HardLinkInfo.begin();
- Iterator != SearchInfo->HardLinkInfo.end();
- ++Iterator)
- Iterator->FileName = NULL;
- }
- else
- {
- PRINT((TEXT("MFT: %d, FileName:"), FileRecord->MFTRecordNumber));
- for (Iterator = SearchInfo->HardLinkInfo.begin();
- Iterator != SearchInfo->HardLinkInfo.end();
- ++Iterator)
- PRINT((TEXT(" %s"), Iterator->FileName));
- PRINT((TEXT("\n")));
- DiskHandle->TotalFiles++;
- }
- }
- }
- else if (Attribute->AttributeType == AttributeData)
- {
- SearchInfo->AllocatedSize = ((PNONRESIDENT_ATTRIBUTE)Attribute)->AllocatedSize;
- SearchInfo->DataSize = ((PNONRESIDENT_ATTRIBUTE)Attribute)->DataSize;
- }
- Attribute = (PATTRIBUTE)((ULONG_PTR)Attribute + Attribute->Length);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement