org.jf.dexlib2.Opcode Java Examples

The following examples show how to use org.jf.dexlib2.Opcode. 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: ImmutableInstruction35c.java    From zjdroid with Apache License 2.0 6 votes vote down vote up
public ImmutableInstruction35c(@Nonnull Opcode opcode,
                               int registerCount,
                               int registerC,
                               int registerD,
                               int registerE,
                               int registerF,
                               int registerG,
                               @Nonnull Reference reference) {
    super(opcode);
    this.registerCount = Preconditions.check35cRegisterCount(registerCount);
    this.registerC = (registerCount>0) ? Preconditions.checkNibbleRegister(registerC) : 0;
    this.registerD = (registerCount>1) ? Preconditions.checkNibbleRegister(registerD) : 0;
    this.registerE = (registerCount>2) ? Preconditions.checkNibbleRegister(registerE) : 0;
    this.registerF = (registerCount>3) ? Preconditions.checkNibbleRegister(registerF) : 0;
    this.registerG = (registerCount>4) ? Preconditions.checkNibbleRegister(registerG) : 0;
    this.reference = ImmutableReferenceFactory.of(opcode.referenceType, reference);
}
 
Example #2
Source File: MethodAnalyzer.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
private void analyzeInvokeObjectInitRange(@Nonnull AnalyzedInstruction analyzedInstruction, boolean analyzeResult) {
    Instruction3rc instruction = (Instruction3rc)analyzedInstruction.instruction;

    Instruction deodexedInstruction;

    int startRegister = instruction.getStartRegister();
    // hack: we should be using instruction.getRegisterCount, but some tweaked versions of dalvik appear
    // to generate invoke-object-init/range instructions with an invalid register count. We know it should
    // always be 1, so just use that.
    int registerCount = 1;
    if (startRegister < 16) {
        deodexedInstruction = new ImmutableInstruction35c(Opcode.INVOKE_DIRECT,
                registerCount, startRegister, 0, 0, 0, 0, instruction.getReference());
    } else {
        deodexedInstruction = new ImmutableInstruction3rc(Opcode.INVOKE_DIRECT_RANGE,
                startRegister, registerCount, instruction.getReference());
    }

    analyzedInstruction.setDeodexedInstruction(deodexedInstruction);

    if (analyzeResult) {
        analyzeInstruction(analyzedInstruction);
    }
}
 
Example #3
Source File: MethodAnalyzer.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
private void analyzeExecuteInline(@Nonnull AnalyzedInstruction analyzedInstruction) {
    if (inlineResolver == null) {
        throw new AnalysisException("Cannot analyze an odexed instruction unless we are deodexing");
    }

    Instruction35mi instruction = (Instruction35mi)analyzedInstruction.instruction;
    Method resolvedMethod = inlineResolver.resolveExecuteInline(analyzedInstruction);

    Opcode deodexedOpcode;
    int acccessFlags = resolvedMethod.getAccessFlags();
    if (AccessFlags.STATIC.isSet(acccessFlags)) {
        deodexedOpcode = Opcode.INVOKE_STATIC;
    } else if (AccessFlags.PRIVATE.isSet(acccessFlags)) {
        deodexedOpcode = Opcode.INVOKE_DIRECT;
    } else {
        deodexedOpcode = Opcode.INVOKE_VIRTUAL;
    }

    Instruction35c deodexedInstruction = new ImmutableInstruction35c(deodexedOpcode, instruction.getRegisterCount(),
            instruction.getRegisterC(), instruction.getRegisterD(), instruction.getRegisterE(),
            instruction.getRegisterF(), instruction.getRegisterG(), resolvedMethod);

    analyzedInstruction.setDeodexedInstruction(deodexedInstruction);
    analyzeInstruction(analyzedInstruction);
}
 
