org.jf.dexlib2.util.MethodUtil Java Examples

The following examples show how to use org.jf.dexlib2.util.MethodUtil. 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 File: BuilderClassDef.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
BuilderClassDef(@Nonnull BuilderTypeReference type,
                int accessFlags,
                @Nullable BuilderTypeReference superclass,
                @Nonnull BuilderTypeList interfaces,
                @Nullable BuilderStringReference sourceFile,
                @Nonnull BuilderAnnotationSet annotations,
                @Nullable Iterable<? extends BuilderField> fields,
                @Nullable Iterable<? extends BuilderMethod> methods) {
    if (fields == null) {
        fields = ImmutableList.of();
    }
    if (methods == null) {
        methods = ImmutableList.of();
    }

    this.type = type;
    this.accessFlags = accessFlags;
    this.superclass = superclass;
    this.interfaces = interfaces;
    this.sourceFile = sourceFile;
    this.annotations = annotations;
    this.staticFields = ImmutableSortedSet.copyOf(Iterables.filter(fields, FieldUtil.FIELD_IS_STATIC));
    this.instanceFields = ImmutableSortedSet.copyOf(Iterables.filter(fields, FieldUtil.FIELD_IS_INSTANCE));
    this.directMethods = ImmutableSortedSet.copyOf(Iterables.filter(methods, MethodUtil.METHOD_IS_DIRECT));
    this.virtualMethods = ImmutableSortedSet.copyOf(Iterables.filter(methods, MethodUtil.METHOD_IS_VIRTUAL));
}
 
Example #2
Source File: ImmutableClassDef.java    From zjdroid with Apache License 2.0 6 votes vote down vote up
public ImmutableClassDef(@Nonnull String type,
                         int accessFlags,
                         @Nullable String superclass,
                         @Nullable Collection<String> interfaces,
                         @Nullable String sourceFile,
                         @Nullable Collection<? extends Annotation> annotations,
                         @Nullable Iterable<? extends Field> fields,
                         @Nullable Iterable<? extends Method> methods) {
    if (fields == null) {
        fields = ImmutableList.of();
    }
    if (methods == null) {
        methods = ImmutableList.of();
    }

    this.type = type;
    this.accessFlags = accessFlags;
    this.superclass = superclass;
    this.interfaces = interfaces==null ? ImmutableSet.<String>of() : ImmutableSet.copyOf(interfaces);
    this.sourceFile = sourceFile;
    this.annotations = ImmutableAnnotation.immutableSetOf(annotations);
    this.staticFields = ImmutableField.immutableSetOf(Iterables.filter(fields, FieldUtil.FIELD_IS_STATIC));
    this.instanceFields = ImmutableField.immutableSetOf(Iterables.filter(fields, FieldUtil.FIELD_IS_INSTANCE));
    this.directMethods = ImmutableMethod.immutableSetOf(Iterables.filter(methods, MethodUtil.METHOD_IS_DIRECT));
    this.virtualMethods = ImmutableMethod.immutableSetOf(Iterables.filter(methods, MethodUtil.METHOD_IS_VIRTUAL));
}
 
Example #3
Source File: BuilderClassDef.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
BuilderClassDef(@Nonnull BuilderTypeReference type,
                int accessFlags,
                @Nullable BuilderTypeReference superclass,
                @Nonnull BuilderTypeList interfaces,
                @Nullable BuilderStringReference sourceFile,
                @Nonnull BuilderAnnotationSet annotations,
                @Nullable Iterable<? extends BuilderField> fields,
                @Nullable Iterable<? extends BuilderMethod> methods) {
    if (fields == null) {
        fields = ImmutableList.of();
    }
    if (methods == null) {
        methods = ImmutableList.of();
    }

    this.type = type;
    this.accessFlags = accessFlags;
    this.superclass = superclass;
    this.interfaces = interfaces;
    this.sourceFile = sourceFile;
    this.annotations = annotations;
    this.staticFields = ImmutableSortedSet.copyOf(Iterables.filter(fields, FieldUtil.FIELD_IS_STATIC));
    this.instanceFields = ImmutableSortedSet.copyOf(Iterables.filter(fields, FieldUtil.FIELD_IS_INSTANCE));
    this.directMethods = ImmutableSortedSet.copyOf(Iterables.filter(methods, MethodUtil.METHOD_IS_DIRECT));
    this.virtualMethods = ImmutableSortedSet.copyOf(Iterables.filter(methods, MethodUtil.METHOD_IS_VIRTUAL));
}
 
Example #4
Source File: BuilderClassDef.java    From zjdroid with Apache License 2.0 6 votes vote down vote up
BuilderClassDef(@Nonnull BuilderTypeReference type,
                int accessFlags,
                @Nullable BuilderTypeReference superclass,
                @Nonnull BuilderTypeList interfaces,
                @Nullable BuilderStringReference sourceFile,
                @Nonnull BuilderAnnotationSet annotations,
                @Nullable Iterable<? extends BuilderField> fields,
                @Nullable Iterable<? extends BuilderMethod> methods) {
    if (fields == null) {
        fields = ImmutableList.of();
    }
    if (methods == null) {
        methods = ImmutableList.of();
    }

    this.type = type;
    this.accessFlags = accessFlags;
    this.superclass = superclass;
    this.interfaces = interfaces;
    this.sourceFile = sourceFile;
    this.annotations = annotations;
    this.staticFields = ImmutableSortedSet.copyOf(Iterables.filter(fields, FieldUtil.FIELD_IS_STATIC));
    this.instanceFields = ImmutableSortedSet.copyOf(Iterables.filter(fields, FieldUtil.FIELD_IS_INSTANCE));
    this.directMethods = ImmutableSortedSet.copyOf(Iterables.filter(methods, MethodUtil.METHOD_IS_DIRECT));
    this.virtualMethods = ImmutableSortedSet.copyOf(Iterables.filter(methods, MethodUtil.METHOD_IS_VIRTUAL));
}
 
Example #5
Source File: ImmutableClassDef.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
public ImmutableClassDef(@Nonnull String type,
                         int accessFlags,
                         @Nullable String superclass,
                         @Nullable Collection<String> interfaces,
                         @Nullable String sourceFile,
                         @Nullable Collection<? extends Annotation> annotations,
                         @Nullable Iterable<? extends Field> fields,
                         @Nullable Iterable<? extends Method> methods) {
    if (fields == null) {
        fields = ImmutableList.of();
    }
    if (methods == null) {
        methods = ImmutableList.of();
    }

    this.type = type;
    this.accessFlags = accessFlags;
    this.superclass = superclass;
    this.interfaces = interfaces==null ? ImmutableSet.<String>of() : ImmutableSet.copyOf(interfaces);
    this.sourceFile = sourceFile;
    this.annotations = ImmutableAnnotation.immutableSetOf(annotations);
    this.staticFields = ImmutableField.immutableSetOf(Iterables.filter(fields, FieldUtil.FIELD_IS_STATIC));
    this.instanceFields = ImmutableField.immutableSetOf(Iterables.filter(fields, FieldUtil.FIELD_IS_INSTANCE));
    this.directMethods = ImmutableMethod.immutableSetOf(Iterables.filter(methods, MethodUtil.METHOD_IS_DIRECT));
    this.virtualMethods = ImmutableMethod.immutableSetOf(Iterables.filter(methods, MethodUtil.METHOD_IS_VIRTUAL));
}
 
Example #6
Source File: ImmutableClassDef.java    From HeyGirl with Apache License 2.0 6 votes vote down vote up
public ImmutableClassDef(@Nonnull String type,
                         int accessFlags,
                         @Nullable String superclass,
                         @Nullable Collection<String> interfaces,
                         @Nullable String sourceFile,
                         @Nullable Collection<? extends Annotation> annotations,
                         @Nullable Iterable<? extends Field> fields,
                         @Nullable Iterable<? extends Method> methods) {
    if (fields == null) {
        fields = ImmutableList.of();
    }
    if (methods == null) {
        methods = ImmutableList.of();
    }

    this.type = type;
    this.accessFlags = accessFlags;
    this.superclass = superclass;
    this.interfaces = interfaces==null ? ImmutableSet.<String>of() : ImmutableSet.copyOf(interfaces);
    this.sourceFile = sourceFile;
    this.annotations = ImmutableAnnotation.immutableSetOf(annotations);
    this.staticFields = ImmutableField.immutableSetOf(Iterables.filter(fields, FieldUtil.FIELD_IS_STATIC));
    this.instanceFields = ImmutableField.immutableSetOf(Iterables.filter(fields, FieldUtil.FIELD_IS_INSTANCE));
    this.directMethods = ImmutableMethod.immutableSetOf(Iterables.filter(methods, MethodUtil.METHOD_IS_DIRECT));
    this.virtualMethods = ImmutableMethod.immutableSetOf(Iterables.filter(methods, MethodUtil.METHOD_IS_VIRTUAL));
}
 
Example #7
Source File: BuilderClassDef.java    From HeyGirl with Apache License 2.0 6 votes vote down vote up
BuilderClassDef(@Nonnull BuilderTypeReference type,
                int accessFlags,
                @Nullable BuilderTypeReference superclass,
                @Nonnull BuilderTypeList interfaces,
                @Nullable BuilderStringReference sourceFile,
                @Nonnull BuilderAnnotationSet annotations,
                @Nullable Iterable<? extends BuilderField> fields,
                @Nullable Iterable<? extends BuilderMethod> methods) {
    if (fields == null) {
        fields = ImmutableList.of();
    }
    if (methods == null) {
        methods = ImmutableList.of();
    }

    this.type = type;
    this.accessFlags = accessFlags;
    this.superclass = superclass;
    this.interfaces = interfaces;
    this.sourceFile = sourceFile;
    this.annotations = annotations;
    this.staticFields = ImmutableSortedSet.copyOf(Iterables.filter(fields, FieldUtil.FIELD_IS_STATIC));
    this.instanceFields = ImmutableSortedSet.copyOf(Iterables.filter(fields, FieldUtil.FIELD_IS_INSTANCE));
    this.directMethods = ImmutableSortedSet.copyOf(Iterables.filter(methods, MethodUtil.METHOD_IS_DIRECT));
    this.virtualMethods = ImmutableSortedSet.copyOf(Iterables.filter(methods, MethodUtil.METHOD_IS_VIRTUAL));
}
 
Example #8
Source File: ImmutableClassDef.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
public ImmutableClassDef(@Nonnull String type,
                         int accessFlags,
                         @Nullable String superclass,
                         @Nullable Collection<String> interfaces,
                         @Nullable String sourceFile,
                         @Nullable Collection<? extends Annotation> annotations,
                         @Nullable Iterable<? extends Field> fields,
                         @Nullable Iterable<? extends Method> methods) {
    if (fields == null) {
        fields = ImmutableList.of();
    }
    if (methods == null) {
        methods = ImmutableList.of();
    }

    this.type = type;
    this.accessFlags = accessFlags;
    this.superclass = superclass;
    this.interfaces = interfaces==null ? ImmutableSet.<String>of() : ImmutableSet.copyOf(interfaces);
    this.sourceFile = sourceFile;
    this.annotations = ImmutableAnnotation.immutableSetOf(annotations);
    this.staticFields = ImmutableField.immutableSetOf(Iterables.filter(fields, FieldUtil.FIELD_IS_STATIC));
    this.instanceFields = ImmutableField.immutableSetOf(Iterables.filter(fields, FieldUtil.FIELD_IS_INSTANCE));
    this.directMethods = ImmutableMethod.immutableSetOf(Iterables.filter(methods, MethodUtil.METHOD_IS_DIRECT));
    this.virtualMethods = ImmutableMethod.immutableSetOf(Iterables.filter(methods, MethodUtil.METHOD_IS_VIRTUAL));
}
 
Example #9
Source File: BuilderProtoPool.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Nonnull public BuilderProtoReference internProto(@Nonnull List<? extends CharSequence> parameters,
                                                  @Nonnull String returnType) {
    ProtoKey key = new Key(parameters, returnType);
    BuilderProtoReference ret = internedItems.get(key);
    if (ret != null) {
        return ret;
    }

    BuilderProtoReference protoReference = new BuilderProtoReference(
            context.stringPool.internString(MethodUtil.getShorty(parameters, returnType)),
            context.typeListPool.internTypeList(parameters),
            context.typePool.internType(returnType));
    ret = internedItems.putIfAbsent(protoReference, protoReference);
    return ret==null?protoReference:ret;
}
 
Example #10
Source File: BuilderProtoPool.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Nonnull public BuilderProtoReference internProto(@Nonnull List<? extends CharSequence> parameters,
                                                  @Nonnull String returnType) {
    ProtoKey key = new Key(parameters, returnType);
    BuilderProtoReference ret = internedItems.get(key);
    if (ret != null) {
        return ret;
    }

    BuilderProtoReference protoReference = new BuilderProtoReference(
            context.stringPool.internString(MethodUtil.getShorty(parameters, returnType)),
            context.typeListPool.internTypeList(parameters),
            context.typePool.internType(returnType));
    ret = internedItems.putIfAbsent(protoReference, protoReference);
    return ret==null?protoReference:ret;
}
 
Example #11
Source File: BuilderProtoPool.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
@Nonnull public BuilderProtoReference internProto(@Nonnull List<? extends CharSequence> parameters,
                                                  @Nonnull String returnType) {
    ProtoKey key = new Key(parameters, returnType);
    BuilderProtoReference ret = internedItems.get(key);
    if (ret != null) {
        return ret;
    }

    BuilderProtoReference protoReference = new BuilderProtoReference(
            context.stringPool.internString(MethodUtil.getShorty(parameters, returnType)),
            context.typeListPool.internTypeList(parameters),
            context.typePool.internType(returnType));
    ret = internedItems.putIfAbsent(protoReference, protoReference);
    return ret==null?protoReference:ret;
}
 
Example #12
Source File: BuilderProtoPool.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
@Nonnull public BuilderProtoReference internProto(@Nonnull List<? extends CharSequence> parameters,
                                                  @Nonnull String returnType) {
    ProtoKey key = new Key(parameters, returnType);
    BuilderProtoReference ret = internedItems.get(key);
    if (ret != null) {
        return ret;
    }

    BuilderProtoReference protoReference = new BuilderProtoReference(
            context.stringPool.internString(MethodUtil.getShorty(parameters, returnType)),
            context.typeListPool.internTypeList(parameters),
            context.typePool.internType(returnType));
    ret = internedItems.putIfAbsent(protoReference, protoReference);
    return ret==null?protoReference:ret;
}
 
Example #13
Source File: DexBody.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param code the codeitem that is contained in this body
 * @param method the method that is associated with this body
 */
public DexBody(DexFile dexFile, Method method, RefType declaringClassType) {
    MethodImplementation code = method.getImplementation();
    if (code == null)
        throw new RuntimeException("error: no code for method "+ method.getName());
    this.declaringClassType = declaringClassType;
    tries = code.getTryBlocks();
    methodSignature = method.getDefiningClass() +": "+ method.getReturnType() +" "+ method.getName() +"(";
    for (MethodParameter mp: method.getParameters())
        methodSignature += mp.getType() +",";

    List<? extends CharSequence> paramTypes = method.getParameterTypes();
    if (paramTypes != null) {
        parameterTypes = new ArrayList<Type>();
        for (CharSequence type : paramTypes)
            parameterTypes.add(DexType.toSoot(type.toString()));
    } else {
    	parameterTypes = Collections.emptyList();
    }
    
    isStatic = Modifier.isStatic(method.getAccessFlags());
    numRegisters = code.getRegisterCount();
    numParameterRegisters = MethodUtil.getParameterRegisterCount(method);
    if (!isStatic)
        numParameterRegisters--;

    instructions = new ArrayList<DexlibAbstractInstruction>();
    instructionAtAddress = new HashMap<Integer, DexlibAbstractInstruction>();

    registerLocals = new Local[numRegisters];

    int address = 0;
    
    for (Instruction instruction : code.getInstructions()) {
        DexlibAbstractInstruction dexInstruction = fromInstruction(instruction, address);
        instructions.add(dexInstruction);
        instructionAtAddress.put(address, dexInstruction);
        Debug.printDbg(" put instruction '", dexInstruction ,"' at 0x", Integer.toHexString(address));
        address += instruction.getCodeUnits();
    }
    
    // Check taken from Android's dalvik/libdex/DexSwapVerify.cpp
    if (numParameterRegisters > numRegisters)
    	throw new RuntimeException("Malformed dex file: insSize (" + numParameterRegisters
    			+ ") > registersSize (" + numRegisters + ")");
    
    for (DebugItem di: code.getDebugItems()) {
        if (di instanceof ImmutableLineNumber) {
            ImmutableLineNumber ln = (ImmutableLineNumber)di;
            DexlibAbstractInstruction ins = instructionAtAddress(ln.getCodeAddress());
            if (ins == null) {
            	Debug.printDbg("Line number tag pointing to invalid offset: " + ln.getCodeAddress());
            	continue;
            }
            ins.setLineNumber(ln.getLineNumber());
            Debug.printDbg("Add line number tag " + ln.getLineNumber() + " for instruction: "
                    + instructionAtAddress(ln.getCodeAddress()));
        }
    }

    this.dexFile = dexFile;
}
 
Example #14
Source File: ProtoPool.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
public String getShorty() {
    return MethodUtil.getShorty(method.getParameterTypes(), method.getReturnType());
}
 
Example #15
Source File: ProtoPool.java    From HeyGirl with Apache License 2.0 4 votes vote down vote up
public String getShorty() {
    return MethodUtil.getShorty(method.getParameterTypes(), method.getReturnType());
}
 
Example #16
Source File: ProtoPool.java    From zjdroid with Apache License 2.0 4 votes vote down vote up
public String getShorty() {
    return MethodUtil.getShorty(method.getParameterTypes(), method.getReturnType());
}
 
Example #17
Source File: ProtoPool.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
public String getShorty() {
    return MethodUtil.getShorty(method.getParameterTypes(), method.getReturnType());
}