Advertisement
captmicro

Leet hax for kernel mode debug redirection

Jan 4th, 2013
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #define DbgPrint WriteLog //IN ALL HEADERS AFTER INCLUDING DDK HEADERS
  2.  
  3. void WriteLog(char *fmt, ...)
  4. {
  5. va_list arglist;
  6. va_start(arglist, fmt);
  7. char *buffer = (char*)ExAllocatePool(NonPagedPool, 4096);
  8. memset(buffer, 0 , 4096);
  9. RtlStringCbVPrintfA(buffer, 4096, fmt, arglist);
  10. ULONG buflen = 0;
  11. RtlStringCbLengthA(buffer, 4096, (size_t*)&buflen);
  12.  
  13. DbgPrintEx(DPFLTR_IHVDRIVER_ID, 0, buffer);
  14.  
  15. if (buflen > 0)
  16. {
  17. /*setup log file*/
  18. UNICODE_STRING logName;
  19. OBJECT_ATTRIBUTES objAttribs;
  20. NTSTATUS status;
  21. HANDLE hFile;
  22. IO_STATUS_BLOCK ioStatus;
  23. RtlInitUnicodeString(&logName, L"\\DosDevices\\C:\\roothop.log");
  24. InitializeObjectAttributes(&objAttribs, &logName,
  25. OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
  26. NULL, NULL);
  27. if(KeGetCurrentIrql() != PASSIVE_LEVEL) goto _exitlogwrite;
  28. status = ZwCreateFile(&hFile, FILE_APPEND_DATA,
  29. &objAttribs, &ioStatus, NULL, FILE_ATTRIBUTE_NORMAL, 0,
  30. FILE_OPEN_IF, FILE_NON_DIRECTORY_FILE | FILE_RANDOM_ACCESS |
  31. FILE_NO_INTERMEDIATE_BUFFERING | FILE_SYNCHRONOUS_IO_NONALERT,
  32. NULL, 0);
  33. if (!NT_SUCCESS(status)) {
  34. DbgPrint("Failed to create log file\n");
  35. goto _exitlogwrite;
  36. }
  37. /*write log file*/
  38. ZwWriteFile(hFile, 0, 0, 0,
  39. &ioStatus, buffer, buflen, 0, 0);
  40. /*close log file*/
  41. ZwClose(hFile);
  42. }
  43.  
  44. _exitlogwrite:;
  45. ExFreePool(buffer);
  46. va_end(arglist);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement