如何打印变量并在 windbg 脚本的 if 语句中使用它?

How to print the variable and use it from the if sentence in windbg script?

1,关于如何打印变量,我在windbg脚本中使用了下面这句话,但是打印不出来

 r @$t0 = 123;
   .printf  @$t0

2、如何在if语句中使用变量,但是我发现还是失败了。

 r @$t0 = 123;
 .if(@$t0 ==123)
{
.printf  @$t0
}

如何修改?

我认为你使用伪寄存器的方式没有错,但是:

1) .printf() 采用格式字符串,就像在 C

中一样

2) 默认情况下,数字是十六进制而不是十进制,使用 0n 或 0x 明确提及它们的基数

3) 从历史上看,您不应该使用“@”来设置带有 'r' 的伪寄存器,尽管我相信现在它可以以任何一种方式工作

r $t0 = 0n123;
.if ( @$t0 == 0n123 )
{ 
 .printf "%d", @$t0 
}

$$ windbg脚本中三角数之和

r eax=0;r $t0=0;.while(@$t0<10){r eax=@eax+@$t0;.printf "%2d=%3d\n",@$t0,@eax;r $t0=@$t0+1}

结果

 0=  0
 1=  1
 2=  3
 3=  6
 4= 10
 5= 15
 6= 21
 7= 28
 8= 36
 9= 45
10= 55
11= 66
12= 78
13= 91
14=105
15=120

让我们确认一下 f(n) = n * (n+1) /2

 ? 0n15 * (0n16/2)
Evaluate expression: 120 = 00000078