com.android.dx.rop.cst.CstMethodRef Java Examples

The following examples show how to use com.android.dx.rop.cst.CstMethodRef. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: J2ME-Loader   Author: nikita36078   File: DebugInfoDecoder.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Validates an encoded debug info stream against data used to encode it,
 * throwing an exception if they do not match. Used to validate the
 * encoder.
 *
 * @param info encoded debug info
 * @param file {@code non-null;} file to refer to during decoding
 * @param ref {@code non-null;} method whose info is being decoded
 * @param code {@code non-null;} original code object that was encoded
 * @param isStatic whether the method is static
 */
public static void validateEncode(byte[] info, DexFile file,
        CstMethodRef ref, DalvCode code, boolean isStatic) {
    PositionList pl = code.getPositions();
    LocalList ll = code.getLocals();
    DalvInsnList insns = code.getInsns();
    int codeSize = insns.codeSize();
    int countRegisters = insns.getRegistersSize();

    try {
        validateEncode0(info, codeSize, countRegisters,
                isStatic, ref, file, pl, ll);
    } catch (RuntimeException ex) {
        System.err.println("instructions:");
        insns.debugPrint(System.err, "  ", true);
        System.err.println("local list:");
        ll.debugPrint(System.err, "  ");
        throw ExceptionWithContext.withContext(ex,
                "while processing " + ref.toHuman());
    }
}
 
Example #2
Source Project: Box   Author: lulululbj   File: DebugInfoDecoder.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Validates an encoded debug info stream against data used to encode it,
 * throwing an exception if they do not match. Used to validate the
 * encoder.
 *
 * @param info encoded debug info
 * @param file {@code non-null;} file to refer to during decoding
 * @param ref {@code non-null;} method whose info is being decoded
 * @param code {@code non-null;} original code object that was encoded
 * @param isStatic whether the method is static
 */
public static void validateEncode(byte[] info, DexFile file,
        CstMethodRef ref, DalvCode code, boolean isStatic) {
    PositionList pl = code.getPositions();
    LocalList ll = code.getLocals();
    DalvInsnList insns = code.getInsns();
    int codeSize = insns.codeSize();
    int countRegisters = insns.getRegistersSize();

    try {
        validateEncode0(info, codeSize, countRegisters,
                isStatic, ref, file, pl, ll);
    } catch (RuntimeException ex) {
        System.err.println("instructions:");
        insns.debugPrint(System.err, "  ", true);
        System.err.println("local list:");
        ll.debugPrint(System.err, "  ");
        throw ExceptionWithContext.withContext(ex,
                "while processing " + ref.toHuman());
    }
}
 
Example #3
Source Project: J2ME-Loader   Author: nikita36078   File: CodeItem.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param ref {@code non-null;} method that this code implements
 * @param code {@code non-null;} the underlying code
 * @param isStatic whether this instance is for a {@code static}
 * method
 * @param throwsList {@code non-null;} list of possibly-thrown exceptions,
 * just used in generating debugging output (listings)
 */
public CodeItem(CstMethodRef ref, DalvCode code, boolean isStatic,
        TypeList throwsList) {
    super(ALIGNMENT, -1);

    if (ref == null) {
        throw new NullPointerException("ref == null");
    }

    if (code == null) {
        throw new NullPointerException("code == null");
    }

    if (throwsList == null) {
        throw new NullPointerException("throwsList == null");
    }

    this.ref = ref;
    this.code = code;
    this.isStatic = isStatic;
    this.throwsList = throwsList;
    this.catches = null;
    this.debugInfo = null;
}
 
Example #4
Source Project: Box   Author: lulululbj   File: EncodedMethod.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param method {@code non-null;} constant for the method
 * @param accessFlags access flags
 * @param code {@code null-ok;} code for the method, if it is neither
 * {@code abstract} nor {@code native}
 * @param throwsList {@code non-null;} list of possibly-thrown exceptions,
 * just used in generating debugging output (listings)
 */
public EncodedMethod(CstMethodRef method, int accessFlags,
        DalvCode code, TypeList throwsList) {
    super(accessFlags);

    if (method == null) {
        throw new NullPointerException("method == null");
    }

    this.method = method;

    if (code == null) {
        this.code = null;
    } else {
        boolean isStatic = (accessFlags & AccessFlags.ACC_STATIC) != 0;
        this.code = new CodeItem(method, code, isStatic, throwsList);
    }
}
 
