LexVel
Platinum Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору /*++ Routine Description: Print buffer content in hex format into string Arguments: outStr - ptr to output string buffer buf - ptr to buffer length - length of buffer Return Value: none --*/ PWCHAR tmpBuf; LONG i; // Check parameters if (!buf) { swprintf(outStr, L"NULL (ptr to data)"); return; } if (length<=0) { swprintf(outStr, L"NULL (length)"); return; } // Create string outStr[0]=0; outStr[1]=0; outStr[2]=0; outStr[3]=0; tmpBuf = ExAllocatePoolWithTag (PagedPool, 512, VUSB_POOL_TAG); if (!tmpBuf) return; for (i=0; i<length ; i++) { swprintf(tmpBuf, L"%02X ", (ULONG) ((UCHAR *)buf)); wcscat(outStr, tmpBuf); } ExFreePool(tmpBuf); } NTSTATUS LogMessage(PCHAR szFormat, ...) { /*++ [i]Routine Description: Log msg into debug console and file Arguments: szFormat - message format string ... - data Return Value: NT status code --*/ ULONG Length; char messagebuf[1024]; va_list va; IO_STATUS_BLOCK IoStatus; OBJECT_ATTRIBUTES objectAttributes; NTSTATUS status; HANDLE FileHandle; UNICODE_STRING fileName; //format the string va_start(va,szFormat); _vsnprintf(messagebuf,sizeof(messagebuf),szFormat,va); va_end(va); //get a handle to the log file object fileName.Buffer = NULL; fileName.Length = 0; fileName.MaximumLength = sizeof(DEFAULT_LOG_FILE_NAME) + sizeof(UNICODE_NULL); fileName.Buffer = ExAllocatePool(PagedPool, fileName.MaximumLength); if (!fileName.Buffer) { DbgPrint ("LogMessageInFile: FAIL. ExAllocatePool Failed.\n"); return FALSE; } RtlZeroMemory(fileName.Buffer, fileName.MaximumLength); status = RtlAppendUnicodeToString(&fileName, (PWSTR)DEFAULT_LOG_FILE_NAME); InitializeObjectAttributes (&objectAttributes, (PUNICODE_STRING)&fileName, OBJ_CASE_INSENSITIVE, NULL, NULL ); status = ZwCreateFile( &FileHandle, FILE_APPEND_DATA, &objectAttributes, &IoStatus, 0, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_WRITE, FILE_OPEN_IF, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0 ); if( NT_SUCCESS(status) ) { CHAR buf[1024]; sprintf(buf,"%s",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; } DbgPrint("%s", buf); ZwWriteFile( FileHandle, NULL, NULL, NULL, &IoStatus, buf, Length, NULL, NULL ); ZwClose( FileHandle ); } if( fileName.Buffer ) { ExFreePool (fileName.Buffer); } return STATUS_SUCCESS; } #endif | Всего записей: 10074 | Зарегистр. 24-04-2007 | Отправлено: 17:11 18-03-2012 | Исправлено: LexVel, 17:32 18-03-2012 |
|