public MethodData(String name, String descriptor, String className, MemberType type, int accessFlags, boolean finalMethod) { this.methodName = name; this.descriptor = descriptor; this.returnTypeDescriptor = DescriptorUtils.getReturnType(descriptor); this.argumentDescriptor = DescriptorUtils.getArgumentString(descriptor); this.className = className; this.type = type; this.accessFlags = accessFlags; this.methodNo = 0; this.finalMethod = finalMethod; }
ConstructorRewriteData(String clazz, String methodDesc, int methodNo, ClassLoader classLoader) { this.clazz = clazz; this.methodDesc = methodDesc; this.methodNo = methodNo; parameters = DescriptorUtils.descriptorStringToParameterArray(methodDesc); this.classLoader = classLoader; }
/** * After writing the instruction that requires a branch offset (e.g. GOTO ) * to the {@link Bytecode} call this method. This will write two zero bytes * to the stream. When you have reached the position in the bytecode that you * want the jump to end at call {@link JumpMarker#mark()}, this will update * the branch offset to point to the next bytecode instruction that is added * * @return The JumpMarker that is used to set the conditionals end point */ public static JumpMarker addJumpInstruction(Bytecode code) { return new JumpMarkerImpl(code); }
public static Bytecode unbox(Bytecode b, char type) { switch (type) { case 'I': return unboxInt(b); case 'J': return unboxLong(b); case 'S': return unboxShort(b); case 'F': return unboxFloat(b); case 'D': return unboxDouble(b); case 'B': return unboxByte(b); case 'C': return unboxChar(b); case 'Z': return unboxBoolean(b); } throw new RuntimeException("Cannot unbox unkown primitive type: " + type); }
public static void box(Bytecode b, char type) { switch (type) { case 'I': boxInt(b); break; case 'J': boxLong(b); break; case 'S': boxShort(b); break; case 'F': boxFloat(b); break; case 'D': boxDouble(b); break; case 'B': boxByte(b); break; case 'C': boxChar(b); break; case 'Z': boxBoolean(b); break; default: throw new RuntimeException("Cannot box unkown primitive type: " + type); } }
public static void pushParametersIntoArray(Bytecode bc, String methodDescriptor) { String[] params = DescriptorUtils.descriptorStringToParameterArray(methodDescriptor); if (DescriptorUtils.isWide(params[i])) { if (DescriptorUtils.isPrimitive(params[i])) { Boxing.box(bc, params[i].charAt(0));
public static byte[] getIntegrationClass(ClassLoader c, String name) { if (!integrationClassloader.contains(c)) { return null; } URL resource = ClassLoader.getSystemClassLoader().getResource(name.replace('.', '/') + ".class"); if (resource == null) { throw new RuntimeException("Could not load integration class " + name); } try (InputStream in = resource.openStream()) { return org.fakereplace.util.FileReader.readFileBytes(resource.openStream()); } catch (Exception e) { throw new RuntimeException(e); } }
String ret = DescriptorUtils.getReturnType(methodDescriptor); b.addCheckcast(DescriptorUtils.getReturnTypeInJvmFormat(methodDescriptor)); b.add(Opcode.ARETURN); return; Boxing.unbox(b, tp); if (tp == 'F') { b.add(Opcode.FRETURN);
public static String methodSignitureToDescriptor(Class<?> returnType, Class<?>... params) { return "(" + classArrayToDescriptorString(params) + ")" + classToStringRepresentation(returnType); }
/** * If this method is actually a constructor get the construtor object */ public Constructor<?> getConstructor(Class<?> actualClass) throws ClassNotFoundException, SecurityException, NoSuchMethodException { Class<?>[] methodDesc = DescriptorUtils.argumentStringToClassArray(descriptor, actualClass); return actualClass.getDeclaredConstructor(methodDesc); }
public static boolean isWide(String descriptor) { if (!isPrimitive(descriptor)) { return false; } char c = descriptor.charAt(0); if (c == 'D' || c == 'J') { return true; } return false; } }
public static String getDescriptor(Constructor<?> method) { return "(" + classArrayToDescriptorString(method.getParameterTypes()) + ")V"; }
public static void setValue(Object instance, Object value, int field) { fieldData.computeIfAbsent(instance, (e) -> new NullSafeConcurrentHashMap<>()).put(field, value); } }
public static String classArrayToDescriptorString(Class<?>... params) { if (params == null) { return ""; } StringBuilder ret = new StringBuilder(); for (Class<?> c : params) { ret.append(classToStringRepresentation(c)); } return ret.toString(); }
public MethodData(String name, String descriptor, String className, MemberType type, int accessFlags, int methodNo) { this.methodName = name; this.descriptor = descriptor; this.returnTypeDescriptor = DescriptorUtils.getReturnType(descriptor); this.argumentDescriptor = DescriptorUtils.getArgumentString(descriptor); this.className = className; this.type = type; this.accessFlags = accessFlags; this.methodNo = methodNo; this.finalMethod = false; }
public static int maxLocalsFromParameters(String methodDescriptor) { String[] params = descriptorStringToParameterArray(methodDescriptor); int ret = params.length; for(String i : params) { if(i.equals("J") || i.equals("D")) { ++ret; } } return ret; }
public static String getDescriptor(Method method) { return "(" + classArrayToDescriptorString(method.getParameterTypes()) + ")" + classToStringRepresentation(method.getReturnType()); }
public Method getMethod(Class<?> actualClass) throws ClassNotFoundException, SecurityException, NoSuchMethodException { Class<?>[] methodDesc = DescriptorUtils.argumentStringToClassArray(descriptor, actualClass); return actualClass.getDeclaredMethod(methodName, methodDesc); }
public static Method getMethod(String name, String methodDesc, Class actual) { try { return actual.getMethod(name, argumentStringToClassArray(methodDesc, actual)); } catch (Exception e) { // this should not happen throw new RuntimeException(e); } }
public Method getMethodToInvoke(Class<?> actualClass) throws ClassNotFoundException, SecurityException, NoSuchMethodException { Class<?>[] methodDesc; if (type == MemberType.FAKE && !isStatic()) { methodDesc = DescriptorUtils.argumentStringToClassArray(descriptor, actualClass); Class<?>[] ret = new Class<?>[methodDesc.length + 1]; ret[0] = ClassDataStore.instance().getRealClassFromProxyName(actualClass.getName()); System.arraycopy(methodDesc, 0, ret, 1, methodDesc.length); methodDesc = ret; } else { methodDesc = DescriptorUtils.argumentStringToClassArray(descriptor, actualClass); } return actualClass.getDeclaredMethod(methodName, methodDesc); }