Example #5
Source Project: Box   Author: lulululbj   File: CodeItem.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param ref {@code non-null;} method that this code implements
 * @param code {@code non-null;} the underlying code
 * @param isStatic whether this instance is for a {@code static}
 * method
 * @param throwsList {@code non-null;} list of possibly-thrown exceptions,
 * just used in generating debugging output (listings)
 */
public CodeItem(CstMethodRef ref, DalvCode code, boolean isStatic,
        TypeList throwsList) {
    super(ALIGNMENT, -1);

    if (ref == null) {
        throw new NullPointerException("ref == null");
    }

    if (code == null) {
        throw new NullPointerException("code == null");
    }

    if (throwsList == null) {
        throw new NullPointerException("throwsList == null");
    }

    this.ref = ref;
    this.code = code;
    this.isStatic = isStatic;
    this.throwsList = throwsList;
    this.catches = null;
    this.debugInfo = null;
}
 
Example #6
Source Project: Box   Author: lulululbj   File: InvokePolymorphicInsn.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param opcode {@code non-null;} the opcode
 * @param position {@code non-null;} source position
 * @param sources {@code non-null;} specs for all the sources
 * @param catches {@code non-null;} list of exceptions caught
 * @param callSiteMethod {@code non-null;} the method called by
 * invoke-virtual that this instance will replace.
 */
public InvokePolymorphicInsn(Rop opcode, SourcePosition position, RegisterSpecList sources, TypeList catches,
        CstMethodRef callSiteMethod) {
    super(opcode, position, null, sources);

    if (opcode.getBranchingness() != Rop.BRANCH_THROW) {
        throw new IllegalArgumentException("opcode with invalid branchingness: " + opcode.getBranchingness());
    }

    if (catches == null) {
        throw new NullPointerException("catches == null");
    }
    this.catches = catches;

    if (callSiteMethod == null) {
        throw new NullPointerException("callSiteMethod == null");
    } else if (!callSiteMethod.isSignaturePolymorphic()) {
        throw new IllegalArgumentException("callSiteMethod is not signature polymorphic");
    }

    this.callSiteMethod = callSiteMethod;
    this.polymorphicMethod = makePolymorphicMethod(callSiteMethod);
    this.callSiteProto = makeCallSiteProto(callSiteMethod);
}
 
Example #7
Source Project: buck   Author: facebook   File: AttributeTranslator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@code EnclosingMethod} attribute out of a given
 * {@link AttributeList}, if any, translating it to an annotation.
 * If the class really has an enclosing method, this returns an
 * {@code EnclosingMethod} annotation; if not, this returns
 * an {@code EnclosingClass} annotation.
 *
 * @param attribs {@code non-null;} the attributes list to search in
 * @return {@code null-ok;} the converted {@code EnclosingMethod} or
 * {@code EnclosingClass} annotation, if there was an
 * attribute to translate
 */
private static Annotation translateEnclosingMethod(AttributeList attribs) {
    AttEnclosingMethod enclosingMethod = (AttEnclosingMethod)
        attribs.findFirst(AttEnclosingMethod.ATTRIBUTE_NAME);

    if (enclosingMethod == null) {
        return null;
    }

    CstType enclosingClass = enclosingMethod.getEnclosingClass();
    CstNat nat = enclosingMethod.getMethod();

    if (nat == null) {
        /*
         * Dalvik doesn't use EnclosingMethod annotations unless
         * there really is an enclosing method. Anonymous classes
         * are unambiguously identified by having an InnerClass
         * annotation with an empty name along with an appropriate
         * EnclosingClass.
         */
        return AnnotationUtils.makeEnclosingClass(enclosingClass);
    }

    return AnnotationUtils.makeEnclosingMethod(
            new CstMethodRef(enclosingClass, nat));
}
 
Example #8
Source Project: Box   Author: lulululbj   File: AttributeTranslator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@code EnclosingMethod} attribute out of a given
 * {@link AttributeList}, if any, translating it to an annotation.
 * If the class really has an enclosing method, this returns an
 * {@code EnclosingMethod} annotation; if not, this returns
 * an {@code EnclosingClass} annotation.
 *
 * @param attribs {@code non-null;} the attributes list to search in
 * @return {@code null-ok;} the converted {@code EnclosingMethod} or
 * {@code EnclosingClass} annotation, if there was an
 * attribute to translate
 */
