Special Command—.if and j to Use in Breakpoints and Scripts
The .if and j commands are used conditionally to execute a command or series of commands.
.if is very similar to if from C and C++:
.if ( Condition ) { Commands } .elsif ( Condition ) { Commands } .else { Commands }
j does the same thing, but uses a very different syntax:
j Expression ' Command1 ' ; ' Command2 '
Generally, I prefer to use .if because I think it’s more intuitive since it looks like C/C++.
Examples:
j (@ecx = 7) '.echo Condition is TRUE' ; '.echo Condition is FALSE'
.if(@ecx = 7){.echo Condition is TRUE}
Let’s suppose we need a breakpoint that performs some action when the breakpoint is hit over 10 times.
We can do that using:
r @$t0 = 0
bp mtgdi!CBallThread::SingleStep "r @$t0 = @$t0 + 1;.if(@$t0 > 0n10){.echo More than 10 times...}.else{ gc }"
Or yet:
r @$t0 = 0
bp mtgdi!CBallThread::SingleStep " r @$t0 = @$t0 + 1; j (@$t0 > 0n10) '.echo More than ten times...'; 'gc' "
Tip: The examples above are "old school". As Koy Kahane mentions, you can use:
bp mtgdi!CBallThread::SingleStep 10
Here you can see scripts that use j and .if.
Comments
Anonymous
June 12, 2008
PingBack from http://blog.a-foton.ru/2008/06/13/special-command%e2%80%94if-and-j-to-use-in-breakpoints-and-scripts/Anonymous
June 12, 2008
The breakpoint command "bp" also has a Passes parameter that makes the breakpoint trigger beginning on the specified pass. For example, to trigger a breakpoint on the 10th call and higher to mtgdi!CBallThread::SingleStep you can do: bp mtgdi!CBallThread::SingleStep 10Anonymous
June 13, 2008
Koby, thanks for the remainder, I totally missed it! The post was changed based on your comment. ;-)