Example #4
Source File: MethodAnalyzer.java    From HeyGirl with Apache License 2.0 6 votes vote down vote up
private void analyzeExecuteInline(@Nonnull AnalyzedInstruction analyzedInstruction) {
    if (inlineResolver == null) {
        throw new AnalysisException("Cannot analyze an odexed instruction unless we are deodexing");
    }

    Instruction35mi instruction = (Instruction35mi)analyzedInstruction.instruction;
    Method resolvedMethod = inlineResolver.resolveExecuteInline(analyzedInstruction);

    Opcode deodexedOpcode;
    int acccessFlags = resolvedMethod.getAccessFlags();
    if (AccessFlags.STATIC.isSet(acccessFlags)) {
        deodexedOpcode = Opcode.INVOKE_STATIC;
    } else if (AccessFlags.PRIVATE.isSet(acccessFlags)) {
        deodexedOpcode = Opcode.INVOKE_DIRECT;
    } else {
        deodexedOpcode = Opcode.INVOKE_VIRTUAL;
    }

    Instruction35c deodexedInstruction = new ImmutableInstruction35c(deodexedOpcode, instruction.getRegisterCount(),
            instruction.getRegisterC(), instruction.getRegisterD(), instruction.getRegisterE(),
            instruction.getRegisterF(), instruction.getRegisterG(), resolvedMethod);

    analyzedInstruction.setDeodexedInstruction(deodexedInstruction);
    analyzeInstruction(analyzedInstruction);
}
 
Example #5
Source File: MutableMethodImplementation.java    From HeyGirl with Apache License 2.0 6 votes vote down vote up
@Nonnull
private BuilderInstruction31t newBuilderInstruction31t(@Nonnull MethodLocation location , int[] codeAddressToIndex,
                                                       @Nonnull Instruction31t instruction) {
    int codeAddress = location.getCodeAddress();
    Label newLabel;
    if (instruction.getOpcode() != Opcode.FILL_ARRAY_DATA) {
        // if it's a sparse switch or packed switch
        newLabel = newSwitchPayloadReferenceLabel(location, codeAddressToIndex, codeAddress + instruction.getCodeOffset());
    } else {
        newLabel = newLabel(codeAddressToIndex, codeAddress + instruction.getCodeOffset());
    }
    return new BuilderInstruction31t(
            instruction.getOpcode(),
            instruction.getRegisterA(),
            newLabel);
}
 
Example #6
Source File: MethodAnalyzer.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
private void analyzeInvokeObjectInitRange(@Nonnull AnalyzedInstruction analyzedInstruction, boolean analyzeResult) {
    Instruction3rc instruction = (Instruction3rc)analyzedInstruction.instruction;

    Instruction deodexedInstruction;

    int startRegister = instruction.getStartRegister();
    // hack: we should be using instruction.getRegisterCount, but some tweaked versions of dalvik appear
    // to generate invoke-object-init/range instructions with an invalid register count. We know it should
    // always be 1, so just use that.
    int registerCount = 1;
    if (startRegister < 16) {
        deodexedInstruction = new ImmutableInstruction35c(Opcode.INVOKE_DIRECT,
                registerCount, startRegister, 0, 0, 0, 0, instruction.getReference());
    } else {
        deodexedInstruction = new ImmutableInstruction3rc(Opcode.INVOKE_DIRECT_RANGE,
                startRegister, registerCount, instruction.getReference());
    }

    analyzedInstruction.setDeodexedInstruction(deodexedInstruction);

    if (analyzeResult) {
        analyzeInstruction(analyzedInstruction);
    }
}
 
Example #7
Source File: ImmutableInstruction35ms.java    From zjdroid with Apache License 2.0 6 votes vote down vote up
public ImmutableInstruction35ms(@Nonnull Opcode opcode,
                                int registerCount,
                                int registerC,
                                int registerD,
                                int registerE,
                                int registerF,
                                int registerG,
                                int vtableIndex) {
    super(opcode);
    this.registerCount = Preconditions.check35cRegisterCount(registerCount);
    this.registerC = (registerCount>0) ? Preconditions.checkNibbleRegister(registerC) : 0;
    this.registerD = (registerCount>1) ? Preconditions.checkNibbleRegister(registerD) : 0;
    this.registerE = (registerCount>2) ? Preconditions.checkNibbleRegister(registerE) : 0;
    this.registerF = (registerCount>3) ? Preconditions.checkNibbleRegister(registerF) : 0;
    this.registerG = (registerCount>4) ? Preconditions.checkNibbleRegister(registerG) : 0;
    this.vtableIndex = Preconditions.checkVtableIndex(vtableIndex);
}
 
