summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYonit Halperin <yhalperi@redhat.com>2013-05-13 15:33:44 -0400
committerYonit Halperin <yhalperi@redhat.com>2013-05-13 15:34:35 -0400
commita4ddf412b83dfc70e829b0e83423b3dbc0b50c66 (patch)
treec879cc237ca2f4b6557df0f18ca1d3dce2ec1ef1
parentec38969558b171a10851eec76d208a6a8222928e (diff)
Log file
I think it can only be called from Passive level TODO: replace with standard debug and error
-rw-r--r--C++/bdd.hxx3
-rw-r--r--C++/bdd_ddi.cxx87
2 files changed, 89 insertions, 1 deletions
diff --git a/C++/bdd.hxx b/C++/bdd.hxx
index 3c98664..c74c58b 100644
--- a/C++/bdd.hxx
+++ b/C++/bdd.hxx
@@ -400,6 +400,9 @@ VOID BltBits(
UINT NumRects,
_In_reads_(NumRects) CONST RECT *pRects);
+VOID CreateLog(VOID);
+VOID CloseLog(VOID);
+VOID LogMessage(PCHAR szFormat, ...);
//
// Driver Entry point
//
diff --git a/C++/bdd_ddi.cxx b/C++/bdd_ddi.cxx
index 544ba22..680fe0c 100644
--- a/C++/bdd_ddi.cxx
+++ b/C++/bdd_ddi.cxx
@@ -9,7 +9,7 @@
#include "BDD.hxx"
-
+#include <stdarg.h>
#pragma code_seg(push)
#pragma code_seg("INIT")
// BEGIN: Init Code
@@ -76,6 +76,91 @@ DriverEntry(
#pragma code_seg(push)
#pragma code_seg("PAGE")
+#define LOG_FILE_NAME L"\\DosDevices\\C:\\WINDOWS\\Temp\\kmdod_sample.log"
+HANDLE hLogFile = NULL;
+
+VOID CreateLog(VOID)
+{
+ if (hLogFile == NULL) {
+ OBJECT_ATTRIBUTES LogFileAttr;
+ UNICODE_STRING LogFileString;
+ IO_STATUS_BLOCK IoStatus;
+
+ RtlInitUnicodeString(&LogFileString, LOG_FILE_NAME);
+ InitializeObjectAttributes(&LogFileAttr, &LogFileString, OBJ_CASE_INSENSITIVE, NULL, NULL);
+ ZwCreateFile(&hLogFile, FILE_APPEND_DATA, &LogFileAttr, &IoStatus, NULL, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_WRITE,
+ FILE_OPEN_IF, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
+
+ }
+}
+
+VOID CloseLog(VOID)
+{
+ if (hLogFile) {
+ ZwClose(hLogFile);
+ hLogFile = NULL;
+ }
+}
+
+// we don't have the actual height and width of the bitmap, so deduce the min from the dirty- and move- rects.
+// Maybe the source is always the same as the frame buffer???
+/*VOID CreateBitmapFile(VOID *pSrc, ULONG BytesPerPixel, LONG Pitch, LONG MinWidth, LONG MinHeight)
+{
+}*/
+
+VOID LogMessage(PCHAR szFormat, ...)
+{
+ ULONG Length;
+ char messagebuf[512];
+ va_list va;
+ IO_STATUS_BLOCK IoStatus;
+ NTSTATUS status;
+ CHAR buf[300];
+ LARGE_INTEGER time;
+
+ CreateLog();
+ if (!hLogFile) {
+ return;
+ }
+ //format the string
+ va_start(va,szFormat);
+ vsprintf(messagebuf,szFormat,va);
+ va_end(va);
+
+ KeQuerySystemTime(&time);
+
+ //put a time stamp on the output message
+ sprintf(buf,"%10u-%10u %s",time.HighPart,time.LowPart,messagebuf);
+
+ //format the string to make sure it appends a newline carrage-return to the
+ //end of the string.
+ Length=strlen(buf);
+ if(buf[Length-1]=='\n')
+ {
+ buf[Length-1]='\r';
+ strcat(buf,"\n");
+ Length++;
+ }
+ else
+ {
+ strcat(buf,"\r\n");
+ Length+=2;
+ }
+
+ buf[Length+1] = '\0';
+
+ status = ZwWriteFile(hLogFile,
+ NULL,
+ NULL,
+ NULL,
+ &IoStatus,
+ buf,
+ Length,
+ NULL,
+ NULL );
+ CloseLog();
+}
+
//
// PnP DDIs
//