SHARE
TWEET

Untitled

a guest Aug 13th, 2017 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.lang.instrument.ClassFileTransformer;
  2. import java.lang.instrument.IllegalClassFormatException;
  3. import java.lang.instrument.Instrumentation;
  4. import java.security.ProtectionDomain;
  5.  
  6. import org.objectweb.asm.ClassAdapter;
  7. import org.objectweb.asm.ClassReader;
  8. import org.objectweb.asm.ClassVisitor;
  9. import org.objectweb.asm.ClassWriter;
  10. import org.objectweb.asm.Label;
  11. import org.objectweb.asm.MethodAdapter;
  12. import org.objectweb.asm.MethodVisitor;
  13.  
  14. public class Agent {
  15.    
  16.     private static class SocketTransformer implements ClassFileTransformer {
  17.  
  18.         private static class RemapMethodVisitor extends MethodAdapter {
  19.             public RemapMethodVisitor(MethodVisitor mv) {
  20.                 super(mv);
  21.             }
  22.  
  23.             @Override
  24.             public void visitLocalVariable(String name, String desc, String signature,
  25.                     Label start, Label end, int index) {
  26.                 System.out.println("Visiting local var "+name);
  27.                 mv.visitLocalVariable(name, desc, signature, start, end, index);
  28.             }
  29.  
  30.             @Override
  31.             public void visitMethodInsn(int opcode, String owner, String name,
  32.                     String desc) {
  33.                 System.out.println("Visiting method insn "+name);
  34.                 mv.visitMethodInsn(opcode, owner, name, desc);
  35.             }
  36.  
  37.             @Override
  38.             public void visitTypeInsn(int opcode, String type) {
  39.                 System.out.println("Visiting type insn "+type);
  40.                 mv.visitTypeInsn(opcode, type);
  41.             }
  42.  
  43.             @Override
  44.             public void visitVarInsn(int opcode, int var) {
  45.                 System.out.println("Visiting var insn " + var);
  46.                 mv.visitVarInsn(opcode, var);
  47.             }
  48.         }
  49.        
  50.         private static class RemapAdapter extends ClassAdapter {
  51.             public RemapAdapter(ClassVisitor cv) {
  52.                 super(cv);
  53.             }
  54.            
  55.             public MethodVisitor visitMethod(int access, String name,
  56.                         String desc, String signature, String [] exceptions) {
  57.                 MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions);
  58.                 if(null != mv) return new RemapMethodVisitor(mv);
  59.                 return mv;
  60.             }
  61.         }
  62.         public byte[] transform(ClassLoader arg0, String arg1, Class<?> arg2,
  63.                 ProtectionDomain arg3, byte[] bytes)
  64.                 throws IllegalClassFormatException {
  65.            
  66.             try {
  67.                 byte [] b = bytes.clone();
  68.                 ClassReader reader = new ClassReader(b);
  69.                 ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
  70.                 reader.accept(new RemapAdapter(writer), 1);
  71.                 b = writer.toByteArray();
  72.                 return b;
  73.             } catch(Throwable t) {
  74.                 System.out.println("Exception");
  75.                 t.printStackTrace();
  76.             }
  77.            
  78.             return bytes;
  79.         }
  80.        
  81.     }
  82.    
  83.     public static void premain(String args, Instrumentation ins) {
  84.         ins.addTransformer(new SocketTransformer());
  85.     }
  86.    
  87.     public static void main(String[] args) {
  88.         String hello = "hello";
  89.         System.out.println(hello);
  90.     }
  91. }
  92. /* ERROR LOG
  93. #
  94. # An unexpected error has been detected by HotSpot Virtual Machine:
  95. #
  96. #  EXCEPTION_PRIV_INSTRUCTION (0xc0000096) at pc=0x009a2571, pid=3380, tid=3384
  97. #
  98. # Java VM: Java HotSpot(TM) Client VM (1.5.0_09-b03 mixed mode)
  99. # Problematic frame:
  100. # j  java.lang.Shutdown.<clinit>()V+0
  101. #
  102.  
  103. ---------------  T H R E A D  ---------------
  104.  
  105. Current thread (0x00375f10):  JavaThread "DestroyJavaVM" [_thread_in_Java, id=3384]
  106.  
  107. siginfo: ExceptionCode=0xc0000096
  108.  
  109. Registers:
  110. EAX=0xffffffff, EBX=0x000000b0, ECX=0x00374ab0, EDX=0x00000000
  111. ESP=0x0006f8a0, EBP=0x0006f8ec, ESI=0x06beede8, EDI=0x0006f8f0
  112. EIP=0x009a2571, EFLAGS=0x00010212
  113.  
  114. Top of Stack: (sp=0x0006f8a0)
  115. 0x0006f8a0:   0006f8f0 06beede8 0006f8ec 0006f8c0
  116. 0x0006f8b0:   000000b0 06beeff0 00000009 0006f8f0
  117. 0x0006f8c0:   009a256b 6d884f98 0006fb14 00000000
  118. 0x0006f8d0:   0006f8d0 06beede0 0006f8f0 06beeff0
  119. 0x0006f8e0:   00000000 06beede0 0006f8f4 0006f904
  120. 0x0006f8f0:   009a0215 00375f10 06beede0 00375f10
  121. 0x0006f900:   009a01e5 0006f980 6d7b6e84 0006f938
  122. 0x0006f910:   0006fa64 0000000a 06beede0 009a75d0
  123.  
  124. Instructions: (pc=0x009a2571)
  125. 0x009a2561:   68 98 4f 88 6d e8 00 00 00 00 60 e8 c2 7d d9 6c
  126. 0x009a2571:   f4 90 90 00 00 00 00 00 00 00 00 00 00 00 00 80
  127.  
  128.  
  129. Stack: [0x00030000,0x00070000),  sp=0x0006f8a0,  free space=254k
  130. Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
  131. j  java.lang.Shutdown.<clinit>()V+0
  132. v  ~StubRoutines::call_stub
  133. V  [jvm.dll+0x86e84]
  134. V  [jvm.dll+0xddead]
  135. V  [jvm.dll+0x86d55]
  136. V  [jvm.dll+0x79481]
  137. V  [jvm.dll+0x78364]
  138. V  [jvm.dll+0xc94a9]
  139. V  [jvm.dll+0x86c7a]
  140. V  [jvm.dll+0x86cbe]
  141. V  [jvm.dll+0x1117f1]
  142. V  [jvm.dll+0x11189c]
  143. V  [jvm.dll+0x917dc]
  144. C  [javaw.exe+0x1508]
  145. C  [javaw.exe+0x3151]
  146. C  [kernel32.dll+0x17067]
  147.  
  148.  
  149. ---------------  P R O C E S S  ---------------
  150.  
  151. Java Threads: ( => current thread )
  152. =>0x00375f10 JavaThread "DestroyJavaVM" [_thread_in_Java, id=3384]
  153.   0x0097a2d0 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=3436]
  154.   0x00974950 JavaThread "CompilerThread0" daemon [_thread_blocked, id=3396]
  155.   0x00974798 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=3416]
  156.   0x00959b80 JavaThread "Finalizer" daemon [_thread_blocked, id=3420]
  157.   0x00958718 JavaThread "Reference Handler" daemon [_thread_blocked, id=3424]
  158.  
  159. Other Threads:
  160.   0x00955c50 VMThread [id=3428]
  161.   0x00962c20 WatcherThread [id=3412]
  162.  
  163. VM state:not at safepoint (normal execution)
  164.  
  165. VM Mutex/Monitor currently owned by a thread: None
  166.  
  167. Heap
  168.  def new generation   total 576K, used 539K [0x02a20000, 0x02ac0000, 0x02f00000)
  169.   eden space 512K,  92% used [0x02a20000, 0x02a96e68, 0x02aa0000)
  170.   from space 64K,  99% used [0x02ab0000, 0x02abfff8, 0x02ac0000)
  171.   to   space 64K,   0% used [0x02aa0000, 0x02aa0000, 0x02ab0000)
  172.  tenured generation   total 1408K, used 59K [0x02f00000, 0x03060000, 0x06a20000)
  173.    the space 1408K,   4% used [0x02f00000, 0x02f0ed90, 0x02f0ee00, 0x03060000)
  174.  compacting perm gen  total 8192K, used 1852K [0x06a20000, 0x07220000, 0x0aa20000)
  175.    the space 8192K,  22% used [0x06a20000, 0x06bef000, 0x06bef000, 0x07220000)
  176. No shared spaces configured.
  177.  
  178. Dynamic libraries:
  179. 0x00400000 - 0x0040d000     C:\Sun\SDK\jdk\bin\javaw.exe
  180. 0x7c900000 - 0x7c9af000     C:\WINDOWS\system32\ntdll.dll
  181. 0x7c800000 - 0x7c8f6000     C:\WINDOWS\system32\kernel32.dll
  182. 0x77dd0000 - 0x77e6b000     C:\WINDOWS\system32\ADVAPI32.dll
  183. 0x77e70000 - 0x77f02000     C:\WINDOWS\system32\RPCRT4.dll
  184. 0x77fe0000 - 0x77ff1000     C:\WINDOWS\system32\Secur32.dll
  185. 0x7e410000 - 0x7e4a1000     C:\WINDOWS\system32\USER32.dll
  186. 0x77f10000 - 0x77f59000     C:\WINDOWS\system32\GDI32.dll
  187. 0x77c10000 - 0x77c68000     C:\WINDOWS\system32\MSVCRT.dll
  188. 0x76390000 - 0x763ad000     C:\WINDOWS\system32\IMM32.DLL
  189. 0x629c0000 - 0x629c9000     C:\WINDOWS\system32\LPK.DLL
  190. 0x74d90000 - 0x74dfb000     C:\WINDOWS\system32\USP10.dll
  191. 0x6d730000 - 0x6d8cb000     C:\Sun\SDK\jdk\jre\bin\client\jvm.dll
  192. 0x76b40000 - 0x76b6d000     C:\WINDOWS\system32\WINMM.dll
  193. 0x6d2f0000 - 0x6d2f8000     C:\Sun\SDK\jdk\jre\bin\hpi.dll
  194. 0x76bf0000 - 0x76bfb000     C:\WINDOWS\system32\PSAPI.DLL
  195. 0x6d320000 - 0x6d32e000     C:\Sun\SDK\jdk\jre\bin\instrument.dll
  196. 0x6d700000 - 0x6d70c000     C:\Sun\SDK\jdk\jre\bin\verify.dll
  197. 0x6d370000 - 0x6d38d000     C:\Sun\SDK\jdk\jre\bin\java.dll
  198. 0x6d720000 - 0x6d72f000     C:\Sun\SDK\jdk\jre\bin\zip.dll
  199.  
  200. VM Arguments:
  201. jvm_args: -javaagent:agent.jar -Dfile.encoding=Cp1252
  202. java_command: Agent
  203. Launcher Type: SUN_STANDARD
  204.  
  205. Environment Variables:
  206. PATH=C:/Sun/SDK/jdk/bin/../jre/bin/client;C:/Sun/SDK/jdk/bin/../jre/bin;C:/Sun/SDK/jdk/bin/../jre/lib/i386;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Sun\SDK\bin;C:\Sun\SDK\jdk\bin;C:\Documents and Settings\DIGIT\Desktop\eclipse;
  207. USERNAME=DIGIT
  208. OS=Windows_NT
  209. PROCESSOR_IDENTIFIER=x86 Family 6 Model 23 Stepping 6, GenuineIntel
  210.  
  211.  
  212.  
  213. ---------------  S Y S T E M  ---------------
  214.  
  215. OS: Windows XP Build 2600 Service Pack 3
  216.  
  217. CPU:total 1 (cores per cpu 2, threads per core 1) family 6 model 7 stepping 6, cmov, cx8, fxsr, mmx, sse, sse2
  218.  
  219. Memory: 4k page, physical 2096624k(1535888k free), swap 4038728k(3663912k free)
  220.  
  221. vm_info: Java HotSpot(TM) Client VM (1.5.0_09-b03) for windows-x86, built on Oct 12 2006 01:20:10 by "java_re" with MS VC++ 6.0
  222. */
RAW Paste Data
Top