2004-10-21 04:48:46 +00:00
|
|
|
#include <stdio.h>
|
2005-11-12 06:37:36 +00:00
|
|
|
#include <string.h>
|
2005-11-20 18:54:55 +00:00
|
|
|
#define WIN32_NO_STATUS
|
2004-10-21 04:48:46 +00:00
|
|
|
#include <windows.h>
|
2005-11-12 06:37:36 +00:00
|
|
|
#define NTOS_MODE_USER
|
|
|
|
#include <ndk/ntndk.h>
|
2004-10-21 04:48:46 +00:00
|
|
|
|
|
|
|
HANDLE OutputHandle;
|
|
|
|
HANDLE InputHandle;
|
|
|
|
|
2008-11-29 21:37:54 +00:00
|
|
|
VOID WINAPI
|
2004-10-21 04:48:46 +00:00
|
|
|
ApcRoutine(PVOID Context,
|
|
|
|
PIO_STATUS_BLOCK IoStatus,
|
|
|
|
ULONG Reserved)
|
|
|
|
{
|
|
|
|
printf("(apc.exe) ApcRoutine(Context %p)\n", Context);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
HANDLE FileHandle;
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
2005-11-12 06:37:36 +00:00
|
|
|
UNICODE_STRING FileName = RTL_CONSTANT_STRING(L"\\C:\\a.txt");
|
2004-10-21 04:48:46 +00:00
|
|
|
IO_STATUS_BLOCK IoStatus;
|
|
|
|
CHAR Buffer[256];
|
|
|
|
HANDLE EventHandle;
|
|
|
|
LARGE_INTEGER off;
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
AllocConsole();
|
|
|
|
InputHandle = GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
|
|
|
|
printf("APC test program\n");
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
EventHandle = CreateEventW(NULL,
|
|
|
|
FALSE,
|
|
|
|
FALSE,
|
|
|
|
NULL);
|
|
|
|
if (EventHandle == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
printf("Failed to create event\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
printf("Opening file\n");
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&FileName,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
printf("Creating file\n");
|
|
|
|
FileHandle = CreateFileW(L"C:\\a.txt",
|
|
|
|
FILE_GENERIC_READ | FILE_GENERIC_WRITE,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
OPEN_EXISTING,
|
|
|
|
FILE_FLAG_OVERLAPPED,
|
|
|
|
NULL);
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
if (FileHandle == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
|
2015-10-03 22:21:19 +00:00
|
|
|
printf("Open failed last err 0x%lx\n",GetLastError());
|
2004-10-21 04:48:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
off.QuadPart = 0;
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
printf("Reading file\n");
|
|
|
|
Status = ZwReadFile(FileHandle,
|
|
|
|
NULL,
|
|
|
|
(PIO_APC_ROUTINE)ApcRoutine,
|
|
|
|
(PVOID) 0xdeadbeef,
|
|
|
|
&IoStatus,
|
|
|
|
Buffer,
|
|
|
|
256,//len
|
2005-05-07 21:24:31 +00:00
|
|
|
&off ,//offset must exist if file was opened for asynch. i/o aka. OVERLAPPED
|
|
|
|
NULL);
|
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2015-10-03 22:21:19 +00:00
|
|
|
printf("Read failed status 0x%lx\n",Status);
|
2004-10-21 04:48:46 +00:00
|
|
|
}
|
|
|
|
printf("Waiting\n");
|
|
|
|
WaitForSingleObjectEx(EventHandle, INFINITE, TRUE);
|
|
|
|
printf("Returned from wait\n");
|
|
|
|
ZwClose(FileHandle);
|
|
|
|
printf("Program finished\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|