Top Description Inners Fields Constructors Methods
org.droidparts.dexmaker.dx.dex.code

public final Class RopTranslator

extends Object
Class Inheritance
Imports
org.droidparts.dexmaker.dx.dex.DexOptions, org.droidparts.dexmaker.dx.io.Opcodes, org.droidparts.dexmaker.dx.rop.code.*, org.droidparts.dexmaker.dx.rop.cst.Constant, .CstInteger, org.droidparts.dexmaker.dx.util.Bits, .IntList, java.util.ArrayList

Translator from RopMethod to DalvCode. The translate method is the thing to call on this class.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
RopTranslator.LocalVariableAwareTranslationVisitor

Instruction visitor class for doing instruction translation with local variable tracking

private class
RopTranslator.TranslationVisitor

Instruction visitor class for doing the instruction translation per se.

Field Summary

Modifier and TypeField and Description
private final BlockAddresses
addresses

non-null; container for all the address objects for the method

private final DexOptions
dexOptions

non-null; options for dex output

private final LocalVariableInfo
locals

null-ok; local variable info to use

private final RopMethod
method

non-null; method to translate

private int[]
order

null-ok; block output order; becomes non-null in pickOrder

private final OutputCollector
output

non-null; list of output instructions in-progress

private boolean
paramsAreInOrder

true if the parameters to this method happen to be in proper order at the end of the frame (as the optimizer emits them)

private final int
paramSize

size, in register units, of all the parameters to this method

private final int
positionInfo

how much position info to preserve; one of the static constants in PositionList

private final int
regCount

>= 0; register count for the method

private final RopTranslator.TranslationVisitor
translationVisitor

non-null; visitor to use during translation

Constructor Summary

AccessConstructor and Description
private
RopTranslator(RopMethod
non-null; the original method
method
,
int
how much position info to preserve; one of the static constants in PositionList
positionInfo
,
LocalVariableInfo
null-ok; local variable information to use
locals
,
int
size, in register units, of all the parameters to this method
paramSize
,
DexOptions
non-null; options for dex output
dexOptions
)

Constructs an instance.

Method Summary

Modifier and TypeMethod and Description
private static boolean
calculateParamsAreInOrder(RopMethod method, final int
size, in register units, of all the parameters to this method
paramSize
)

Checks to see if the move-param instructions that occur in this method happen to slot the params in an order at the top of the stack frame that matches dalvik's calling conventions.

private static RegisterSpecList

Returns:

non-null; the instruction's complete register list
getRegs
(Insn
non-null; instruction in question
insn
)

Gets the complete register list (result and sources) out of a given rop instruction.

private static RegisterSpecList

Returns:

