org.jf.dexlib2.ReferenceType Java Examples

The following examples show how to use org.jf.dexlib2.ReferenceType. 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: ZjDroid   Author: KB5201314   File: ReferenceFormatter.java    License: Apache License 2.0 6 votes vote down vote up
public static void writeReference(IndentingWriter writer, int referenceType,
                                  Reference reference) throws IOException {
    switch (referenceType) {
        case ReferenceType.STRING:
            writeStringReference(writer, ((StringReference)reference).getString());
            return;
        case ReferenceType.TYPE:
            writer.write(((TypeReference)reference).getType());
            return;
        case ReferenceType.METHOD:
            ReferenceUtil.writeMethodDescriptor(writer, (MethodReference)reference);
            return;
        case ReferenceType.FIELD:
            ReferenceUtil.writeFieldDescriptor(writer, (FieldReference)reference);
            return;
        default:
            throw new IllegalStateException("Unknown reference type");
    }
}
 
Example #2
Source Project: atlas   Author: alibaba   File: ReferenceFormatter.java    License: Apache License 2.0 6 votes vote down vote up
public static void writeReference(IndentingWriter writer, int referenceType,
                                  Reference reference) throws IOException {
    switch (referenceType) {
        case ReferenceType.STRING:
            writeStringReference(writer, ((StringReference)reference).getString());
            return;
        case ReferenceType.TYPE:
            writer.write(((TypeReference)reference).getType());
            return;
        case ReferenceType.METHOD:
            ReferenceUtil.writeMethodDescriptor(writer, (MethodReference) reference);
            return;
        case ReferenceType.FIELD:
            ReferenceUtil.writeFieldDescriptor(writer, (FieldReference)reference);
            return;
        default:
            throw new IllegalStateException("Unknown reference type");
    }
}
 
Example #3
Source Project: zjdroid   Author: Miracle963   File: ReferenceFormatter.java    License: Apache License 2.0 6 votes vote down vote up
public static void writeReference(IndentingWriter writer, int referenceType,
                                  Reference reference) throws IOException {
    switch (referenceType) {
        case ReferenceType.STRING:
            writeStringReference(writer, ((StringReference)reference).getString());
            return;
        case ReferenceType.TYPE:
            writer.write(((TypeReference)reference).getType());
            return;
        case ReferenceType.METHOD:
            ReferenceUtil.writeMethodDescriptor(writer, (MethodReference)reference);
            return;
        case ReferenceType.FIELD:
            ReferenceUtil.writeFieldDescriptor(writer, (FieldReference)reference);
            return;
        default:
            throw new IllegalStateException("Unknown reference type");
    }
}
 
Example #4
Source Project: HeyGirl   Author: mikusjelly   File: ReferenceFormatter.java    License: Apache License 2.0 6 votes vote down vote up
public static void writeReference(IndentingWriter writer, int referenceType,
                                  Reference reference) throws IOException {
    switch (referenceType) {
        case ReferenceType.STRING:
            writeStringReference(writer, ((StringReference)reference).getString());
            return;
        case ReferenceType.TYPE:
            writer.write(((TypeReference)reference).getType());
            return;
        case ReferenceType.METHOD:
            ReferenceUtil.writeMethodDescriptor(writer, (MethodReference)reference);
            return;
        case ReferenceType.FIELD:
            ReferenceUtil.writeFieldDescriptor(writer, (FieldReference)reference);
            return;
        default:
            throw new IllegalStateException("Unknown reference type");
    }
}
 
Example #5
Source Project: ZjDroid   Author: halfkiss   File: ReferenceFormatter.java    License: Apache License 2.0 6 votes vote down vote up
public static void writeReference(IndentingWriter writer, int referenceType,
                                  Reference reference) throws IOException {
    switch (referenceType) {
        case ReferenceType.STRING:
            writeStringReference(writer, ((StringReference)reference).getString());
            return;
        case ReferenceType.TYPE:
            writer.write(((TypeReference)reference).getType());
            return;
        case ReferenceType.METHOD:
            ReferenceUtil.writeMethodDescriptor(writer, (MethodReference)reference);
            return;
        case ReferenceType.FIELD:
            ReferenceUtil.writeFieldDescriptor(writer, (FieldReference)reference);
            return;
        default:
            throw new IllegalStateException("Unknown reference type");
    }
}
 