private static Annotation translateEnclosingMethod(AttributeList attribs) {
    AttEnclosingMethod enclosingMethod = (AttEnclosingMethod)
        attribs.findFirst(AttEnclosingMethod.ATTRIBUTE_NAME);

    if (enclosingMethod == null) {
        return null;
    }

    CstType enclosingClass = enclosingMethod.getEnclosingClass();
    CstNat nat = enclosingMethod.getMethod();

    if (nat == null) {
        /*
         * Dalvik doesn't use EnclosingMethod annotations unless
         * there really is an enclosing method. Anonymous classes
         * are unambiguously identified by having an InnerClass
         * annotation with an empty name along with an appropriate
         * EnclosingClass.
         */
        return AnnotationUtils.makeEnclosingClass(enclosingClass);
    }

    return AnnotationUtils.makeEnclosingMethod(
            new CstMethodRef(enclosingClass, nat));
}
 
Example #9
Source Project: Box   Author: lulululbj   File: DebugInfoDecoder.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Validates an encoded debug info stream against data used to encode it,
 * throwing an exception if they do not match. Used to validate the
 * encoder.
 *
 * @param info encoded debug info
 * @param file {@code non-null;} file to refer to during decoding
 * @param ref {@code non-null;} method whose info is being decoded
 * @param code {@code non-null;} original code object that was encoded
 * @param isStatic whether the method is static
 */
public static void validateEncode(byte[] info, DexFile file,
        CstMethodRef ref, DalvCode code, boolean isStatic) {
    PositionList pl = code.getPositions();
    LocalList ll = code.getLocals();
    DalvInsnList insns = code.getInsns();
    int codeSize = insns.codeSize();
    int countRegisters = insns.getRegistersSize();

    try {
        validateEncode0(info, codeSize, countRegisters,
                isStatic, ref, file, pl, ll);
    } catch (RuntimeException ex) {
        System.err.println("instructions:");
        insns.debugPrint(System.err, "  ", true);
        System.err.println("local list:");
        ll.debugPrint(System.err, "  ");
        throw ExceptionWithContext.withContext(ex,
                "while processing " + ref.toHuman());
    }
}
 
Example #10
Source Project: buck   Author: facebook   File: EncodedMethod.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param method {@code non-null;} constant for the method
 * @param accessFlags access flags
 * @param code {@code null-ok;} code for the method, if it is neither
 * {@code abstract} nor {@code native}
 * @param throwsList {@code non-null;} list of possibly-thrown exceptions,
 * just used in generating debugging output (listings)
 */
public EncodedMethod(CstMethodRef method, int accessFlags,
        DalvCode code, TypeList throwsList) {
    super(accessFlags);

    if (method == null) {
        throw new NullPointerException("method == null");
    }

    this.method = method;

    if (code == null) {
        this.code = null;
    } else {
        boolean isStatic = (accessFlags & AccessFlags.ACC_STATIC) != 0;
        this.code = new CodeItem(method, code, isStatic, throwsList);
    }
}
 
Example #11
Source Project: Box   Author: lulululbj   File: CodeItem.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param ref {@code non-null;} method that this code implements
 * @param code {@code non-null;} the underlying code
 * @param isStatic whether this instance is for a {@code static}
 * method
 * @param throwsList {@code non-null;} list of possibly-thrown exceptions,
 * just used in generating debugging output (listings)
 */
public CodeItem(CstMethodRef ref, DalvCode code, boolean isStatic,
        TypeList throwsList) {
    super(ALIGNMENT, -1);

    if (ref == null) {
        throw new NullPointerException("ref == null");
    }

    if (code == null) {
        throw new NullPointerException("code == null");
    }

    if (throwsList == null) {
        throw new NullPointerException("throwsList == null");
    }

    this.ref = ref;
    this.code = code;
    this.isStatic = isStatic;
    this.throwsList = throwsList;
    this.catches = null;
    this.debugInfo = null;
}
 
