@Nullable private static List<Value> copyToBuffer( EvaluationContextImpl evaluationContext, ObjectReference bitmap, Dimension size) throws EvaluateException { DebugProcessImpl debugProcess = evaluationContext.getDebugProcess(); VirtualMachineProxyImpl virtualMachineProxy = debugProcess.getVirtualMachineProxy(); List<ReferenceType> classes = virtualMachineProxy.classesByName("byte[]"); if (classes.size() != 1 || !(classes.get(0) instanceof ArrayType)) { return null; } ArrayType byteArrayType = (ArrayType) classes.get(0); classes = virtualMachineProxy.classesByName("java.nio.ByteBuffer"); if (classes.size() != 1 || !(classes.get(0) instanceof ClassType)) { return null; } ClassType byteBufferType = (ClassType) classes.get(0); Method wrapMethod = DebuggerUtils.findMethod(byteBufferType, "wrap", "([B)Ljava/nio/ByteBuffer;"); if (wrapMethod == null) { return null; } ArrayReference byteArray = byteArrayType.newInstance(size.width * size.height * 4); Value byteBufferRef = debugProcess.invokeMethod( evaluationContext, byteBufferType, wrapMethod, ImmutableList.of(byteArray)); Method copyToBufferMethod = DebuggerUtils.findMethod( bitmap.referenceType(), "copyPixelsToBuffer", "(Ljava/nio/Buffer;)V"); if (copyToBufferMethod == null) { return null; } debugProcess.invokeMethod( evaluationContext, bitmap, copyToBufferMethod, ImmutableList.of(byteBufferRef)); return byteArray.getValues(); }
private static ArrayReference createURLArray(EvaluationContext context) throws EvaluateException, InvocationException, InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException { DebugProcess process = context.getDebugProcess(); ArrayType arrayType = (ArrayType) process.findClass(context, "java.net.URL[]", context.getClassLoader()); ArrayReference arrayRef = arrayType.newInstance(1); keep(arrayRef, context); ClassType classType = (ClassType) process.findClass(context, "java.net.URL", context.getClassLoader()); VirtualMachineProxyImpl proxy = (VirtualMachineProxyImpl) process.getVirtualMachineProxy(); StringReference url = proxy.mirrorOf("file:a"); keep(url, context); ObjectReference reference = process.newInstance( context, classType, classType.concreteMethodByName("<init>", "(Ljava/lang/String;)V"), Collections.singletonList(url)); keep(reference, context); arrayRef.setValues(Collections.singletonList(reference)); return arrayRef; }