1 4 package com.tc.object.bytecode.hook.impl; 5 6 import java.nio.ByteBuffer ; 7 import java.security.ProtectionDomain ; 8 9 13 public class ClassProcessorHelperJDK15 { 14 15 public static ByteBuffer defineClass0Pre(ClassLoader caller, String name, ByteBuffer buffer, int off, int len, 16 ProtectionDomain pd) { 17 18 final byte[] origBytes; 19 final int offset; 20 21 if (buffer.hasArray()) { 22 origBytes = buffer.array(); 23 offset = buffer.arrayOffset() + buffer.position(); 24 } else { 25 origBytes = new byte[len]; 26 offset = 0; 27 int origPos = buffer.position(); 28 try { 29 buffer.get(origBytes); 30 } finally { 31 buffer.position(origPos); 32 } 33 } 34 35 byte[] possiblyTransformed = ClassProcessorHelper.defineClass0Pre(caller, name, origBytes, offset, len, pd); 36 37 if (possiblyTransformed == origBytes) { return buffer; } 38 39 ByteBuffer returnValue; 40 if (buffer.isDirect()) { 41 returnValue = ByteBuffer.allocateDirect(possiblyTransformed.length); 42 } else { 43 returnValue = ByteBuffer.allocate(possiblyTransformed.length); 44 } 45 46 returnValue.put(possiblyTransformed); 47 returnValue.position(0); 48 return returnValue; 49 } 50 51 } 52 | Popular Tags |