0.windbg script-$<, $><, $$<, $$><, $$>a< (Run Script File)

script是包含调试器命令序列的文本文件,

可以使用以下方式来执行script

如最简单的script:c:\1.txt

.echo hello windbg
执行方式有:

$<filename
$><Filename 

此两种方式,要求文件路径和前面的标识符紧贴,不允许有空格

示例:

0:000> $><c:\1.txt
hello windbg
0:000> $<c:\1.txt
0:000> .echo hello windbg
hello windbg
0:000> $< c:\1.txt
Command file execution failed, Win32 error 0n123
    "文件名、目录名或卷标语法不正确。"

为此,个人建议使用$$方式:它支持filename之前带空格

$$< Filename 
$$>< Filename 
示例:

0:000> $$< c:\1.txt
0:000> .echo hello windbg
hello windbg
0:000> $$><   c:\1.txt
hello windbg


还有一种常用的带参方式:

$$>a< Filename [arg1 arg2 arg3 ... ]

argn:指定任意数目的参数,用于调试器传送给脚本,在执行脚本文件之前,脚本文件中任意${$argn}格式的字符串,对应被调试器传送进来的argn替换,

参数中不能包括引号或分号,多个参数应该用空格来分隔开,如果一个参数包含了空格,那么就用引号把它括起来,你可以使用任意多的参数,如果这个参数没被传入,就直接显示${$arg1}

如,我把1.txt内容变成如下:

.echo The first argument is ${$arg1}.
.echo The fifth argument is ${$arg5}.
.echo The fourth argument is ${$arg4}.

也就是脚本会获取第1第5第4个参数,运行:

0:000> $$>a< c:\1.txt  1 2 3 4 5
The first argument is 1.
The fifth argument is 5.
The fourth argument is 4.
0:000> $$>a< c:\1.txt  1 2 3 4 
The first argument is 1.
The fifth argument is ${$arg5}.
The fourth argument is 4.


//-----------------------------------------------

1.$$>a< script文件参数中带空格:那么就把它用双引号括起来,这同样适用于filename

0:000> $$>a< C:\Program Files\1.txt  1 2 3 4 
Command file execution failed, Win32 error 0n2
    "系统找不到指定的文件。"
0:000> $$>a< "C:\Program Files\1.txt"  1 2 3 4 
The first argument is 1.
The fifth argument is ${$arg5}.
The fourth argument is 4.
2.如果你使用$<或$><,你不能在Filename之前加任意空格,你也不能使用引号把Filename括起来,你也不能在这个命令后加分号或其他命令!

0:000> $><c:\1.txt
The first argument is ${$arg1}
The fifth argument is ${$arg5}
The fourth argument is ${$arg4}
0:000> $>< c:\1.txt
Command file execution failed, Win32 error 0n2
    "系统找不到指定的文件。"
0:000> $><c:\1.txt;
Command file execution failed, Win32 error 0n2
    "系统找不到指定的文件。"
0:000> $><c:\1.txt;r eax
Command file execution failed, Win32 error 0n2
    "系统找不到指定的文件。"

3.如果你使用$$<或$$><,那么Filename之前可以不带空格,你能在这个命令之后使用一个分号或其他命令,你可以选择Filename使用引号括起来,但不是必需的,即使Filename中含有空格或同一行中有其他命令(这个前面肯定要带分号来分隔不同命令):

0:000> $$>< c:\1.txt
The first argument is ${$arg1}
The fifth argument is ${$arg5}
The fourth argument is ${$arg4}
0:000> $$><c:\1.txt
The first argument is ${$arg1}
The fifth argument is ${$arg5}
The fourth argument is ${$arg4}
0:000> $$><"c:\1.txt"
The first argument is ${$arg1}
The fifth argument is ${$arg5}
The fourth argument is ${$arg4}
0:000> $$><c:\1.txt; r ebx
The first argument is ${$arg1}
The fifth argument is ${$arg5}
The fourth argument is ${$arg4}
ebx=00000000

也就是$$><或$$<会把分号之前(如果没有分号就是整行)都当成Filename


$< 和$$<关键字逐个执行脚本文件中的命令(多个命令就是一个一个命令输出)。

$><和$$><关键字打开脚本文件,将所有回车替换为分号,然后将转换后的文本当作单个命令块来执行。这些关键字在运行包含调试器命令程序的脚本时非常有用。

注意是<和><的区别

把1.txt改成如下:

.echo cmd1
.echo cmd2


执行:

0:000> $<c:\1.txt
0:000> .echo cmd1
cmd1
0:000> .echo cmd2
cmd2
0:000> 
cmd2
0:000> 
cmd2
0:000> $><c:\1.txt
cmd1
cmd2

<输出果然是多行,而><是单行,但为什么会出现

0:000> 
cmd2
0:000> 
cmd2

原因很简单

<不做转换,它一行行执行,而1.txt最后两行有两个回车

><做转换,最后的回车换成了分号,相当于

.echo cmd1;.echo cmd2;;;








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值