Example #6
Source Project: ZjDroid   Author: KB5201314   File: ImmutableReferenceFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
public static ImmutableReference of(int referenceType, Reference reference) {
    switch (referenceType) {
        case ReferenceType.STRING:
            return ImmutableStringReference.of((StringReference)reference);
        case ReferenceType.TYPE:
            return ImmutableTypeReference.of((TypeReference)reference);
        case ReferenceType.FIELD:
            return ImmutableFieldReference.of((FieldReference)reference);
        case ReferenceType.METHOD:
            return ImmutableMethodReference.of((MethodReference)reference);
    }
    throw new ExceptionWithContext("Invalid reference type: %d", referenceType);
}
 
Example #7
Source Project: ZjDroid   Author: KB5201314   File: InstructionWriter.java    License: Apache License 2.0 5 votes vote down vote up
private int getReferenceIndex(ReferenceInstruction referenceInstruction) {
    switch (referenceInstruction.getOpcode().referenceType) {
        case ReferenceType.FIELD:
            return fieldSection.getItemIndex((FieldRefKey)referenceInstruction.getReference());
        case ReferenceType.METHOD:
            return methodSection.getItemIndex((MethodRefKey)referenceInstruction.getReference());
        case ReferenceType.STRING:
            return stringSection.getItemIndex((StringRef)referenceInstruction.getReference());
        case ReferenceType.TYPE:
            return typeSection.getItemIndex((TypeRef)referenceInstruction.getReference());
        default:
            throw new ExceptionWithContext("Unknown reference type: %d",
                    referenceInstruction.getOpcode().referenceType);
    }
}
 
Example #8
Source Project: ZjDroid   Author: KB5201314   File: InstructionRewriter.java    License: Apache License 2.0 5 votes vote down vote up
@Override @Nonnull public Reference getReference() {
    switch (getReferenceType()) {
        case ReferenceType.TYPE:
            return RewriterUtils.rewriteTypeReference(rewriters.getTypeRewriter(),
                    (TypeReference)instruction.getReference());
        case ReferenceType.FIELD:
            return rewriters.getFieldReferenceRewriter().rewrite((FieldReference)instruction.getReference());
        case ReferenceType.METHOD:
            return rewriters.getMethodReferenceRewriter().rewrite((MethodReference)instruction.getReference());
        case ReferenceType.STRING:
            return instruction.getReference();
        default:
            throw new IllegalArgumentException();
    }
}
 
Example #9
Source Project: ZjDroid   Author: KB5201314   File: DexBackedReference.java    License: Apache License 2.0 5 votes vote down vote up
public static Reference makeReference(@Nonnull DexBackedDexFile dexFile, int referenceType, int referenceIndex) {
    switch (referenceType) {
        case ReferenceType.STRING:
            return new DexBackedStringReference(dexFile, referenceIndex);
        case ReferenceType.TYPE:
            return new DexBackedTypeReference(dexFile, referenceIndex);
        case ReferenceType.METHOD:
            return new DexBackedMethodReference(dexFile, referenceIndex);
        case ReferenceType.FIELD:
            return new DexBackedFieldReference(dexFile, referenceIndex);
        default:
            throw new ExceptionWithContext("Invalid reference type: %d", referenceType);
    }
}
 
Example #10
Source Project: ZjDroid   Author: KB5201314   File: Preconditions.java    License: Apache License 2.0 5 votes vote down vote up
public static <T extends Reference> T checkReference(int referenceType, T reference) {
    switch (referenceType) {
        case ReferenceType.STRING:
            if (!(reference instanceof StringReference)) {
                throw new IllegalArgumentException("Invalid reference type, expecting a string reference");
            }
            break;
        case ReferenceType.TYPE:
            if (!(reference instanceof TypeReference)) {
                throw new IllegalArgumentException("Invalid reference type, expecting a type reference");
            }
            break;
        case ReferenceType.FIELD:
            if (!(reference instanceof FieldReference)) {
                throw new IllegalArgumentException("Invalid reference type, expecting a field reference");
            }
            break;
        case ReferenceType.METHOD:
            if (!(reference instanceof MethodReference)) {
                throw new IllegalArgumentException("Invalid reference type, expecting a method reference");
            }
            break;
        default:
            throw new IllegalArgumentException(String.format("Not a valid reference type: %d", referenceType));
    }
    return reference;
}
 
Example #11
Source Project: atlas   Author: alibaba   File: InstructionMethodItem.java    License: Apache License 2.0 5 votes vote down vote up
private String writeInvalidItemIndex(InvalidItemIndex ex, int type, IndentingWriter writer)
        throws IOException {
    writer.write("#");
    writer.write(ex.getMessage());
    writer.write("\n");
    return String.format("%[email protected]%d", ReferenceType.toString(type), ex.getInvalidIndex());
}
 
Example #12
Source Project: zjdroid   Author: Miracle963   File: ImmutableReferenceFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
public static ImmutableReference of(int referenceType, Reference reference) {
    switch (referenceType) {
        case ReferenceType.STRING:
            return ImmutableStringReference.of((StringReference)reference);
        case ReferenceType.TYPE:
            return ImmutableTypeReference.of((TypeReference)reference);
        case ReferenceType.FIELD:
            return ImmutableFieldReference.of((FieldReference)reference);
        case ReferenceType.METHOD:
            return ImmutableMethodReference.of((MethodReference)reference);
    }
    throw new ExceptionWithContext("Invalid reference type: %d", referenceType);
}
 
Example #13
Source Project: zjdroid   Author: Miracle963   File: InstructionWriter.java    License: Apache License 2.0 5 votes vote down vote up
private int getReferenceIndex(ReferenceInstruction referenceInstruction) {
    switch (referenceInstruction.getOpcode().referenceType) {
        case ReferenceType.FIELD:
            return fieldSection.getItemIndex((FieldRefKey)referenceInstruction.getReference());
        case ReferenceType.METHOD:
            return methodSection.getItemIndex((MethodRefKey)referenceInstruction.getReference());
        case ReferenceType.STRING:
            return stringSection.getItemIndex((StringRef)referenceInstruction.getReference());
        case ReferenceType.TYPE:
            return typeSection.getItemIndex((TypeRef)referenceInstruction.getReference());
        default:
            throw new ExceptionWithContext("Unknown reference type: %d",
                    referenceInstruction.getOpcode().referenceType);
    }
}
 
Example #14
Source Project: zjdroid   Author: Miracle963   File: InstructionRewriter.java    License: Apache License 2.0 5 votes vote down vote up
@Override @Nonnull public Reference getReference() {
    switch (getReferenceType()) {
        case ReferenceType.TYPE:
            return RewriterUtils.rewriteTypeReference(rewriters.getTypeRewriter(),
                    (TypeReference)instruction.getReference());
        case ReferenceType.FIELD:
            return rewriters.getFieldReferenceRewriter().rewrite((FieldReference)instruction.getReference());
        case ReferenceType.METHOD:
            return rewriters.getMethodReferenceRewriter().rewrite((MethodReference)instruction.getReference());
        case ReferenceType.STRING:
            return instruction.getReference();
        default:
            throw new IllegalArgumentException();
    }
}
 
Example #15
Source Project: zjdroid   Author: Miracle963   File: DexBackedReference.java    License: Apache License 2.0 5 votes vote down vote up
public static Reference makeReference(@Nonnull DexBackedDexFile dexFile, int referenceType, int referenceIndex) {
    switch (referenceType) {
        case ReferenceType.STRING:
            return new DexBackedStringReference(dexFile, referenceIndex);
        case ReferenceType.TYPE:
            return new DexBackedTypeReference(dexFile, referenceIndex);
        case ReferenceType.METHOD:
            return new DexBackedMethodReference(dexFile, referenceIndex);
        case ReferenceType.FIELD:
            return new DexBackedFieldReference(dexFile, referenceIndex);
        default:
            throw new ExceptionWithContext("Invalid reference type: %d", referenceType);
    }
}
 
