Initial commit
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
#include <include.h>
|
||||
|
||||
BOOL util::read_file_ex(LPCWSTR pszPath, PVOID pBuffer, DWORD uLength)
|
||||
{
|
||||
NTSTATUS status{ };
|
||||
HANDLE handle{ };
|
||||
OBJECT_ATTRIBUTES attribs{ };
|
||||
UNICODE_STRING unicode_path{ };
|
||||
IO_STATUS_BLOCK iosb{ };
|
||||
LARGE_INTEGER byte_offs{ };
|
||||
|
||||
stl::init_unicode_string(&unicode_path, pszPath);
|
||||
|
||||
attribs.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||
attribs.RootDirectory = NULL;
|
||||
attribs.ObjectName = &unicode_path;
|
||||
attribs.Attributes = 0;
|
||||
attribs.SecurityDescriptor = NULL;
|
||||
attribs.SecurityQualityOfService = NULL;
|
||||
|
||||
status = sc_asm_open_file(
|
||||
&handle, FILE_READ_ACCESS | FILE_WRITE_ACCESS | SYNCHRONIZE,
|
||||
&attribs, &iosb, 0,
|
||||
FILE_SYNCHRONOUS_IO_NONALERT
|
||||
);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
return false;
|
||||
|
||||
stl::c_handle_guard _(handle);
|
||||
|
||||
status = sc_asm_read_file(
|
||||
handle, nullptr, nullptr,
|
||||
nullptr, &iosb, pBuffer,
|
||||
uLength, &byte_offs, nullptr
|
||||
);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
PVOID util::get_file_ptr(LPCWSTR pszPath)
|
||||
{
|
||||
if (pszPath && file_exists_wide(pszPath))
|
||||
{
|
||||
SIZE_T uLength = get_file_size_wide(pszPath);
|
||||
PVOID pBuffer{ };
|
||||
|
||||
if (uLength)
|
||||
{
|
||||
pBuffer = stl::mem_alloc<void*>(uLength + 1);
|
||||
|
||||
if (pBuffer == nullptr)
|
||||
return nullptr;
|
||||
|
||||
ZERO_MEM(pBuffer, uLength + 1);
|
||||
|
||||
if (read_file_ex(pszPath, pBuffer, uLength))
|
||||
return pBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
Reference in New Issue
Block a user