Example #12
Source Project: RocooFix   Author: dodola   File: ClassReferenceListBuilder.java    License: MIT License 6 votes vote down vote up
private void addDependencies(ConstantPool pool) {

        for (Constant constant : pool.getEntries()) {
            if (constant instanceof CstType) {
                checkDescriptor(((CstType) constant).getClassType());
            } else if (constant instanceof CstFieldRef) {
                checkDescriptor(((CstFieldRef) constant).getType());
            } else if (constant instanceof CstMethodRef) {
                Prototype proto = ((CstMethodRef) constant).getPrototype();
                checkDescriptor(proto.getReturnType());
                StdTypeList args = proto.getParameterTypes();
                for (int i = 0; i < args.size(); i++) {
                    checkDescriptor(args.get(i));
                }
            }
        }
    }
 
Example #13
Source Project: buck   Author: facebook   File: CodeItem.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param ref {@code non-null;} method that this code implements
 * @param code {@code non-null;} the underlying code
 * @param isStatic whether this instance is for a {@code static}
 * method
 * @param throwsList {@code non-null;} list of possibly-thrown exceptions,
 * just used in generating debugging output (listings)
 */
public CodeItem(CstMethodRef ref, DalvCode code, boolean isStatic,
        TypeList throwsList) {
    super(ALIGNMENT, -1);

    if (ref == null) {
        throw new NullPointerException("ref == null");
    }

    if (code == null) {
        throw new NullPointerException("code == null");
    }

    if (throwsList == null) {
        throw new NullPointerException("throwsList == null");
    }

    this.ref = ref;
    this.code = code;
    this.isStatic = isStatic;
    this.throwsList = throwsList;
    this.catches = null;
    this.debugInfo = null;
}
 
Example #14
Source Project: J2ME-Loader   Author: nikita36078   File: Form35c.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    if (!(insn instanceof CstInsn)) {
        return false;
    }

    CstInsn ci = (CstInsn) insn;
    int cpi = ci.getIndex();

    if (! unsignedFitsInShort(cpi)) {
        return false;
    }

    Constant cst = ci.getConstant();
    if (!((cst instanceof CstMethodRef) ||
          (cst instanceof CstType))) {
        return false;
    }

    RegisterSpecList regs = ci.getRegisters();
    return (wordCount(regs) >= 0);
}
 
Example #15
Source Project: buck   Author: facebook   File: Form35c.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    if (!(insn instanceof CstInsn)) {
        return false;
    }

    CstInsn ci = (CstInsn) insn;
    int cpi = ci.getIndex();

    if (! unsignedFitsInShort(cpi)) {
        return false;
    }

    Constant cst = ci.getConstant();
    if (!((cst instanceof CstMethodRef) ||
          (cst instanceof CstType))) {
        return false;
    }

    RegisterSpecList regs = ci.getRegisters();
    return (wordCount(regs) >= 0);
}
 
Example #16
Source Project: Box   Author: lulululbj   File: Form45cc.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    if (!(insn instanceof MultiCstInsn)) {
        return false;
    }

    MultiCstInsn mci = (MultiCstInsn) insn;
    if (mci.getNumberOfConstants() != 2) {
        return false;
    }

    int methodIdx = mci.getIndex(0);
    int protoIdx = mci.getIndex(1);
    if (!unsignedFitsInShort(methodIdx) || !unsignedFitsInShort(protoIdx)) {
        return false;
    }

    Constant methodRef = mci.getConstant(0);
    if (!(methodRef instanceof CstMethodRef)) {
        return false;
    }

    Constant protoRef = mci.getConstant(1);
    if (!(protoRef instanceof CstProtoRef)) {
        return false;
    }

    RegisterSpecList regs = mci.getRegisters();
    return (wordCount(regs) >= 0);
}
 
