use of com.google.security.zynamics.zylib.general.Triple in project binnavi by google.
the class BasicBlockGenerator method addInstruction.
private void addInstruction(final ReilInstruction reilInstruction, final HashSet<IAddress> jumpTargets, final ReilInstruction lastInstruction) {
if (jumpTargets.contains(reilInstruction.getAddress()) && (currentBlock.size() != 0)) {
final ReilBlock reilBlock = new ReilBlock(currentBlock);
// final IAddress blockAddress = reilBlock.getAddress();
blocks.add(reilBlock);
// if ((reilBlock.getAddress().toLong() & 0xFFFFFFFFFFFFFF00L) ==
// (reilInstruction.getAddress().toLong() & 0xFFFFFFFFFFFFFF00L))
{
edgepairs.add(new Triple<ReilBlock, IAddress, EdgeType>(reilBlock, reilInstruction.getAddress(), EdgeType.JUMP_UNCONDITIONAL));
}
currentBlock = new ArrayList<ReilInstruction>();
}
currentBlock.add(reilInstruction);
if (reilInstruction.getMnemonic().equals(ReilHelpers.OPCODE_JCC) && (ReilHelpers.isDelayedBranch(reilInstruction) || (reilInstruction != lastInstruction))) {
// Every JCC instruction finishes a block. We skip the last instruction of a block
// because those edges already exist in the native edge set.
//
// Delayed branches also finish a block, at least as far as edge creation goes.
final ReilBlock reilBlock = new ReilBlock(currentBlock);
blocks.add(reilBlock);
currentBlock = new ArrayList<ReilInstruction>();
final String jumpTarget = reilInstruction.getThirdOperand().getValue();
if (ReilHelpers.isConditionalJump(reilInstruction)) {
// If we have a conditional jump we have to add two edges.
edgepairs.add(new Triple<ReilBlock, IAddress, EdgeType>(reilBlock, null, EdgeType.JUMP_CONDITIONAL_FALSE));
if (Convert.isDecString(jumpTarget)) {
edgepairs.add(new Triple<ReilBlock, IAddress, EdgeType>(reilBlock, toReilAddress(jumpTarget), EdgeType.JUMP_CONDITIONAL_TRUE));
} else if (reilInstruction.getThirdOperand().getType() == OperandType.SUB_ADDRESS) {
final String[] parts = jumpTarget.split("\\.");
edgepairs.add(new Triple<ReilBlock, IAddress, EdgeType>(reilBlock, toReilAddress(parts), EdgeType.JUMP_CONDITIONAL_TRUE));
}
} else if (ReilHelpers.isFunctionCall(reilInstruction)) {
edgepairs.add(new Triple<ReilBlock, IAddress, EdgeType>(reilBlock, null, EdgeType.JUMP_UNCONDITIONAL));
} else if (Convert.isDecString(jumpTarget)) {
edgepairs.add(new Triple<ReilBlock, IAddress, EdgeType>(reilBlock, toReilAddress(jumpTarget), EdgeType.JUMP_UNCONDITIONAL));
} else if (reilInstruction.getThirdOperand().getType() == OperandType.SUB_ADDRESS) {
final String[] parts = jumpTarget.split("\\.");
edgepairs.add(new Triple<ReilBlock, IAddress, EdgeType>(reilBlock, toReilAddress(parts), EdgeType.JUMP_UNCONDITIONAL));
}
}
}
use of com.google.security.zynamics.zylib.general.Triple in project binnavi by google.
the class ReilGraphGenerator method createGraphElements.
/**
* Creates REIL basic blocks and edges from a list of REIL instructions.
*
* @param instructionList A list of REIL instructions.
* @param nativeJumpTargets Additional jump targets for the algorithm to consider.
*
* @return A pair containing the blocks and edges created from the REIL instructions.
*/
public static Pair<List<ReilBlock>, List<ReilEdge>> createGraphElements(final Collection<List<ReilInstruction>> instructionList, final Collection<IAddress> nativeJumpTargets) {
final BasicBlockGenerator generator = new BasicBlockGenerator(instructionList, nativeJumpTargets);
final List<ReilBlock> blocks = generator.getBlocks();
final ArrayList<Triple<ReilBlock, IAddress, EdgeType>> edgepairs = generator.getEdges();
final List<ReilEdge> edges = new ArrayList<ReilEdge>();
for (final Triple<ReilBlock, IAddress, EdgeType> p : edgepairs) {
final ReilBlock source = p.first();
final IAddress target = p.second();
final EdgeType edgeType = p.third();
if (target != null) {
for (final ReilBlock block : blocks) {
for (final ReilInstruction instruction : block.getInstructions()) {
if (target.equals(instruction.getAddress())) {
final ReilEdge edge = new ReilEdge(source, block, edgeType);
edges.add(edge);
ReilBlock.link(source, block, edge);
}
}
}
} else {
// Unknown target address
final int index = blocks.indexOf(source);
if (blocks.size() > (index + 1)) {
final ReilEdge edge = new ReilEdge(source, blocks.get(index + 1), edgeType);
edges.add(edge);
ReilBlock.link(source, blocks.get(index + 1), edge);
}
}
}
return new Pair<List<ReilBlock>, List<ReilEdge>>(blocks, edges);
}
use of com.google.security.zynamics.zylib.general.Triple in project binnavi by google.
the class OperandLoader method loadDuplicateFirst.
public static Triple<IOperandTree, IOperandTree, IOperandTree> loadDuplicateFirst(final IInstruction instruction) {
final List<? extends IOperandTree> operands = instruction.getOperands();
final IOperandTree operand1 = operands.get(0);
final IOperandTree operand2 = operands.size() == 2 ? operands.get(0) : operands.get(1);
final IOperandTree operand3 = operands.size() == 2 ? operands.get(1) : operands.get(2);
return new Triple<IOperandTree, IOperandTree, IOperandTree>(operand1, operand2, operand3);
}
Aggregations