non-null; the instruction's complete register list
getRegs
(Insn
non-null; instruction in question
insn
,
RegisterSpec
null-ok; the real result to use (ignore the insn's)
resultReg
)

Gets the complete register list (result and sources) out of a given rop instruction.

private void
outputBlock(BasicBlock
non-null; the block to process and output
block
,
int
>= -1; the next block that will be processed, or -1 if there is no next block
nextLabel
)

Helper for outputInstructions, which does the processing and output of one block.

private void
outputInstructions()

Performs initial creation of output instructions based on the original blocks.

private void
pickOrder()

Picks an order for the blocks by doing "trace" analysis.

public static DalvCode

Returns:

non-null; the translated version
translate
(RopMethod
non-null; the original method
method
,
int
how much position info to preserve; one of the static constants in PositionList
positionInfo
,
LocalVariableInfo
null-ok; local variable information to use
locals
,
int
size, in register units, of all the parameters to this method
paramSize
,
DexOptions
non-null; options for dex output
dexOptions
)

Translates a RopMethod.

private DalvCode

Returns:

non-null; the result
translateAndGetResult
()

Does the translation and returns the result.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

addressesback to summary
private final BlockAddresses addresses

non-null; container for all the address objects for the method

dexOptionsback to summary
private final DexOptions dexOptions

non-null; options for dex output

localsback to summary
private final LocalVariableInfo locals

null-ok; local variable info to use

methodback to summary
private final RopMethod method

non-null; method to translate

orderback to summary
private int[] order

null-ok; block output order; becomes non-null in pickOrder

outputback to summary
private final OutputCollector output

non-null; list of output instructions in-progress

paramsAreInOrderback to summary
private boolean paramsAreInOrder

true if the parameters to this method happen to be in proper order at the end of the frame (as the optimizer emits them)

paramSizeback to summary
private final int paramSize

size, in register units, of all the parameters to this method

positionInfoback to summary
private final int positionInfo

how much position info to preserve; one of the static constants in PositionList

regCountback to summary
private final int regCount

>= 0; register count for the method

translationVisitorback to summary
private final RopTranslator.TranslationVisitor translationVisitor

non-null; visitor to use during translation

Constructor Detail

RopTranslatorback to summary
private RopTranslator(RopMethod method, int positionInfo, LocalVariableInfo locals, int paramSize, DexOptions dexOptions)

Constructs an instance. This method is private. Use translate.

Parameters
method:RopMethod

non-null; the original method

positionInfo:int

how much position info to preserve; one of the static constants in PositionList

locals:LocalVariableInfo

null-ok; local variable information to use

paramSize:int

size, in register units, of all the parameters to this method

dexOptions:DexOptions

non-null; options for dex output

Method Detail

calculateParamsAreInOrderback to summary
private static boolean calculateParamsAreInOrder(RopMethod method, final int paramSize)

Checks to see if the move-param instructions that occur in this method happen to slot the params in an order at the top of the stack frame that matches dalvik's calling conventions. This will alway result in "true" for methods that have run through the SSA optimizer.

Parameters
paramSize:int

size, in register units, of all the parameters to this method

getRegsback to summary
private static RegisterSpecList getRegs(Insn insn)

Gets the complete register list (result and sources) out of a given rop instruction. For insns that are commutative, have two register sources, and have a source equal to the result, place that source first.

Parameters
insn:Insn

non-null; instruction in question

Returns:RegisterSpecList

non-null; the instruction's complete register list

getRegsback to summary
private static RegisterSpecList getRegs(Insn insn, RegisterSpec resultReg)

Gets the complete register list (result and sources) out of a given rop instruction. For insns that are commutative, have two register sources, and have a source equal to the result, place that source first.

Parameters
insn:Insn

non-null; instruction in question

resultReg:RegisterSpec

null-ok; the real result to use (ignore the insn's)

Returns:RegisterSpecList

non-null; the instruction's complete register list

outputBlockback to summary
private void outputBlock(BasicBlock block, int nextLabel)

Helper for outputInstructions, which does the processing and output of one block.

Parameters
block:BasicBlock

non-null; the block to process and output

nextLabel:int

>= -1; the next block that will be processed, or -1 if there is no next block

outputInstructionsback to summary
private void outputInstructions()

Performs initial creation of output instructions based on the original blocks.

pickOrderback to summary
private void pickOrder()

Picks an order for the blocks by doing "trace" analysis.

translateback to summary
public static DalvCode translate(RopMethod method, int positionInfo, LocalVariableInfo locals, int paramSize, DexOptions dexOptions)

Translates a RopMethod. This may modify the given input.

Parameters
method:RopMethod

non-null; the original method

positionInfo:int

how much position info to preserve; one of the static constants in PositionList

locals:LocalVariableInfo

null-ok; local variable information to use

paramSize:int

size, in register units, of all the parameters to this method

dexOptions:DexOptions

non-null; options for dex output

Returns:DalvCode

non-null; the translated version

translateAndGetResultback to summary
private DalvCode translateAndGetResult()

Does the translation and returns the result.

Returns:DalvCode

non-null; the result

org.droidparts.dexmaker.dx.dex.code back to summary

private Class RopTranslator.LocalVariableAwareTranslationVisitor

extends TranslationVisitor
Class Inheritance

Instruction visitor class for doing instruction translation with local variable tracking

Field Summary

Modifier and TypeField and Description
private LocalVariableInfo
locals

non-null; local variable info

Constructor Summary

AccessConstructor and Description
public
LocalVariableAwareTranslationVisitor(OutputCollector
non-null; destination for instruction output
output
,
LocalVariableInfo
non-null; the local variable info
locals
)

Constructs an instance.

Method Summary

Modifier and TypeMethod and Description
public void
addIntroductionIfNecessary(Insn
non-null; instruction in question
insn
)

Adds a LocalStart to the output if the given instruction in fact introduces a local variable.

public void
public void
public void
public void
public void
Inherited from org.droidparts.dexmaker.dx.dex.code.RopTranslator.TranslationVisitor:
addOutputaddOutputSuffixsetBlockvisitFillArrayDataInsn

Field Detail

localsback to summary
private LocalVariableInfo locals

non-null; local variable info

Constructor Detail

LocalVariableAwareTranslationVisitorback to summary
public LocalVariableAwareTranslationVisitor(OutputCollector output, LocalVariableInfo locals)

Constructs an instance.

Parameters
output:OutputCollector

non-null; destination for instruction output

locals:LocalVariableInfo

non-null; the local variable info

Method Detail

addIntroductionIfNecessaryback to summary
public void addIntroductionIfNecessary(Insn insn)

Adds a LocalStart to the output if the given instruction in fact introduces a local variable.

Parameters
insn:Insn

non-null; instruction in question

visitPlainCstInsnback to summary
public void visitPlainCstInsn(PlainCstInsn insn)

Overrides org.droidparts.dexmaker.dx.dex.code.RopTranslator.TranslationVisitor.visitPlainCstInsn.

Implements org.droidparts.dexmaker.dx.rop.code.Insn.Visitor.visitPlainCstInsn.

Doc from org.droidparts.dexmaker.dx.dex.code.RopTranslator.TranslationVisitor.visitPlainCstInsn.

Visits a PlainCstInsn.

Parameters
insn:PlainCstInsn

Doc from org.droidparts.dexmaker.dx.rop.code.Insn.Visitor.visitPlainCstInsn.

non-null; the instruction to visit

Annotations
@Override
visitPlainInsnback to summary
public void visitPlainInsn(PlainInsn insn)

Overrides org.droidparts.dexmaker.dx.dex.code.RopTranslator.TranslationVisitor.visitPlainInsn.

Implements org.droidparts.dexmaker.dx.rop.code.Insn.Visitor.visitPlainInsn.

Doc from org.droidparts.dexmaker.dx.dex.code.RopTranslator.TranslationVisitor.visitPlainInsn.

Visits a PlainInsn.

Parameters
insn:PlainInsn

Doc from org.droidparts.dexmaker.dx.rop.code.Insn.Visitor.visitPlainInsn.

non-null; the instruction to visit

Annotations
@Override
visitSwitchInsnback to summary
public void visitSwitchInsn(SwitchInsn insn)

Overrides org.droidparts.dexmaker.dx.dex.code.RopTranslator.TranslationVisitor.visitSwitchInsn.

Implements org.droidparts.dexmaker.dx.rop.code.Insn.Visitor.visitSwitchInsn.

Doc from org.droidparts.dexmaker.dx.dex.code.RopTranslator.TranslationVisitor.visitSwitchInsn.

Visits a SwitchInsn.

Parameters
insn:SwitchInsn

Doc from org.droidparts.dexmaker.dx.rop.code.Insn.Visitor.visitSwitchInsn.

non-null; the instruction to visit

Annotations
@Override
visitThrowingCstInsnback to summary
public void visitThrowingCstInsn(ThrowingCstInsn insn)

Overrides org.droidparts.dexmaker.dx.dex.code.RopTranslator.TranslationVisitor.visitThrowingCstInsn.

Implements org.droidparts.dexmaker.dx.rop.code.Insn.Visitor.visitThrowingCstInsn.

Doc from org.droidparts.dexmaker.dx.dex.code.RopTranslator.TranslationVisitor.visitThrowingCstInsn.

Visits a ThrowingCstInsn.

Parameters
insn:ThrowingCstInsn

Doc from org.droidparts.dexmaker.dx.rop.code.Insn.Visitor.visitThrowingCstInsn.

non-null; the instruction to visit

Annotations
@Override
visitThrowingInsnback to summary
public void visitThrowingInsn(ThrowingInsn insn)

Overrides org.droidparts.dexmaker.dx.dex.code.RopTranslator.TranslationVisitor.visitThrowingInsn.

Implements org.droidparts.dexmaker.dx.rop.code.Insn.Visitor.visitThrowingInsn.

Doc from org.droidparts.dexmaker.dx.dex.code.RopTranslator.TranslationVisitor.visitThrowingInsn.

Visits a ThrowingInsn.

Parameters
insn:ThrowingInsn

Doc from org.droidparts.dexmaker.dx.rop.code.Insn.Visitor.visitThrowingInsn.

non-null; the instruction to visit

Annotations
@Override
org.droidparts.dexmaker.dx.dex.code back to summary

private Class RopTranslator.TranslationVisitor

extends Object
implements Visitor
Class Inheritance
  • java.lang.Object
  • org.droidparts.dexmaker.dx.dex.code.RopTranslator.TranslationVisitor
All Implemented Interfaces
org.droidparts.dexmaker.dx.rop.code.Insn.Visitor
Known Direct Subclasses
org.droidparts.dexmaker.dx.dex.code.RopTranslator.LocalVariableAwareTranslationVisitor

Instruction visitor class for doing the instruction translation per se.

Field Summary

Modifier and TypeField and Description
private BasicBlock
block

non-null; basic block being worked on

private CodeAddress
lastAddress

null-ok; code address for the salient last instruction of the block (used before switches and throwing instructions)

private final OutputCollector
output

non-null; list of output instructions in-progress

Constructor Summary

AccessConstructor and Description
public
TranslationVisitor(OutputCollector
non-null; destination for instruction output
output
)

Constructs an instance.

Method Summary

Modifier and TypeMethod and Description
protected void
addOutput(DalvInsn
non-null; instruction to add
insn
)

Adds to the output.

protected void
addOutputSuffix(DalvInsn
non-null; instruction to add
insn
)

Adds to the output suffix.

private RegisterSpec

Returns:

null-ok; result of move-result-pseudo at the beginning of primary successor
getNextMoveResultPseudo
()

Looks forward to the current block's primary successor, returning the RegisterSpec of the result of the move-result-pseudo at the top of that block or null if none.

public void
setBlock(BasicBlock
non-null; the block
block
,
CodeAddress
non-null; code address for the salient last instruction of the block
lastAddress
)

Sets the block currently being worked on.

public void
public void
public void
visitPlainInsn(PlainInsn
non-null; the instruction to visit
insn
)

Implements org.droidparts.dexmaker.dx.rop.code.Insn.Visitor.visitPlainInsn.

Visits a PlainInsn.
public void
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

blockback to summary
private BasicBlock block

non-null; basic block being worked on

lastAddressback to summary
private CodeAddress lastAddress

null-ok; code address for the salient last instruction of the block (used before switches and throwing instructions)

outputback to summary
private final OutputCollector output

non-null; list of output instructions in-progress

Constructor Detail

TranslationVisitorback to summary
public TranslationVisitor(OutputCollector output)

Constructs an instance.

Parameters
output:OutputCollector

non-null; destination for instruction output

Method Detail

addOutputback to summary
protected void addOutput(DalvInsn insn)

Adds to the output.

Parameters
insn:DalvInsn

non-null; instruction to add

addOutputSuffixback to summary
protected void addOutputSuffix(DalvInsn insn)

Adds to the output suffix.

Parameters
insn:DalvInsn

non-null; instruction to add

getNextMoveResultPseudoback to summary
private RegisterSpec getNextMoveResultPseudo()

Looks forward to the current block's primary successor, returning the RegisterSpec of the result of the move-result-pseudo at the top of that block or null if none.

Returns:RegisterSpec

null-ok; result of move-result-pseudo at the beginning of primary successor

setBlockback to summary
public void setBlock(BasicBlock block, CodeAddress lastAddress)

Sets the block currently being worked on.

Parameters
block:BasicBlock

non-null; the block

lastAddress:CodeAddress

non-null; code address for the salient last instruction of the block

visitFillArrayDataInsnback to summary
public void visitFillArrayDataInsn(FillArrayDataInsn insn)

Implements org.droidparts.dexmaker.dx.rop.code.Insn.Visitor.visitFillArrayDataInsn.

Doc from org.droidparts.dexmaker.dx.rop.code.Insn.Visitor.visitFillArrayDataInsn.

Visits a FillArrayDataInsn.

Parameters
insn:FillArrayDataInsn

non-null; the instruction to visit

visitPlainCstInsnback to summary
public void visitPlainCstInsn(PlainCstInsn insn)

Implements org.droidparts.dexmaker.dx.rop.code.Insn.Visitor.visitPlainCstInsn.

Doc from org.droidparts.dexmaker.dx.rop.code.Insn.Visitor.visitPlainCstInsn.

Visits a PlainCstInsn.

Parameters
insn:PlainCstInsn

non-null; the instruction to visit

visitPlainInsnback to summary
public void visitPlainInsn(PlainInsn insn)

Implements org.droidparts.dexmaker.dx.rop.code.Insn.Visitor.visitPlainInsn.

Doc from org.droidparts.dexmaker.dx.rop.code.Insn.Visitor.visitPlainInsn.

Visits a PlainInsn.

Parameters
insn:PlainInsn

non-null; the instruction to visit

visitSwitchInsnback to summary
public void visitSwitchInsn(SwitchInsn insn)

Implements org.droidparts.dexmaker.dx.rop.code.Insn.Visitor.visitSwitchInsn.

Doc from org.droidparts.dexmaker.dx.rop.code.Insn.Visitor.visitSwitchInsn.

Visits a SwitchInsn.

Parameters
insn:SwitchInsn

non-null; the instruction to visit

visitThrowingCstInsnback to summary
public void visitThrowingCstInsn(ThrowingCstInsn insn)

Implements org.droidparts.dexmaker.dx.rop.code.Insn.Visitor.visitThrowingCstInsn.

Doc from org.droidparts.dexmaker.dx.rop.code.Insn.Visitor.visitThrowingCstInsn.

Visits a ThrowingCstInsn.

Parameters
insn:ThrowingCstInsn

non-null; the instruction to visit

visitThrowingInsnback to summary
public void visitThrowingInsn(ThrowingInsn insn)

Implements org.droidparts.dexmaker.dx.rop.code.Insn.Visitor.visitThrowingInsn.

Doc from org.droidparts.dexmaker.dx.rop.code.Insn.Visitor.visitThrowingInsn.

Visits a ThrowingInsn.

Parameters
insn:ThrowingInsn

non-null; the instruction to visit