Example #17
Source Project: Box   Author: lulululbj   File: Form4rcc.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    if (!(insn instanceof MultiCstInsn)) {
        return false;
    }

    MultiCstInsn mci = (MultiCstInsn) insn;
    int methodIdx = mci.getIndex(0);
    int protoIdx = mci.getIndex(1);
    if (!unsignedFitsInShort(methodIdx) || !unsignedFitsInShort(protoIdx)) {
        return false;
    }

    Constant methodRef = mci.getConstant(0);
    if (!(methodRef instanceof CstMethodRef)) {
        return false;
    }

    Constant protoRef = mci.getConstant(1);
    if (!(protoRef instanceof CstProtoRef)) {
        return false;
    }

    RegisterSpecList regs = mci.getRegisters();
    int sz = regs.size();
    if (sz == 0) {
        return true;
    }

    return (unsignedFitsInByte(regs.getWordCount()) &&
            unsignedFitsInShort(sz) &&
            unsignedFitsInShort(regs.get(0).getReg()) &&
            isRegListSequential(regs));
}
 
Example #18
Source Project: Box   Author: lulululbj   File: Form3rc.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    if (!(insn instanceof CstInsn)) {
        return false;
    }

    CstInsn ci = (CstInsn) insn;
    int cpi = ci.getIndex();
    Constant cst = ci.getConstant();

    if (! unsignedFitsInShort(cpi)) {
        return false;
    }

    if (!((cst instanceof CstMethodRef) ||
          (cst instanceof CstType) ||
          (cst instanceof CstCallSiteRef))) {
        return false;
    }

    RegisterSpecList regs = ci.getRegisters();
    int sz = regs.size();

    return (regs.size() == 0) ||
        (isRegListSequential(regs) &&
         unsignedFitsInShort(regs.get(0).getReg()) &&
         unsignedFitsInByte(regs.getWordCount()));
}
 
Example #19
Source Project: dexmaker   Author: linkedin   File: MethodId.java    License: Apache License 2.0 5 votes vote down vote up
MethodId(TypeId<D> declaringType, TypeId<R> returnType, String name, TypeList parameters) {
    if (declaringType == null || returnType == null || name == null || parameters == null) {
        throw new NullPointerException();
    }
    this.declaringType = declaringType;
    this.returnType = returnType;
    this.name = name;
    this.parameters = parameters;
    this.nat = new CstNat(new CstString(name), new CstString(descriptor(false)));
    this.constant = new CstMethodRef(declaringType.constant, nat);
}
 
Example #20
Source Project: Box   Author: lulululbj   File: AnnotationsDirectoryItem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Adds a method annotations item to this instance.
 *
 * @param method {@code non-null;} method in question
 * @param annotations {@code non-null;} associated annotations to add
 * @param dexFile {@code non-null;} dex output
 */
public void addMethodAnnotations(CstMethodRef method,
        Annotations annotations, DexFile dexFile) {
    if (methodAnnotations == null) {
        methodAnnotations = new ArrayList<MethodAnnotationStruct>();
    }

    methodAnnotations.add(new MethodAnnotationStruct(method,
                    new AnnotationSetItem(annotations, dexFile)));
}
 
Example #21
Source Project: Box   Author: lulululbj   File: AnnotationsDirectoryItem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Adds a parameter annotations item to this instance.
 *
 * @param method {@code non-null;} method in question
 * @param list {@code non-null;} associated list of annotation sets to add
 * @param dexFile {@code non-null;} dex output
 */
public void addParameterAnnotations(CstMethodRef method,
        AnnotationsList list, DexFile dexFile) {
    if (parameterAnnotations == null) {
        parameterAnnotations = new ArrayList<ParameterAnnotationStruct>();
    }

    parameterAnnotations.add(new ParameterAnnotationStruct(method, list, dexFile));
}
 
Example #22
Source Project: Box   Author: lulululbj   File: AnnotationsDirectoryItem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets the parameter annotations for a given method, if any. This is
 * meant for use by debugging / dumping code.
 *
 * @param method {@code non-null;} the method
 * @return {@code null-ok;} the parameter annotations, if any
 */
public AnnotationsList getParameterAnnotations(CstMethodRef method) {
    if (parameterAnnotations == null) {
        return null;
    }

    for (ParameterAnnotationStruct item : parameterAnnotations) {
        if (item.getMethod().equals(method)) {
            return item.getAnnotationsList();
        }
    }

    return null;
}
 
Example #23
Source Project: J2ME-Loader   Author: nikita36078   File: DebugInfoEncoder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates an instance.
 *
 * @param positions {@code null-ok;} positions (line numbers) to encode
 * @param locals {@code null-ok;} local variables to encode
 * @param file {@code null-ok;} may only be {@code null} if simply using
 * this class to do a debug print
 * @param codeSize
 * @param regSize
 * @param isStatic
 * @param ref
 */
