Refine search
public static Class<?> toClass(ClassFile ct, ClassLoader loader, ProtectionDomain domain) { if (MAGIC_IN_PROGRESS.get()) { try { final Class<?> originalProxyClass = loader.loadClass(ct.getName()); try { ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(); ct.write(out); Map<Class<?>, byte[]> reloadMap = new HashMap<Class<?>, byte[]>(); reloadMap.put(originalProxyClass, out.getBytes()); // TODO : is this standard way how to reload class? PluginManager.getInstance().hotswap(reloadMap); return originalProxyClass; } catch (Exception e) { throw new RuntimeException(e); } } catch (ClassNotFoundException e) { //it has not actually been loaded yet return ClassFileUtils.toClass(ct, loader, domain); } } return ClassFileUtils.toClass(ct, loader, domain); }
@Override public void writeData(ByteArrayDataOutputStream stream) throws IOException { stream.writeInt(2); // data length stream.writeShort(signatureIndex); } }
throw new RuntimeException("Code attribute is empty for method " + method.getName() + " " + method.getDescriptor()); LazySize size = stream.writeSize(); stream.writeShort(maxStackDepth); stream.writeShort(maxLocals); stream.writeInt(bytecode.length); stream.write(bytecode); stream.writeShort(exceptionTable.size()); // exception table length for (ExceptionHandler exception : exceptionTable) { stream.writeShort(exception.getStart()); stream.writeShort(exception.getEnd()); stream.writeShort(exception.getHandler()); stream.writeShort(exception.getExceptionIndex()); stream.writeShort(attributes.size()); // attributes count for (Attribute attribute : attributes) { attribute.write(stream);
@Override public void writeData(ByteArrayDataOutputStream stream) throws IOException { // as we don't know the size yet we write everything to a byte stream first // TODO: make this better final CodeAttribute ca = method.getCodeAttribute(); // now we need to write the stack frames. // for now we are going to write all frames as full frames // TODO: optimise the frame creation // write to dstream LazySize size = stream.writeSize(); stream.writeShort(ca.getStackFrames().size()); int lastPos = -1; for (Entry<Integer, StackFrame> entry : method.getCodeAttribute().getStackFrames().entrySet()) { int offset = entry.getKey() - lastPos - 1; lastPos = entry.getKey(); StackFrame frame = entry.getValue(); if (frame.getType() == StackFrameType.SAME_FRAME || frame.getType() == StackFrameType.SAME_FRAME_EXTENDED) { writeSameFrame(stream, offset, lastPos, frame); } else if (frame.getType() == StackFrameType.SAME_LOCALS_1_STACK && offset < (127 - 64)) { writeSameLocals1Stack(stream, offset, lastPos, frame); } else { writeFullFrame(stream, offset, lastPos, entry.getValue()); } } size.markEnd(); }
@Override public void writeData(ByteArrayDataOutputStream stream) throws IOException { LazySize sizeMarker = stream.writeSize(); stream.writeByte(noParameters); for(int i = 0; i < noParameters; ++ i) { if(!annotations.containsKey(i)) { stream.writeShort(0); } else { List<ClassAnnotation> ans = annotations.get(i); stream.writeShort(ans.size()); for (ClassAnnotation annotation : ans) { annotation.write(stream); } } } sizeMarker.markEnd(); }
stream.writeInt(0xCAFEBABE);// magic stream.writeInt(version); constPool.write(stream); stream.writeShort(accessFlags); stream.writeShort(nameIndex); stream.writeShort(superClassIndex); stream.writeShort(interfaceIndexes.size()); // interface count for (int i : interfaceIndexes) { stream.writeShort(i); stream.writeShort(fields.size()); // field count for (ClassField field : fields) { field.write(stream); stream.writeShort(methods.size()); // method count for (ClassMethod method : methods) { method.write(stream); stream.writeShort(attributes.size()); // attribute count for (Attribute attribute : attributes) { attribute.write(stream);
@Override public void writeData(ByteArrayDataOutputStream stream) throws IOException { stream.writeShort(typeIndex); stream.writeShort(valueIndex); }
public void write(ByteArrayDataOutputStream stream) throws IOException { if (nameIndex != -1) { stream.writeShort(nameIndex); } stream.writeByte(getTag()); writeData(stream); }
@Override public void writeData(ByteArrayDataOutputStream stream) throws IOException { LazySize sizeMarker = stream.writeSize(); stream.writeShort(annotations.size()); for (ClassAnnotation annotation : annotations) { annotation.write(stream); } sizeMarker.markEnd(); }
int size=(int)file.length(); FileInputStream input=new FileInputStream(file); ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(size); byte[] read_buf=new byte[1024]; int bytes;
public byte[] getBytes() { byte[] data = bytes.toByteArray(); for (final LazySizeImpl i : sizes) { overwriteInt(data, i.position, i.value); } return data; }
public LazySize writeSize() throws IOException { LazySizeImpl sv = new LazySizeImpl(this.written); sizes.add(sv); writeInt(0); return sv; }
public final void write(ByteArrayDataOutputStream stream) throws IOException { stream.writeByte(getType().getTag()); writeData(stream); }
if (method.getClassFile().getClassLoader() != null) { throw new RuntimeException("Code attribute is empty for method " + method.getName() + " " + method.getDescriptor()); LazySize size = stream.writeSize(); stream.writeShort(maxStackDepth); stream.writeShort(maxLocals); stream.writeInt(bytecode.length); stream.write(bytecode); stream.writeShort(exceptionTable.size()); // exception table length for (ExceptionHandler exception : exceptionTable) { stream.writeShort(exception.getStart()); stream.writeShort(exception.getEnd()); stream.writeShort(exception.getHandler()); stream.writeShort(exception.getExceptionIndex()); stream.writeShort(attributes.size()); // attributes count for (Attribute attribute : attributes) { attribute.write(stream);
@Override public void writeData(ByteArrayDataOutputStream stream) throws IOException { // as we don't know the size yet we write everything to a byte stream first // TODO: make this better final CodeAttribute ca = method.getCodeAttribute(); // now we need to write the stack frames. // for now we are going to write all frames as full frames // TODO: optimise the frame creation // write to dstream LazySize size = stream.writeSize(); stream.writeShort(ca.getStackFrames().size()); int lastPos = -1; for (Entry<Integer, StackFrame> entry : method.getCodeAttribute().getStackFrames().entrySet()) { int offset = entry.getKey() - lastPos - 1; lastPos = entry.getKey(); StackFrame frame = entry.getValue(); if (frame.getType() == StackFrameType.SAME_FRAME || frame.getType() == StackFrameType.SAME_FRAME_EXTENDED) { writeSameFrame(stream, offset, lastPos, frame); } else if (frame.getType() == StackFrameType.SAME_LOCALS_1_STACK && offset < (127 - 64)) { writeSameLocals1Stack(stream, offset, lastPos, frame); } else { writeFullFrame(stream, offset, lastPos, entry.getValue()); } } size.markEnd(); }
@Override public void writeData(ByteArrayDataOutputStream stream) throws IOException { LazySize sizeMarker = stream.writeSize(); stream.writeByte(noParameters); for(int i = 0; i < noParameters; ++ i) { if(!annotations.containsKey(i)) { stream.writeShort(0); } else { List<ClassAnnotation> ans = annotations.get(i); stream.writeShort(ans.size()); for (ClassAnnotation annotation : ans) { annotation.write(stream); } } } sizeMarker.markEnd(); }
stream.writeInt(0xCAFEBABE);// magic stream.writeInt(version); constPool.write(stream); stream.writeShort(accessFlags); stream.writeShort(nameIndex); stream.writeShort(superClassIndex); stream.writeShort(interfaceIndexes.size()); // interface count for (short i : interfaceIndexes) { stream.writeShort(i); stream.writeShort(fields.size()); // field count for (ClassField field : fields) { field.write(stream); stream.writeShort(methods.size()); // method count for (ClassMethod method : methods) { method.write(stream); stream.writeShort(attributes.size()); // attribute count for (Attribute attribute : attributes) { attribute.write(stream);
@Override public void writeData(ByteArrayDataOutputStream stream) throws IOException { stream.writeShort(typeIndex); stream.writeShort(valueIndex); }
public void write(ByteArrayDataOutputStream stream) throws IOException { if (nameIndex != -1) { stream.writeShort(nameIndex); } stream.writeByte(getTag()); writeData(stream); }
@Override public void writeData(ByteArrayDataOutputStream stream) throws IOException { LazySize sizeMarker = stream.writeSize(); stream.writeShort(annotations.size()); for (ClassAnnotation annotation : annotations) { annotation.write(stream); } sizeMarker.markEnd(); }