Example #16
Source Project: zjdroid   Author: Miracle963   File: Preconditions.java    License: Apache License 2.0 5 votes vote down vote up
public static <T extends Reference> T checkReference(int referenceType, T reference) {
    switch (referenceType) {
        case ReferenceType.STRING:
            if (!(reference instanceof StringReference)) {
                throw new IllegalArgumentException("Invalid reference type, expecting a string reference");
            }
            break;
        case ReferenceType.TYPE:
            if (!(reference instanceof TypeReference)) {
                throw new IllegalArgumentException("Invalid reference type, expecting a type reference");
            }
            break;
        case ReferenceType.FIELD:
            if (!(reference instanceof FieldReference)) {
                throw new IllegalArgumentException("Invalid reference type, expecting a field reference");
            }
            break;
        case ReferenceType.METHOD:
            if (!(reference instanceof MethodReference)) {
                throw new IllegalArgumentException("Invalid reference type, expecting a method reference");
            }
            break;
        default:
            throw new IllegalArgumentException(String.format("Not a valid reference type: %d", referenceType));
    }
    return reference;
}
 
Example #17
Source Project: HeyGirl   Author: mikusjelly   File: ImmutableReferenceFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
public static ImmutableReference of(int referenceType, Reference reference) {
    switch (referenceType) {
        case ReferenceType.STRING:
            return ImmutableStringReference.of((StringReference)reference);
        case ReferenceType.TYPE:
            return ImmutableTypeReference.of((TypeReference)reference);
        case ReferenceType.FIELD:
            return ImmutableFieldReference.of((FieldReference)reference);
        case ReferenceType.METHOD:
            return ImmutableMethodReference.of((MethodReference)reference);
    }
    throw new ExceptionWithContext("Invalid reference type: %d", referenceType);
}
 
Example #18
Source Project: HeyGirl   Author: mikusjelly   File: InstructionWriter.java    License: Apache License 2.0 5 votes vote down vote up
private int getReferenceIndex(ReferenceInstruction referenceInstruction) {
    switch (referenceInstruction.getOpcode().referenceType) {
        case ReferenceType.FIELD:
            return fieldSection.getItemIndex((FieldRefKey)referenceInstruction.getReference());
        case ReferenceType.METHOD:
            return methodSection.getItemIndex((MethodRefKey)referenceInstruction.getReference());
        case ReferenceType.STRING:
            return stringSection.getItemIndex((StringRef)referenceInstruction.getReference());
        case ReferenceType.TYPE:
            return typeSection.getItemIndex((TypeRef)referenceInstruction.getReference());
        default:
            throw new ExceptionWithContext("Unknown reference type: %d",
                    referenceInstruction.getOpcode().referenceType);
    }
}
 
Example #19
Source Project: HeyGirl   Author: mikusjelly   File: InstructionRewriter.java    License: Apache License 2.0 5 votes vote down vote up
@Override @Nonnull public Reference getReference() {
    switch (getReferenceType()) {
        case ReferenceType.TYPE:
            return RewriterUtils.rewriteTypeReference(rewriters.getTypeRewriter(),
                    (TypeReference)instruction.getReference());
        case ReferenceType.FIELD:
            return rewriters.getFieldReferenceRewriter().rewrite((FieldReference)instruction.getReference());
        case ReferenceType.METHOD:
            return rewriters.getMethodReferenceRewriter().rewrite((MethodReference)instruction.getReference());
        case ReferenceType.STRING:
            return instruction.getReference();
        default:
            throw new IllegalArgumentException();
    }
}
 
Example #20
Source Project: HeyGirl   Author: mikusjelly   File: DexBackedReference.java    License: Apache License 2.0 5 votes vote down vote up
public static Reference makeReference(@Nonnull DexBackedDexFile dexFile, int referenceType, int referenceIndex) {
    switch (referenceType) {
        case ReferenceType.STRING:
            return new DexBackedStringReference(dexFile, referenceIndex);
        case ReferenceType.TYPE:
            return new DexBackedTypeReference(dexFile, referenceIndex);
        case ReferenceType.METHOD:
            return new DexBackedMethodReference(dexFile, referenceIndex);
        case ReferenceType.FIELD:
            return new DexBackedFieldReference(dexFile, referenceIndex);
        default:
            throw new ExceptionWithContext("Invalid reference type: %d", referenceType);
    }
}
 