public DebugInfoEncoder(PositionList positions, LocalList locals,
        DexFile file, int codeSize, int regSize,
        boolean isStatic, CstMethodRef ref) {
    this.positions = positions;
    this.locals = locals;
    this.file = file;
    this.desc = ref.getPrototype();
    this.isStatic = isStatic;
    this.codeSize = codeSize;
    this.regSize = regSize;

    output = new ByteArrayAnnotatedOutput();
    lastEntryForReg = new LocalList.Entry[regSize];
}
 
Example #24
Source Project: Box   Author: lulululbj   File: MethodAnnotationStruct.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param method {@code non-null;} the method in question
 * @param annotations {@code non-null;} the associated annotations
 */
public MethodAnnotationStruct(CstMethodRef method,
        AnnotationSetItem annotations) {
    if (method == null) {
        throw new NullPointerException("method == null");
    }

    if (annotations == null) {
        throw new NullPointerException("annotations == null");
    }

    this.method = method;
    this.annotations = annotations;
}
 
Example #25
Source Project: Box   Author: lulululbj   File: EscapeAnalysis.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Replaces instructions that trigger an ArrayIndexOutofBounds exception
 * with an actual throw of the exception.
 *
 * @param insn {@code non-null;} instruction causing the exception
 * @param index {@code non-null;} index value that is out of bounds
 * @param deletedInsns {@code non-null;} set of instructions marked for
 * deletion
 */
private void insertExceptionThrow(SsaInsn insn, RegisterSpec index,
                                      HashSet<SsaInsn> deletedInsns) {
    // Create a new ArrayIndexOutOfBoundsException
    CstType exception =
        new CstType(Exceptions.TYPE_ArrayIndexOutOfBoundsException);
    insertThrowingInsnBefore(insn, RegisterSpecList.EMPTY, null,
                                 RegOps.NEW_INSTANCE, exception);

    // Add a successor block with a move result pseudo for the exception
    SsaBasicBlock currBlock = insn.getBlock();
    SsaBasicBlock newBlock =
        currBlock.insertNewSuccessor(currBlock.getPrimarySuccessor());
    SsaInsn newInsn = newBlock.getInsns().get(0);
    RegisterSpec newReg =
        RegisterSpec.make(ssaMeth.makeNewSsaReg(), exception);
    insertPlainInsnBefore(newInsn, RegisterSpecList.EMPTY, newReg,
                              RegOps.MOVE_RESULT_PSEUDO, null);

    // Add another successor block to initialize the exception
    SsaBasicBlock newBlock2 =
        newBlock.insertNewSuccessor(newBlock.getPrimarySuccessor());
    SsaInsn newInsn2 = newBlock2.getInsns().get(0);
    CstNat newNat = new CstNat(new CstString("<init>"), new CstString("(I)V"));
    CstMethodRef newRef = new CstMethodRef(exception, newNat);
    insertThrowingInsnBefore(newInsn2, RegisterSpecList.make(newReg, index),
                                 null, RegOps.INVOKE_DIRECT, newRef);
    deletedInsns.add(newInsn2);

    // Add another successor block to throw the new exception
    SsaBasicBlock newBlock3 =
        newBlock2.insertNewSuccessor(newBlock2.getPrimarySuccessor());
    SsaInsn newInsn3 = newBlock3.getInsns().get(0);
    insertThrowingInsnBefore(newInsn3, RegisterSpecList.make(newReg), null,
                                 RegOps.THROW, null);
    newBlock3.replaceSuccessor(newBlock3.getPrimarySuccessorIndex(),
                                   ssaMeth.getExitBlock().getIndex());
    deletedInsns.add(newInsn3);
}
 
