You can insert an infinite loop in the code that you can find once you attach to the process.
- Right click the method you want to put a breakpoint on and select
Edit Method
.
- Add an infinite loop inside an
if
before the code where you wanted to put the breakpoint: bool a = true;if(a){while(true){}}
. Click Compile
.
- Save module.
- Run the sample as desired.
- Attach to the process with DnSpy (you may need to run it as admin) and pause (
Break all
) the debugger, which will stop at the infinite loop.
- The instruction where you wanted to put the breakpoint is the first after the
else
. Right click this instruction and select Set Next Statement
.
This is similar to the EBFE
technique.
Note that the definition of bool a = true;
and the if
surrounding the while(true)
is needed to trick the debugger to avoid that compilation remove the rest of the code. If the compiler is still able to remove it, you can try a bit more difficult condition to trick the debugger such as int a = 3; int b = 2; if(a*2-b+1==5){while(true){}};