diff --git a/include/Domito.h b/include/Domito.h index 7fab754..0915005 100644 --- a/include/Domito.h +++ b/include/Domito.h @@ -150,3 +150,17 @@ DomitoGetPortableExecutableDigestKind( _In_ PUCHAR pPeBytes, _In_ PIMAGE_DATA_DIRECTORY pImgDataDirectory ); + +// +// Reads from the beginning of a file until the end or the buffer size is reached +// +_Success_(return == STATUS_SUCCESS) +_Must_inspect_result_ +_IRQL_requires_max_(PASSIVE_LEVEL) +EXTERN_C +NTSTATUS +DomitoReadFile( + _In_ HANDLE FileHandle, + _Out_ PVOID Buffer, + _In_ ULONG BufferSize +); diff --git a/src/Domito.cpp b/src/Domito.cpp index 75281ed..ebe4354 100644 --- a/src/Domito.cpp +++ b/src/Domito.cpp @@ -316,3 +316,42 @@ DomitoGetPortableExecutableDigestKind( return CALG_SHA1; } + +_Success_(return == STATUS_SUCCESS) +_Must_inspect_result_ +_IRQL_requires_max_(PASSIVE_LEVEL) +NTSTATUS +DomitoReadFile( + _In_ HANDLE FileHandle, + _Out_ PVOID Buffer, + _In_ ULONG BufferSize +) +{ + NTSTATUS status = STATUS_SUCCESS; + IO_STATUS_BLOCK ioStatusBlock; + + // Read the file into memory using ZwReadFile + if (!NT_SUCCESS(status = ZwReadFile( + FileHandle, + NULL, + NULL, + NULL, + &ioStatusBlock, + Buffer, + BufferSize, + NULL, + NULL + ))) + { + return status; + } + + // Check if the file was read successfully + if (!NT_SUCCESS(ioStatusBlock.Status)) + { + return ioStatusBlock.Status; + } + + // File read successfully + return status; +}