Example #26
Source Project: Box   Author: lulululbj   File: Form45cc.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    if (!(insn instanceof MultiCstInsn)) {
        return false;
    }

    MultiCstInsn mci = (MultiCstInsn) insn;
    if (mci.getNumberOfConstants() != 2) {
        return false;
    }

    int methodIdx = mci.getIndex(0);
    int protoIdx = mci.getIndex(1);
    if (!unsignedFitsInShort(methodIdx) || !unsignedFitsInShort(protoIdx)) {
        return false;
    }

    Constant methodRef = mci.getConstant(0);
    if (!(methodRef instanceof CstMethodRef)) {
        return false;
    }

    Constant protoRef = mci.getConstant(1);
    if (!(protoRef instanceof CstProtoRef)) {
        return false;
    }

    RegisterSpecList regs = mci.getRegisters();
    return (wordCount(regs) >= 0);
}
 
Example #27
Source Project: Box   Author: lulululbj   File: Form4rcc.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    if (!(insn instanceof MultiCstInsn)) {
        return false;
    }

    MultiCstInsn mci = (MultiCstInsn) insn;
    int methodIdx = mci.getIndex(0);
    int protoIdx = mci.getIndex(1);
    if (!unsignedFitsInShort(methodIdx) || !unsignedFitsInShort(protoIdx)) {
        return false;
    }

    Constant methodRef = mci.getConstant(0);
    if (!(methodRef instanceof CstMethodRef)) {
        return false;
    }

    Constant protoRef = mci.getConstant(1);
    if (!(protoRef instanceof CstProtoRef)) {
        return false;
    }

    RegisterSpecList regs = mci.getRegisters();
    int sz = regs.size();
    if (sz == 0) {
        return true;
    }

    return (unsignedFitsInByte(regs.getWordCount()) &&
            unsignedFitsInShort(sz) &&
            unsignedFitsInShort(regs.get(0).getReg()) &&
            isRegListSequential(regs));
}
 
Example #28
Source Project: Box   Author: lulululbj   File: Form3rc.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    if (!(insn instanceof CstInsn)) {
        return false;
    }

    CstInsn ci = (CstInsn) insn;
    int cpi = ci.getIndex();
    Constant cst = ci.getConstant();

    if (! unsignedFitsInShort(cpi)) {
        return false;
    }

    if (!((cst instanceof CstMethodRef) ||
          (cst instanceof CstType) ||
          (cst instanceof CstCallSiteRef))) {
        return false;
    }

    RegisterSpecList regs = ci.getRegisters();
    int sz = regs.size();

    return (regs.size() == 0) ||
        (isRegListSequential(regs) &&
         unsignedFitsInShort(regs.get(0).getReg()) &&
         unsignedFitsInByte(regs.getWordCount()));
}
 
Example #29
Source Project: Box   Author: lulululbj   File: DebugInfoDecoder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param encoded encoded debug info
 * @param codesize size of code block in code units
 * @param regSize register size, in register units, of the register space
 * used by this method
 * @param isStatic true if method is static
 * @param ref method descriptor of method this debug info is for
 * @param file dex file this debug info will be stored in
 */
DebugInfoDecoder(byte[] encoded, int codesize, int regSize,
        boolean isStatic, CstMethodRef ref, DexFile file) {
    if (encoded == null) {
        throw new NullPointerException("encoded == null");
    }

    this.encoded = encoded;
    this.isStatic = isStatic;
    this.desc = ref.getPrototype();
    this.file = file;
    this.regSize = regSize;

    positions = new ArrayList<PositionEntry>();
    locals = new ArrayList<LocalEntry>();
    this.codesize = codesize;
    lastEntryForReg = new LocalEntry[regSize];

    int idx = -1;

    try {
        idx = file.getStringIds().indexOf(new CstString("this"));
    } catch (IllegalArgumentException ex) {
        /*
         * Silently tolerate not finding "this". It just means that
         * no method has local variable info that looks like
         * a standard instance method.
         */
    }

    thisStringIdx = idx;
}
 
Example #30
Source Project: Box   Author: lulululbj   File: AnnotationsDirectoryItem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Adds a method annotations item to this instance.
 *
 * @param method {@code non-null;} method in question
 * @param annotations {@code non-null;} associated annotations to add
 * @param dexFile {@code non-null;} dex output
 */
public void addMethodAnnotations(CstMethodRef method,
        Annotations annotations, DexFile dexFile) {
    if (methodAnnotations == null) {
        methodAnnotations = new ArrayList<MethodAnnotationStruct>();
    }

    methodAnnotations.add(new MethodAnnotationStruct(method,
                    new AnnotationSetItem(annotations, dexFile)));
}