Example #21
Source Project: HeyGirl   Author: mikusjelly   File: Preconditions.java    License: Apache License 2.0 5 votes vote down vote up
public static <T extends Reference> T checkReference(int referenceType, T reference) {
    switch (referenceType) {
        case ReferenceType.STRING:
            if (!(reference instanceof StringReference)) {
                throw new IllegalArgumentException("Invalid reference type, expecting a string reference");
            }
            break;
        case ReferenceType.TYPE:
            if (!(reference instanceof TypeReference)) {
                throw new IllegalArgumentException("Invalid reference type, expecting a type reference");
            }
            break;
        case ReferenceType.FIELD:
            if (!(reference instanceof FieldReference)) {
                throw new IllegalArgumentException("Invalid reference type, expecting a field reference");
            }
            break;
        case ReferenceType.METHOD:
            if (!(reference instanceof MethodReference)) {
                throw new IllegalArgumentException("Invalid reference type, expecting a method reference");
            }
            break;
        default:
            throw new IllegalArgumentException(String.format("Not a valid reference type: %d", referenceType));
    }
    return reference;
}
 
Example #22
Source Project: ZjDroid   Author: halfkiss   File: ImmutableReferenceFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
public static ImmutableReference of(int referenceType, Reference reference) {
    switch (referenceType) {
        case ReferenceType.STRING:
            return ImmutableStringReference.of((StringReference)reference);
        case ReferenceType.TYPE:
            return ImmutableTypeReference.of((TypeReference)reference);
        case ReferenceType.FIELD:
            return ImmutableFieldReference.of((FieldReference)reference);
        case ReferenceType.METHOD:
            return ImmutableMethodReference.of((MethodReference)reference);
    }
    throw new ExceptionWithContext("Invalid reference type: %d", referenceType);
}
 
Example #23
Source Project: ZjDroid   Author: halfkiss   File: InstructionWriter.java    License: Apache License 2.0 5 votes vote down vote up
private int getReferenceIndex(ReferenceInstruction referenceInstruction) {
    switch (referenceInstruction.getOpcode().referenceType) {
        case ReferenceType.FIELD:
            return fieldSection.getItemIndex((FieldRefKey)referenceInstruction.getReference());
        case ReferenceType.METHOD:
            return methodSection.getItemIndex((MethodRefKey)referenceInstruction.getReference());
        case ReferenceType.STRING:
            return stringSection.getItemIndex((StringRef)referenceInstruction.getReference());
        case ReferenceType.TYPE:
            return typeSection.getItemIndex((TypeRef)referenceInstruction.getReference());
        default:
            throw new ExceptionWithContext("Unknown reference type: %d",
                    referenceInstruction.getOpcode().referenceType);
    }
}
 
Example #24
Source Project: ZjDroid   Author: halfkiss   File: InstructionRewriter.java    License: Apache License 2.0 5 votes vote down vote up
@Override @Nonnull public Reference getReference() {
    switch (getReferenceType()) {
        case ReferenceType.TYPE:
            return RewriterUtils.rewriteTypeReference(rewriters.getTypeRewriter(),
                    (TypeReference)instruction.getReference());
        case ReferenceType.FIELD:
            return rewriters.getFieldReferenceRewriter().rewrite((FieldReference)instruction.getReference());
        case ReferenceType.METHOD:
            return rewriters.getMethodReferenceRewriter().rewrite((MethodReference)instruction.getReference());
        case ReferenceType.STRING:
            return instruction.getReference();
        default:
            throw new IllegalArgumentException();
    }
}
 
Example #25
Source Project: ZjDroid   Author: halfkiss   File: DexBackedReference.java    License: Apache License 2.0 5 votes vote down vote up
public static Reference makeReference(@Nonnull DexBackedDexFile dexFile, int referenceType, int referenceIndex) {
    switch (referenceType) {
        case ReferenceType.STRING:
            return new DexBackedStringReference(dexFile, referenceIndex);
        case ReferenceType.TYPE:
            return new DexBackedTypeReference(dexFile, referenceIndex);
        case ReferenceType.METHOD:
            return new DexBackedMethodReference(dexFile, referenceIndex);
        case ReferenceType.FIELD:
            return new DexBackedFieldReference(dexFile, referenceIndex);
        default:
            throw new ExceptionWithContext("Invalid reference type: %d", referenceType);
    }
}
 
