Guest User

Interesting Anti-Debugging Technique for standalone Java app

a guest
Mar 22nd, 2013
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. // (c) 2013 http://twitter.com/mihi42 //
  2.  
  3. import java.lang.reflect.Field;
  4. import java.lang.reflect.Method;
  5. import sun.misc.Unsafe;
  6.  
  7. public class CrashWhenDebugged {
  8.     public static void main(String[] args) throws Exception {
  9.         Field ff = Unsafe.class.getDeclaredField("theUnsafe");
  10.         ff.setAccessible(true);
  11.         Unsafe u = (Unsafe) ff.get(null);
  12.         final Field g = Thread.class.getDeclaredField("group");
  13.         g.setAccessible(true);
  14.         Thread t = new Thread("Killer") {
  15.             public void run() {
  16.                 try {
  17.                     Thread.sleep(200);
  18.                     g.set(this, null);
  19.                 } catch (Exception ex) {
  20.                 }
  21.             }
  22.         };
  23.         u.putInt(t, u.objectFieldOffset(g), 3);
  24.         Method m = Thread.class.getDeclaredMethod("start0");
  25.         m.setAccessible(true);
  26.         m.invoke(t);
  27.         t.join();
  28.         System.out.println("I survived!");
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment