Java Code Examples for org.jf.dexlib2.iface.MethodImplementation#getInstructions()

The following examples show how to use org.jf.dexlib2.iface.MethodImplementation#getInstructions() . 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: ControlFlowGraph.java    From CFGScanDroid with GNU General Public License v2.0 6 votes vote down vote up
private static List<BasicBlockInstruction> getFlatMethod(Method method) {
	List<BasicBlockInstruction> flatMethod = new ArrayList<BasicBlockInstruction>();
	MethodImplementation impl = method.getImplementation();
	//List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = null;
	if(impl != null) {
		int address = 0;
		for(Instruction instruction: impl.getInstructions()) {
			BasicBlockInstruction bbinsn = new BasicBlockInstruction(address, instruction);
			//System.out.print("\t" + address + "\t" + instruction.getOpcode() + "\t" + bbinsn.branch);
			address += instruction.getCodeUnits();
			flatMethod.add(bbinsn);
		}
		//tryBlocks = impl.getTryBlocks();
	}

	return flatMethod;
}
 
Example 2
Source File: ImmutableMethodImplementation.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Nullable
public static ImmutableMethodImplementation of(@Nullable MethodImplementation methodImplementation) {
    if (methodImplementation == null) {
        return null;
    }
    if (methodImplementation instanceof ImmutableMethodImplementation) {
        return (ImmutableMethodImplementation)methodImplementation;
    }
    return new ImmutableMethodImplementation(
            methodImplementation.getRegisterCount(),
            methodImplementation.getInstructions(),
            methodImplementation.getTryBlocks(),
            methodImplementation.getDebugItems());
}
 
Example 3
Source File: BuilderClassPool.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Nullable @Override
public Iterable<? extends Instruction> getInstructions(@Nonnull BuilderMethod builderMethod) {
    MethodImplementation impl = builderMethod.getImplementation();
    if (impl == null) {
        return null;
    }
    return impl.getInstructions();
}
 
Example 4
Source File: MethodImplReIClassDef.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
protected MethodImplementation reMethodImpl(MethodImplementation methodImplementation) {
    if (methodImplementation == null){
        return null;
    }
    Iterable<? extends Instruction> instructions = methodImplementation.getInstructions();
    Iterable<? extends DebugItem> debugItems = methodImplementation.getDebugItems();
    List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = methodImplementation.getTryBlocks();
    return new ImmutableMethodImplementation(methodImplementation.getRegisterCount(), reInstructions(instructions), reTryCatchBlock(methodImplementation.getTryBlocks()), reDebugItem(methodImplementation.getDebugItems()));

}
 
Example 5
Source File: ImmutableMethodImplementation.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
@Nullable
public static ImmutableMethodImplementation of(@Nullable MethodImplementation methodImplementation) {
    if (methodImplementation == null) {
        return null;
    }
    if (methodImplementation instanceof ImmutableMethodImplementation) {
        return (ImmutableMethodImplementation)methodImplementation;
    }
    return new ImmutableMethodImplementation(
            methodImplementation.getRegisterCount(),
            methodImplementation.getInstructions(),
            methodImplementation.getTryBlocks(),
            methodImplementation.getDebugItems());
}
 
Example 6
Source File: BuilderClassPool.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
@Nullable @Override
public Iterable<? extends Instruction> getInstructions(@Nonnull BuilderMethod builderMethod) {
    MethodImplementation impl = builderMethod.getImplementation();
    if (impl == null) {
        return null;
    }
    return impl.getInstructions();
}
 
Example 7
Source File: ImmutableMethodImplementation.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
@Nullable
public static ImmutableMethodImplementation of(@Nullable MethodImplementation methodImplementation) {
    if (methodImplementation == null) {
        return null;
    }
    if (methodImplementation instanceof ImmutableMethodImplementation) {
        return (ImmutableMethodImplementation)methodImplementation;
    }
    return new ImmutableMethodImplementation(
            methodImplementation.getRegisterCount(),
            methodImplementation.getInstructions(),
            methodImplementation.getTryBlocks(),
            methodImplementation.getDebugItems());
}
 
Example 8
Source File: BuilderClassPool.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
@Nullable @Override
public Iterable<? extends Instruction> getInstructions(@Nonnull BuilderMethod builderMethod) {
    MethodImplementation impl = builderMethod.getImplementation();
    if (impl == null) {
        return null;
    }
    return impl.getInstructions();
}
 
Example 9
Source File: ImmutableMethodImplementation.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Nullable
public static ImmutableMethodImplementation of(@Nullable MethodImplementation methodImplementation) {
    if (methodImplementation == null) {
        return null;
    }
    if (methodImplementation instanceof ImmutableMethodImplementation) {
        return (ImmutableMethodImplementation)methodImplementation;
    }
    return new ImmutableMethodImplementation(
            methodImplementation.getRegisterCount(),
            methodImplementation.getInstructions(),
            methodImplementation.getTryBlocks(),
            methodImplementation.getDebugItems());
}
 
Example 10
Source File: BuilderClassPool.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Nullable @Override
public Iterable<? extends Instruction> getInstructions(@Nonnull BuilderMethod builderMethod) {
    MethodImplementation impl = builderMethod.getImplementation();
    if (impl == null) {
        return null;
    }
    return impl.getInstructions();
}
 
Example 11
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;
}