Example #26
Source Project: ZjDroid   Author: halfkiss   File: Preconditions.java    License: Apache License 2.0 5 votes vote down vote up
public static <T extends Reference> T checkReference(int referenceType, T reference) {
    switch (referenceType) {
        case ReferenceType.STRING:
            if (!(reference instanceof StringReference)) {
                throw new IllegalArgumentException("Invalid reference type, expecting a string reference");
            }
            break;
        case ReferenceType.TYPE:
            if (!(reference instanceof TypeReference)) {
                throw new IllegalArgumentException("Invalid reference type, expecting a type reference");
            }
            break;
        case ReferenceType.FIELD:
            if (!(reference instanceof FieldReference)) {
                throw new IllegalArgumentException("Invalid reference type, expecting a field reference");
            }
            break;
        case ReferenceType.METHOD:
            if (!(reference instanceof MethodReference)) {
                throw new IllegalArgumentException("Invalid reference type, expecting a method reference");
            }
            break;
        default:
            throw new IllegalArgumentException(String.format("Not a valid reference type: %d", referenceType));
    }
    return reference;
}
 
Example #27
Source Project: ZjDroid   Author: KB5201314   File: ClassPool.java    License: Apache License 2.0 4 votes vote down vote up
private void internCode(@Nonnull Method method) {
    // this also handles parameter names, which aren't directly tied to the MethodImplementation, even though the debug items are
    boolean hasInstruction = false;

    MethodImplementation methodImpl = method.getImplementation();
    if (methodImpl != null) {
        for (Instruction instruction: methodImpl.getInstructions()) {
            hasInstruction = true;
            if (instruction instanceof ReferenceInstruction) {
                Reference reference = ((ReferenceInstruction)instruction).getReference();
                switch (instruction.getOpcode().referenceType) {
                    case ReferenceType.STRING:
                        stringPool.intern((StringReference)reference);
                        break;
                    case ReferenceType.TYPE:
                        typePool.intern((TypeReference)reference);
                        break;
                    case ReferenceType.FIELD:
                        fieldPool.intern((FieldReference) reference);
                        break;
                    case ReferenceType.METHOD:
                        methodPool.intern((MethodReference)reference);
                        break;
                    default:
                        throw new ExceptionWithContext("Unrecognized reference type: %d",
                                instruction.getOpcode().referenceType);
                }
            }
        }

        List<? extends TryBlock> tryBlocks = methodImpl.getTryBlocks();
        if (!hasInstruction && tryBlocks.size() > 0) {
            throw new ExceptionWithContext("Method %s has no instructions, but has try blocks.",
                    ReferenceUtil.getMethodDescriptor(method));
        }

        for (TryBlock<? extends ExceptionHandler> tryBlock: methodImpl.getTryBlocks()) {
            for (ExceptionHandler handler: tryBlock.getExceptionHandlers()) {
                typePool.internNullable(handler.getExceptionType());
            }
        }
    }
}
 
Example #28
Source Project: ZjDroid   Author: KB5201314   File: DexBackedInstruction20bc.java    License: Apache License 2.0 4 votes vote down vote up
@Override public int getReferenceType() {
    int referenceType = (dexFile.readUbyte(instructionStart + 1) >>> 6) + 1;
    ReferenceType.validateReferenceType(referenceType);
    return referenceType;
}
 
