开发驱动时用到的内核打印函数KdPrint 的使用方法
2017-01-09 14:21
651 查看
转载自: http://blog.csdn.net/wjcsharp/article/details/6161712
DbgPrint会发送一个消息给内核调试器。
DbgPrint and DbgPrintEx can be called at IRQL<=DIRQL. However, Unicode format codes (%wc and %ws) can be used only at IRQL PASSIVE_LEVEL. Also, because the debugger uses interprocess
interrupts (IPIs) to communicate with other processors, callingDbgPrint at IRQL>DIRQL can cause deadlocks.
仅能在内核模式下使用DbgPrint函数。如果想在用户模式下使用打印到windbg上查看,得用OutPutDebugString。
In Windows Vista and later versions of Windows, DbgPrint sends a message only if certain conditions apply. Specifically, it behaves like theDbgPrintEx routine
with the DEFAULT component and a message importance level of DPFLTR_INFO_LEVEL. In other words, the following two function calls are identical:
KdPrint使用方法类似printf,注意KdPrint((" ", ));使用的是双括号。
用KdPrint(())来代替printf 输出信息。这些信息可以在DbgView 中看到。KdPrint(())自身是一个宏,
为了完整传入参数所以使用了两重括弧。这个比DbgPrint 调用要稍好。因为在free 版不被编译。
DebugPrint格式说明符
二、
几天一直在做那些无聊的实验,把驱动的学习耽误到现在。幸好,把那些无聊的实验写完。
话说回来,驱动编程真的比在RING3下麻烦很多呢,在字符串的使用都需要做很多的初始化,搞到我头都大了,如果是用C就很好理解,但是我用的是汇编~~~。今天,就看了看关于DbgPrint的用法,顺便做点笔记。
DbgPrintf,是输出Debug信息的,用法跟printf,sprintf,wsprintf类似。
[cpp] view
plain copy
ULONG
DbgPrint(
IN PCHAR Format,
. . . . [arguments]
);
1、直接输出字符串,输出的字符串是以NULL结尾的字符串(CHAR类型),如:
[cpp] view
plain copy
invoke DbgPrint,$CTA0("the Driver has loaded.")
2、指定格式输出字符串,输出得字符串可以是以NULL结尾的ASNI字符串,也可以是宽字符串(WCHAR类型),如:
[cpp] view
plain copy
invoke DbgPrint,$CTA0("%s"),$CTA0("The Driver has Unloaded.") ;输出ASNI字符串
invoke DbgPrint,$CTA0("%ws"),$CTW0("The Driver has Unloaded.") ;输出wchar类型字符串
invoke DbgPrint,$CTA0("%S"),$CTW0("The Driver has Unloaded.") ;输出wchar类型字符串(注意是大写的S)
3、UNICODE_STRING结构的串的输出,如:
[cpp] view
plain copy
ucstShow UNICODE_STRING <?> ;定义一个UNICODE_STRING的结构
invoke RtlInitUnicodeString,addr ucstShow,$CTW0("This is the fifth debug Information.") ;初始化
invoke DbgPrint,$CTA0("%wZ"),addr ucstShow
4、混合拼接信息输出,如:
[cpp] view
plain copy
invoke RtlInitUnicodeString,addr ucstShow,$CTW0("hello,I was born in")
invoke DbgPrint,$CTA0("%wZ %x"),addr ucstShow,dwShow
实际上就是printf,sprintf,wsprintf的用法,很简单~~
还有很多输出方式,如下表(网上找的):
以下是随便写的测试代码:
[plain] view
plain copy
;/**
; *************************************************************************
; * 文件名称: Driver.asm
; * 版 本:
; * 描 述: 学习DbgPrint的用法
; * 作 者: zzydog
; * 创建日期: 2010
; *************************************************************************
; */
.386
.model flat, stdcall
option casemap:none
include Strings.mac
include w2k\ntstatus.inc
include w2k\ntddk.inc
include w2k\ntoskrnl.inc
includelib ntoskrnl.lib
includelib ntdll.lib
;************************************************************************************
;函数定义
DriverEntry proto pDriverObject:PDRIVER_OBJECT,pusRegistryPath:PUNICODE_STRING
DirverUnload proto pDriverObject:PDRIVER_OBJECT
;************************************************************************************
.data
ucstShow UNICODE_STRING <?>
szShowLoad db "The Dirver has been loaded!",NULL
szShowUnLoad db "The Driver has been Unloaded!",NULL
dwShow dd 1990h
.code
DriverEntry proc pDriverObject:PDRIVER_OBJECT,pusRegistryPath:PUNICODE_STRING
invoke DbgPrint,addr szShowLoad
invoke DbgPrint,$CTA0("This is the first debug Information.")
invoke DbgPrint,$CTA0("%s"),$CTA0("This is the second debug Information.")
invoke DbgPrint,$CTA0("%ws"),$CTW0("This is the third debug Information.")
invoke DbgPrint,$CTA0("%S"),$CTW0("This is the forth debug Information.")
invoke RtlInitUnicodeString,addr ucstShow,$CTW0("This is the fifth debug Information.")
invoke DbgPrint,$CTA0("%wZ"),addr ucstShow
invoke RtlInitUnicodeString,addr ucstShow,$CTW0("hello,I was born in")
invoke DbgPrint,$CTA0("%wZ %x"),addr ucstShow,dwShow
assume edx:ptr DRIVER_OBJECT
mov edx,[pDriverObject]
mov [edx].DriverUnload,offset DriverUnload
mov eax,STATUS_SUCCESS
ret
DriverEntry endp
DriverUnload proc pDriverObject:PDRIVER_OBJECT
invoke DbgPrint,$CTA0("%s"),addr szShowUnLoad
mov eax,STATUS_SUCCESS
ret
DriverUnload endp
end DriverEntry
DbgPrint会发送一个消息给内核调试器。
DbgPrint and DbgPrintEx can be called at IRQL<=DIRQL. However, Unicode format codes (%wc and %ws) can be used only at IRQL PASSIVE_LEVEL. Also, because the debugger uses interprocess
interrupts (IPIs) to communicate with other processors, callingDbgPrint at IRQL>DIRQL can cause deadlocks.
仅能在内核模式下使用DbgPrint函数。如果想在用户模式下使用打印到windbg上查看,得用OutPutDebugString。
In Windows Vista and later versions of Windows, DbgPrint sends a message only if certain conditions apply. Specifically, it behaves like theDbgPrintEx routine
with the DEFAULT component and a message importance level of DPFLTR_INFO_LEVEL. In other words, the following two function calls are identical:
KdPrint使用方法类似printf,注意KdPrint((" ", ));使用的是双括号。
用KdPrint(())来代替printf 输出信息。这些信息可以在DbgView 中看到。KdPrint(())自身是一个宏,
为了完整传入参数所以使用了两重括弧。这个比DbgPrint 调用要稍好。因为在free 版不被编译。
DebugPrint格式说明符
二、
几天一直在做那些无聊的实验,把驱动的学习耽误到现在。幸好,把那些无聊的实验写完。
话说回来,驱动编程真的比在RING3下麻烦很多呢,在字符串的使用都需要做很多的初始化,搞到我头都大了,如果是用C就很好理解,但是我用的是汇编~~~。今天,就看了看关于DbgPrint的用法,顺便做点笔记。
DbgPrintf,是输出Debug信息的,用法跟printf,sprintf,wsprintf类似。
[cpp] view
plain copy
ULONG
DbgPrint(
IN PCHAR Format,
. . . . [arguments]
);
1、直接输出字符串,输出的字符串是以NULL结尾的字符串(CHAR类型),如:
[cpp] view
plain copy
invoke DbgPrint,$CTA0("the Driver has loaded.")
2、指定格式输出字符串,输出得字符串可以是以NULL结尾的ASNI字符串,也可以是宽字符串(WCHAR类型),如:
[cpp] view
plain copy
invoke DbgPrint,$CTA0("%s"),$CTA0("The Driver has Unloaded.") ;输出ASNI字符串
invoke DbgPrint,$CTA0("%ws"),$CTW0("The Driver has Unloaded.") ;输出wchar类型字符串
invoke DbgPrint,$CTA0("%S"),$CTW0("The Driver has Unloaded.") ;输出wchar类型字符串(注意是大写的S)
3、UNICODE_STRING结构的串的输出,如:
[cpp] view
plain copy
ucstShow UNICODE_STRING <?> ;定义一个UNICODE_STRING的结构
invoke RtlInitUnicodeString,addr ucstShow,$CTW0("This is the fifth debug Information.") ;初始化
invoke DbgPrint,$CTA0("%wZ"),addr ucstShow
4、混合拼接信息输出,如:
[cpp] view
plain copy
invoke RtlInitUnicodeString,addr ucstShow,$CTW0("hello,I was born in")
invoke DbgPrint,$CTA0("%wZ %x"),addr ucstShow,dwShow
实际上就是printf,sprintf,wsprintf的用法,很简单~~
还有很多输出方式,如下表(网上找的):
以下是随便写的测试代码:
[plain] view
plain copy
;/**
; *************************************************************************
; * 文件名称: Driver.asm
; * 版 本:
; * 描 述: 学习DbgPrint的用法
; * 作 者: zzydog
; * 创建日期: 2010
; *************************************************************************
; */
.386
.model flat, stdcall
option casemap:none
include Strings.mac
include w2k\ntstatus.inc
include w2k\ntddk.inc
include w2k\ntoskrnl.inc
includelib ntoskrnl.lib
includelib ntdll.lib
;************************************************************************************
;函数定义
DriverEntry proto pDriverObject:PDRIVER_OBJECT,pusRegistryPath:PUNICODE_STRING
DirverUnload proto pDriverObject:PDRIVER_OBJECT
;************************************************************************************
.data
ucstShow UNICODE_STRING <?>
szShowLoad db "The Dirver has been loaded!",NULL
szShowUnLoad db "The Driver has been Unloaded!",NULL
dwShow dd 1990h
.code
DriverEntry proc pDriverObject:PDRIVER_OBJECT,pusRegistryPath:PUNICODE_STRING
invoke DbgPrint,addr szShowLoad
invoke DbgPrint,$CTA0("This is the first debug Information.")
invoke DbgPrint,$CTA0("%s"),$CTA0("This is the second debug Information.")
invoke DbgPrint,$CTA0("%ws"),$CTW0("This is the third debug Information.")
invoke DbgPrint,$CTA0("%S"),$CTW0("This is the forth debug Information.")
invoke RtlInitUnicodeString,addr ucstShow,$CTW0("This is the fifth debug Information.")
invoke DbgPrint,$CTA0("%wZ"),addr ucstShow
invoke RtlInitUnicodeString,addr ucstShow,$CTW0("hello,I was born in")
invoke DbgPrint,$CTA0("%wZ %x"),addr ucstShow,dwShow
assume edx:ptr DRIVER_OBJECT
mov edx,[pDriverObject]
mov [edx].DriverUnload,offset DriverUnload
mov eax,STATUS_SUCCESS
ret
DriverEntry endp
DriverUnload proc pDriverObject:PDRIVER_OBJECT
invoke DbgPrint,$CTA0("%s"),addr szShowUnLoad
mov eax,STATUS_SUCCESS
ret
DriverUnload endp
end DriverEntry
相关文章推荐
- 开发驱动时用到的内核打印函数KdPrint 的使用方法
- 开发驱动时用到的内核打印函数KdPrint 的使用方法
- JS 使用 window对象的print方法实现分页打印
- 测试驱动开发方法介绍及CPPUnit使用指南
- 使用unity进行测试驱动开发的方法
- 驱动开发之二:ntddk.h文件中函数的使用 如:PsSetCreateProcessNotifyRoutine
- 让你提前认识软件开发(18):C语言中常用的文件操作函数总结及使用方法演示代码
- 用函数printk打印内核信息的方法
- 有关win7下使用DebugView看内核打印的配置方法
- 订单打印软件PrintPDF的使用方法(临时)
- 驱动开发中使用wcscpy_s 等安全字符函数
- 测试驱动开发方法介绍及CPPUnit使用指南
- JavaWeb学习笔记——开发动态WEB资源(四)打印当前使用的是get方法
- 源码-JavaScript&jQuery交互式前端开发-第3章-函数、方法与对象-使用构造函数语法创建对象
- Linux驱动开发中s3c2410关于gpio的内核导出函数的解读
- WinDBG实时打印Windows驱动或者内核信息的方法
- 使用eclipse 开发 嵌入式Linux驱动(注意事项)(make:***没有规则可言创建目标"all".停止 的解决方法)
- 函数调试用函数printk打印内核信息的方法
- 用函数printk打印内核信息的方法
- Linux下使用函数打印程序堆栈错误的方法