Search in sources :

Example 1 with LocationImpl

use of com.sun.tools.jdi.LocationImpl in project smali by JesusFreke.

the class SmaliCodeFragmentFactory method evaluateRegister.

@Nullable
public static Value evaluateRegister(EvaluationContext context, final SmaliMethod smaliMethod, final int registerNum, final String type) throws EvaluateException {
    if (registerNum >= smaliMethod.getRegisterCount()) {
        return null;
    }
    final StackFrameProxy frameProxy = context.getSuspendContext().getFrameProxy();
    if (frameProxy == null) {
        return null;
    }
    VirtualMachine vm = frameProxy.getStackFrame().virtualMachine();
    Location currentLocation = frameProxy.location();
    if (currentLocation == null) {
        return null;
    }
    Method method = currentLocation.method();
    try {
        final Constructor<LocalVariableImpl> localVariableConstructor = LocalVariableImpl.class.getDeclaredConstructor(VirtualMachine.class, Method.class, Integer.TYPE, Location.class, Location.class, String.class, String.class, String.class);
        localVariableConstructor.setAccessible(true);
        Constructor<LocationImpl> locationConstructor = LocationImpl.class.getDeclaredConstructor(VirtualMachine.class, Method.class, Long.TYPE);
        locationConstructor.setAccessible(true);
        int methodSize = 0;
        for (SmaliInstruction instruction : smaliMethod.getInstructions()) {
            methodSize += instruction.getInstructionSize();
        }
        Location endLocation = null;
        for (int endCodeIndex = (methodSize / 2) - 1; endCodeIndex >= 0; endCodeIndex--) {
            endLocation = method.locationOfCodeIndex(endCodeIndex);
            if (endLocation != null) {
                break;
            }
        }
        if (endLocation == null) {
            return null;
        }
        LocalVariable localVariable = localVariableConstructor.newInstance(vm, method, mapRegister(frameProxy.getStackFrame().virtualMachine(), smaliMethod, registerNum), method.location(), endLocation, String.format("v%d", registerNum), type, null);
        return frameProxy.getStackFrame().getValue(localVariable);
    } catch (NoSuchMethodException e) {
        return null;
    } catch (InstantiationException e) {
        return null;
    } catch (IllegalAccessException e) {
        return null;
    } catch (InvocationTargetException e) {
        return null;
    }
}
Also used : LocalVariableImpl(com.sun.tools.jdi.LocalVariableImpl) StackFrameProxy(com.intellij.debugger.engine.jdi.StackFrameProxy) PsiLocalVariable(com.intellij.psi.PsiLocalVariable) SmaliMethod(org.jf.smalidea.psi.impl.SmaliMethod) SmaliInstruction(org.jf.smalidea.psi.impl.SmaliInstruction) InvocationTargetException(java.lang.reflect.InvocationTargetException) LocationImpl(com.sun.tools.jdi.LocationImpl) Nullable(javax.annotation.Nullable)

Aggregations

StackFrameProxy (com.intellij.debugger.engine.jdi.StackFrameProxy)1 PsiLocalVariable (com.intellij.psi.PsiLocalVariable)1 LocalVariableImpl (com.sun.tools.jdi.LocalVariableImpl)1 LocationImpl (com.sun.tools.jdi.LocationImpl)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Nullable (javax.annotation.Nullable)1 SmaliInstruction (org.jf.smalidea.psi.impl.SmaliInstruction)1 SmaliMethod (org.jf.smalidea.psi.impl.SmaliMethod)1