Example #29
Source Project: ZjDroid   Author: KB5201314   File: SyntheticAccessCommentMethodItem.java    License: Apache License 2.0 4 votes vote down vote up
public boolean writeTo(IndentingWriter writer) throws IOException {
    writer.write("# ");
    switch (accessedMember.accessedMemberType) {
        case SyntheticAccessorResolver.METHOD:
            writer.write("invokes: ");
            break;
        case SyntheticAccessorResolver.GETTER:
            writer.write("getter for: ");
            break;
        case SyntheticAccessorResolver.SETTER:
            writer.write("setter for: ");
            break;
        case SyntheticAccessorResolver.PREFIX_INCREMENT:
            writer.write("++operator for: ");
            break;
        case SyntheticAccessorResolver.POSTFIX_INCREMENT:
            writer.write("operator++ for: ");
            break;
        case SyntheticAccessorResolver.PREFIX_DECREMENT:
            writer.write("--operator for: ");
            break;
        case SyntheticAccessorResolver.POSTFIX_DECREMENT:
            writer.write("operator-- for: ");
            break;
        case SyntheticAccessorResolver.ADD_ASSIGNMENT:
            writer.write("+= operator for: ");
            break;
        case SyntheticAccessorResolver.SUB_ASSIGNMENT:
            writer.write("-= operator for: ");
            break;
        case SyntheticAccessorResolver.MUL_ASSIGNMENT:
            writer.write("*= operator for: ");
            break;
        case SyntheticAccessorResolver.DIV_ASSIGNMENT:
            writer.write("/= operator for: ");
            break;
        case SyntheticAccessorResolver.REM_ASSIGNMENT:
            writer.write("%= operator for: ");
            break;
        case SyntheticAccessorResolver.AND_ASSIGNMENT:
            writer.write("&= operator for: ");
            break;
        case SyntheticAccessorResolver.OR_ASSIGNMENT:
            writer.write("|= operator for: ");
            break;
        case SyntheticAccessorResolver.XOR_ASSIGNMENT:
            writer.write("^= operator for: ");
            break;
        case SyntheticAccessorResolver.SHL_ASSIGNMENT:
            writer.write("<<= operator for: ");
            break;
        case SyntheticAccessorResolver.SHR_ASSIGNMENT:
            writer.write(">>= operator for: ");
            break;
        case SyntheticAccessorResolver.USHR_ASSIGNMENT:
            writer.write(">>>= operator for: ");
            break;
        default:
            throw new ExceptionWithContext("Unknown access type: %d", accessedMember.accessedMemberType);
    }

    int referenceType;
    if (accessedMember.accessedMemberType == SyntheticAccessorResolver.METHOD) {
        referenceType = ReferenceType.METHOD;
    } else {
        referenceType = ReferenceType.FIELD;
    }
    ReferenceFormatter.writeReference(writer, referenceType, accessedMember.accessedMember);
    return true;
}
 
Example #30
Source Project: apkfile   Author: CalebFenton   File: DexMethod.java    License: Apache License 2.0 4 votes vote down vote up
private void analyze(@Nonnull DexBackedMethodImplementation implementation) {
    debugItemCount = Utils.makeCollection(implementation.getDebugItems()).size();
    registerCount = implementation.getRegisterCount();
    tryCatchCount = implementation.getTryBlocks().size();

    for (Instruction instruction : implementation.getInstructions()) {
        instructionCount++;
        Opcode op = instruction.getOpcode();
        opCounts.adjustOrPutValue(op.apiToValueMap.get(DexFile.TARGET_API), 1, 1);

        if (instruction instanceof ReferenceInstruction) {
            ReferenceInstruction refInstr = (ReferenceInstruction) instruction;
            if (op.referenceType == ReferenceType.METHOD || op.referenceType == ReferenceType.FIELD) {
                boolean isApiPackage = false;
                for (String apiPackage : API_PACKAGES) {
                    String refStr = ReferenceUtil.getReferenceString(refInstr.getReference());
                    if (refStr.startsWith(apiPackage)) {
                        isApiPackage = true;
                        break;
                    }
                }
                if (!isApiPackage) {
                    continue;
                }
            }

            switch (op.referenceType) {
                case ReferenceType.METHOD:
                    MethodReference methodRef = (MethodReference) refInstr.getReference();
                    if (shortMethodSignatures) {
                        ShortMethodReference shortMethodRef = new ShortMethodReference(methodRef);
                        frameworkApiCounts.adjustOrPutValue(shortMethodRef, 1, 1);
                    } else {
                        frameworkApiCounts.adjustOrPutValue(methodRef, 1, 1);
                    }
                    break;
                case ReferenceType.FIELD:
                    FieldReference fieldRef = (FieldReference) refInstr.getReference();
                    frameworkFieldReferenceCounts.adjustOrPutValue(fieldRef, 1, 1);
                    break;
                case ReferenceType.STRING:
                    StringReference stringRef = (StringReference) refInstr.getReference();
                    stringReferenceCounts.adjustOrPutValue(stringRef, 1, 1);
                    break;
            }
        }
    }

    analyzeEntropy();
}