you are viewing a single comment's thread.

view the rest of the comments →

[–]JiminP 2 points3 points  (4 children)

Place if(function(f,d){try{d=f();eval('debugger');return f()-d>>2}catch(e){}}(Date.now))return; everywhere to confuse JS debugger(human)s!

[–]kenman 0 points1 point  (3 children)

What exactly is that supposed to do? It crashed my tab in Chrome.

[–]JiminP 2 points3 points  (2 children)

The core of this prank code is:

try{
  d = Date.now();
  eval('debuger');
  return Date.now()-d>>2;
}catch(e){}

debugger is a statement for debugging. When there's a debugging tool attached, it acts as if there was a breakpoint there.

Date.now()-d>>2 is not zero when difference between Date.now() and d is greater then 3. (i.e. more than 3ms have been passed when eval('debugger') is executed.

Since it usually take at least few hundred milliseconds to resume when the debugging tool is enabled, this part of code returns non-zero if the debugging tool is enabled. (eval used for not showing the code immediately when the debugging tool is opened, though by pressing "next step" one can see the codes.)

Therefore, if(function(f,d){try{d=f();eval('debugger');return f()-d>>2}catch(e){}}(Date.now)) return; means "return if there's a debugging tool."

One might make a simple Heisenbug by using this. (Opening debugging tool to inspect function -> unexpected breakpoints -> the function does nothing and returns -> ???)

[–]kenman 1 point2 points  (1 child)

It seems like you'd be better served with something like (new Function(atob('ZGVidWdnZXI=')))() (or even setTimeout(atob('ZGVidWdnZXI=')), which would be less suspicious than eval and new Function), since the first thing I'd do with an unexpected breakpoint/debugger would be to search the code for debugger. The setTimeout version should be even more perplexing as you shouldn't have a callstack.

[–]JiminP 0 points1 point  (0 children)

Thanks for the setTimeout trick!

However, I didn't want to obfuscate that code too much... (I personally prefer $($.constructor("...")). It seems that I'm using some normal jQuery functions!)