MCPcopy Create free account
hub / github.com/bailey27/cppcryptfs / DOKAN_CALLBACK CryptReadFile

Function DOKAN_CALLBACK CryptReadFile

cppcryptfs/dokan/cryptdokan.cpp:791–866  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

789}
790
791static NTSTATUS DOKAN_CALLBACK CryptReadFile(LPCWSTR FileName, LPVOID Buffer,
792 DWORD BufferLength,
793 LPDWORD ReadLength,
794 LONGLONG Offset,
795 PDOKAN_FILE_INFO DokanFileInfo) {
796 FileNameEnc filePath(DokanFileInfo, FileName);
797 HANDLE handle = (HANDLE)DokanFileInfo->Context;
798 BOOL opened = FALSE;
799 NTSTATUS ret_status = STATUS_SUCCESS;
800
801 DbgPrint(L"ReadFile : %s, %I64u, paging io = %u\n", FileName,
802 (ULONGLONG)handle, DokanFileInfo->PagingIo);
803 DbgPrint(L"ReadFile : attempting to read %u bytes from offset %ld\n",
804 BufferLength, Offset);
805
806 bool is_virtual = rt_is_virtual_file(GetContext(), FileName);
807
808 if (!handle || (!is_virtual && handle == INVALID_HANDLE_VALUE)) {
809 DbgPrint(L"\tinvalid handle, cleanuped?\n");
810 handle = CreateFile(filePath, GENERIC_READ, FILE_SHARE_READ, NULL,
811 OPEN_EXISTING, 0, NULL);
812 if (handle == INVALID_HANDLE_VALUE) {
813 DWORD error = GetLastError();
814 DbgPrint(L"\tCreateFile error : %d\n\n", error);
815 return ToNtStatus(error);
816 }
817
818 GetContext()->m_openfiles.OpenFile(FileName, handle);
819 opened = TRUE;
820 }
821
822 CryptFile *file = CryptFile::NewInstance(GetContext());
823
824 if (rt_is_config_file(GetContext(), FileName)) {
825 OVERLAPPED ov;
826 SetOverlapped(&ov, Offset);
827
828 if (!ReadFile(handle, Buffer, BufferLength, ReadLength, &ov)) {
829 ret_status = ToNtStatus(GetLastError());
830 }
831
832 } else if (is_virtual) {
833 if (!read_virtual_file(GetContext(), FileName, (unsigned char *)Buffer,
834 BufferLength, ReadLength, Offset)) {
835 DWORD error = GetLastError();
836 if (error == 0)
837 error = ERROR_ACCESS_DENIED;
838 DbgPrint(L"\tread error = %u, buffer length = %d, read length = %d\n\n",
839 error, BufferLength, *ReadLength);
840 ret_status = ToNtStatus(error);
841 }
842 } else if (file->Associate(GetContext(), handle, FileName, false)) {
843
844 if (!file->Read((unsigned char *)Buffer, BufferLength, ReadLength,
845 Offset)) {
846 DWORD error = GetLastError();
847 DbgPrint(L"\tread error = %u, buffer length = %d, read length = %d\n\n",
848 error, BufferLength, *ReadLength);

Callers

nothing calls this directly

Calls 10

DbgPrintFunction · 0.85
rt_is_virtual_fileFunction · 0.85
ToNtStatusFunction · 0.85
rt_is_config_fileFunction · 0.85
SetOverlappedFunction · 0.85
read_virtual_fileFunction · 0.85
OpenFileMethod · 0.80
AssociateMethod · 0.80
ReadMethod · 0.80
CloseFileMethod · 0.80

Tested by

no test coverage detected