Example #8
Source File: MethodAnalyzer.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
private void analyzeExecuteInlineRange(@Nonnull AnalyzedInstruction analyzedInstruction) {
    if (inlineResolver == null) {
        throw new AnalysisException("Cannot analyze an odexed instruction unless we are deodexing");
    }

    Instruction3rmi instruction = (Instruction3rmi)analyzedInstruction.instruction;
    Method resolvedMethod = inlineResolver.resolveExecuteInline(analyzedInstruction);

    Opcode deodexedOpcode;
    int acccessFlags = resolvedMethod.getAccessFlags();
    if (AccessFlags.STATIC.isSet(acccessFlags)) {
        deodexedOpcode = Opcode.INVOKE_STATIC_RANGE;
    } else if (AccessFlags.PRIVATE.isSet(acccessFlags)) {
        deodexedOpcode = Opcode.INVOKE_DIRECT_RANGE;
    } else {
        deodexedOpcode = Opcode.INVOKE_VIRTUAL_RANGE;
    }

    Instruction3rc deodexedInstruction = new ImmutableInstruction3rc(deodexedOpcode, instruction.getStartRegister(),
            instruction.getRegisterCount(), resolvedMethod);

    analyzedInstruction.setDeodexedInstruction(deodexedInstruction);
    analyzeInstruction(analyzedInstruction);
}
 
Example #9
Source File: MethodImplementationTranslator.java    From PATDroid with Apache License 2.0 6 votes vote down vote up
private Instruction translateNew(final Instruction31t i1) {
    final Instruction i = new Instruction();
    i.opcode = Instruction.OP_NEW;
    i.opcode_aux = Instruction.OP_NEW_FILLED_ARRAY;
    i.rdst = (short) i1.getRegisterA();
    final int payloadAddress = currentCodeAddress + i1.getCodeOffset();
    PayloadInstruction p = payloadCache.get(payloadAddress);
    if (p != null) {
        checkState(p.getOpcode() == Opcode.ARRAY_PAYLOAD, "payload type mismatch");
        applyPayload(i, (ArrayPayload)p);
    } else {
        ArrayList<Instruction> defers = payloadDefers.get(payloadAddress);
        if (defers == null) {
            defers = new ArrayList<Instruction>();
            payloadDefers.put(payloadAddress, defers);
        }
        defers.add(i);
    }
    return i;
}
 
Example #10
Source File: ImmutableInstruction21ih.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
public ImmutableInstruction21ih(@Nonnull Opcode opcode,
                                int registerA,
                                int literal) {
    super(opcode);
    this.registerA = Preconditions.checkByteRegister(registerA);
    this.literal = Preconditions.checkIntegerHatLiteral(literal);
}
 
Example #11
Source File: BuilderInstruction22x.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
public BuilderInstruction22x(@Nonnull Opcode opcode,
                             int registerA,
                             int registerB) {
    super(opcode);
    this.registerA = Preconditions.checkByteRegister(registerA);
    this.registerB = Preconditions.checkShortRegister(registerB);
}
 
Example #12
Source File: ImmutableInstruction21ih.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public ImmutableInstruction21ih(@Nonnull Opcode opcode,
                                int registerA,
                                int literal) {
    super(opcode);
    this.registerA = Preconditions.checkByteRegister(registerA);
    this.literal = Preconditions.checkIntegerHatLiteral(literal);
}
 
Example #13
Source File: ImmutableInstruction12x.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
public ImmutableInstruction12x(@Nonnull Opcode opcode,
                               int registerA,
                               int registerB) {
    super(opcode);
    this.registerA = Preconditions.checkNibbleRegister(registerA);
    this.registerB = Preconditions.checkNibbleRegister(registerB);
}
 
Example #14
Source File: ImmutableInstruction23x.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
public ImmutableInstruction23x(@Nonnull Opcode opcode,
                               int registerA,
                               int registerB,
                               int registerC) {
    super(opcode);
    this.registerA = Preconditions.checkByteRegister(registerA);
    this.registerB = Preconditions.checkByteRegister(registerB);
    this.registerC = Preconditions.checkByteRegister(registerC);
}
 
Example #15
Source File: ImmutableInstruction21ih.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public ImmutableInstruction21ih(@Nonnull Opcode opcode,
                                int registerA,
                                int literal) {
    super(opcode);
    this.registerA = Preconditions.checkByteRegister(registerA);
    this.literal = Preconditions.checkIntegerHatLiteral(literal);
}
 
Example #16
Source File: ExprVisitor.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void caseNewArrayExpr(NewArrayExpr nae) {
	Value size = nae.getSize();
	constantV.setOrigStmt(origStmt);
	Register sizeReg = regAlloc.asImmediate(size, constantV);
	ArrayType arrayType = nae.getBaseType().getArrayType();
	BuilderReference arrayTypeItem = DexPrinter.toTypeReference
			(arrayType, stmtV.getBelongingFile());
       stmtV.addInsn(new Insn22c(Opcode.NEW_ARRAY, destinationReg, sizeReg, arrayTypeItem), origStmt);
}
 
Example #17
Source File: BuilderInstruction23x.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public BuilderInstruction23x(@Nonnull Opcode opcode,
                             int registerA,
                             int registerB,
                             int registerC) {
    super(opcode);
    this.registerA = Preconditions.checkByteRegister(registerA);
    this.registerB = Preconditions.checkByteRegister(registerB);
    this.registerC = Preconditions.checkByteRegister(registerC);
}
 
Example #18
Source File: MethodAnalyzer.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
private void analyzeReturnVoidBarrier(@Nonnull AnalyzedInstruction analyzedInstruction, boolean analyzeResult) {
    Instruction10x deodexedInstruction = new ImmutableInstruction10x(Opcode.RETURN_VOID);

    analyzedInstruction.setDeodexedInstruction(deodexedInstruction);

    if (analyzeResult) {
        analyzeInstruction(analyzedInstruction);
    }
}
 
Example #19
Source File: ImmutableInstructionFactory.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
public ImmutableInstruction35c makeInstruction35c(@Nonnull Opcode opcode,
                                                  int registerCount,
                                                  int registerC,
                                                  int registerD,
                                                  int registerE,
                                                  int registerF,
                                                  int registerG,
                                                  @Nonnull Reference reference) {
    return new ImmutableInstruction35c(opcode, registerCount, registerC, registerD, registerE, registerF, registerG,
            reference);
}
 
Example #20
Source File: MethodDefinition.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
public int findSwitchPayload(int targetOffset, Opcode type) {
    int targetIndex;
    try {
        targetIndex = instructionOffsetMap.getInstructionIndexAtCodeOffset(targetOffset);
    } catch (InvalidInstructionOffset ex) {
        throw new InvalidSwitchPayload(targetOffset);
    }

    //TODO: does dalvik let you pad with multiple nops?
    //TODO: does dalvik let a switch instruction point to a non-payload instruction?

    Instruction instruction = instructions.get(targetIndex);
    if (instruction.getOpcode() != type) {
        // maybe it's pointing to a NOP padding instruction. Look at the next instruction
        if (instruction.getOpcode() == Opcode.NOP) {
            targetIndex += 1;
            if (targetIndex < instructions.size()) {
                instruction = instructions.get(targetIndex);
                if (instruction.getOpcode() == type) {
                    return instructionOffsetMap.getInstructionCodeOffset(targetIndex);
                }
            }
        }
        throw new InvalidSwitchPayload(targetOffset);
    } else {
        return targetOffset;
    }
}
 
Example #21
Source File: BuilderInstruction22b.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public BuilderInstruction22b(@Nonnull Opcode opcode,
                             int registerA,
                             int registerB,
                             int literal) {
    super(opcode);
    this.registerA = Preconditions.checkByteRegister(registerA);
    this.registerB = Preconditions.checkByteRegister(registerB);
    this.literal = Preconditions.checkByteLiteral(literal);
}
 
