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.