Skip to content

Commit

Permalink
return STATUS_NOT_SUPPORTED if overlapped IO is requested
Browse files Browse the repository at this point in the history
  • Loading branch information
stevefan1999-personal authored and mingkuang-Chuyu committed Oct 22, 2024
1 parent fc14c4b commit 4681d56
Showing 1 changed file with 26 additions and 33 deletions.
59 changes: 26 additions & 33 deletions src/Thunks/ntdll.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,37 @@ namespace YY::Thunks
{
return _pfnNtCancelIoFileEx(handle, io, io_status);
}

auto currentTid = GetCurrentThreadId();
auto currentPid = GetCurrentProcessId();
HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, GetCurrentProcessId());
if (h != INVALID_HANDLE_VALUE)

if (io != nullptr)
{
THREADENTRY32 te;
te.dwSize = sizeof(te);
if (Thread32First(h, &te))
// Not supported
return STATUS_NOT_SUPPORTED;
}

internal::StringBuffer<char> _Buffer;
auto _pProcessInfo = internal::GetCurrentProcessInfo(_Buffer);
if (_pProcessInfo)
{
const auto _uCurrentThreadId = GetCurrentThreadId();

for (ULONG i = 0; i != _pProcessInfo->ThreadCount; ++i)
{
do
auto& _Thread = _pProcessInfo->Threads[i];

if (_uCurrentThreadId == static_cast<DWORD>(reinterpret_cast<UINT_PTR>(_Thread.ClientId.UniqueThread)))
continue;

auto _hThread = OpenThread(THREAD_SET_CONTEXT, FALSE, static_cast<DWORD>(reinterpret_cast<UINT_PTR>(_Thread.ClientId.UniqueThread)));
if (!_hThread)
{
if (te.th32ThreadID == currentTid || te.th32OwnerProcessID != currentPid)
{
continue;
}
HANDLE threadHandle = OpenThread(THREAD_SET_CONTEXT, FALSE, te.th32ThreadID);
if (threadHandle != INVALID_HANDLE_VALUE)
{
QueueUserAPC([](ULONG_PTR param) {
#ifndef __USING_NTDLL_LIB
const auto NtCancelIoFile = try_get_NtCancelIoFile();
if (!NtCancelIoFile)
{
// 正常来说不应该走到这里
return;
}
#endif
IO_STATUS_BLOCK dummy;
NtCancelIoFile((HANDLE)param, &dummy);
}, threadHandle, (ULONG_PTR)handle);
CloseHandle(threadHandle);
}
} while (Thread32Next(h, &te));
continue;
}

QueueUserAPC((PAPCFUNC)CancelIo, _hThread, (ULONG_PTR)handle);
CloseHandle(_hThread);
}
CloseHandle(h);
}

#ifndef __USING_NTDLL_LIB
const auto NtCancelIoFile = try_get_NtCancelIoFile();
if (!NtCancelIoFile)
Expand Down

0 comments on commit 4681d56

Please sign in to comment.