Example #22
Source File: BuilderInstruction31c.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public BuilderInstruction31c(@Nonnull Opcode opcode,
                             int registerA,
                             @Nonnull Reference reference) {
    super(opcode);
    this.registerA = Preconditions.checkByteRegister(registerA);
    this.reference = reference;
}
 
Example #23
Source File: OdexedFieldInstructionMapper.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
private static int getOpcodeSubtype(@Nonnull Opcode opcode) {
    if (opcode.isOdexedInstanceQuick()) {
        return 0;
    } else if (opcode.isOdexedInstanceVolatile()) {
        return 1;
    } else if (opcode.isOdexedStaticVolatile()) {
        return 2;
    }
    throw new RuntimeException(String.format("Not an odexed field access opcode: %s", opcode.name));
}
 
Example #24
Source File: BuilderInstruction3rc.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public BuilderInstruction3rc(@Nonnull Opcode opcode,
                             int startRegister,
                             int registerCount,
                             @Nonnull Reference reference) {
    super(opcode);
    this.startRegister = Preconditions.checkShortRegister(startRegister);
    this.registerCount = Preconditions.checkRegisterRangeCount(registerCount);
    this.reference = reference;
}
 
Example #25
Source File: StmtVisitor.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private Insn buildSwitchInsn(Opcode opc, Value key, Stmt defaultTarget,
		SwitchPayload payload, Stmt stmt) {
	Register keyReg = regAlloc.asImmediate(key, constantV);
	Insn31t switchInsn = new Insn31t(opc, keyReg);
	switchInsn.setPayload(payload);
	payload.setSwitchInsn(switchInsn);
       addInsn(switchInsn, stmt);
	// create instruction to jump to the default target, always follows the switch instruction
	return buildGotoInsn(defaultTarget);
}
 
Example #26
Source File: OdexedFieldInstructionMapper.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
private static int getOpcodeSubtype(@Nonnull Opcode opcode) {
    if (opcode.isOdexedInstanceQuick()) {
        return 0;
    } else if (opcode.isOdexedInstanceVolatile()) {
        return 1;
    } else if (opcode.isOdexedStaticVolatile()) {
        return 2;
    }
    throw new RuntimeException(String.format("Not an odexed field access opcode: %s", opcode.name));
}
 
Example #27
Source File: ImmutableInstruction21c.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
public ImmutableInstruction21c(@Nonnull Opcode opcode,
                                  int registerA,
                                  @Nonnull Reference reference) {
    super(opcode);
    this.registerA = Preconditions.checkByteRegister(registerA);
    this.reference = ImmutableReferenceFactory.of(opcode.referenceType, reference);
}
 
Example #28
Source File: ImmutableInstruction32x.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
public ImmutableInstruction32x(@Nonnull Opcode opcode,
                               int registerA,
                               int registerB) {
    super(opcode);
    this.registerA = Preconditions.checkShortRegister(registerA);
    this.registerB = Preconditions.checkShortRegister(registerB);
}
 
Example #29
Source File: StmtVisitor.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private Insn buildStaticFieldPutInsn(StaticFieldRef destRef, Value source) {
	SootField destSootField = destRef.getField();
	Register sourceReg = regAlloc.asImmediate(source, constantV);
	BuilderFieldReference destField = DexPrinter.toFieldReference(destSootField, belongingFile);
	Opcode opc = getPutGetOpcodeWithTypeSuffix("sput", destField.getType());
	return new Insn21c(opc, sourceReg, destField);
}
 
Example #30
Source File: ImmutableInstruction22b.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public ImmutableInstruction22b(@Nonnull Opcode opcode,
                               int registerA,
                               int registerB,
                               int literal) {
    super(opcode);
    this.registerA = Preconditions.checkByteRegister(registerA);
    this.registerB = Preconditions.checkByteRegister(registerB);
    this.literal = Preconditions.checkByteLiteral(literal);
}