use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class CTracking method track.
/**
* Performs a register forward tracking operation.
*
* @param view The view where the operation happens.
* @param startInstruction The start instruction.
* @param trackedRegister The register to track.
* @param options Register tracking options.
*
* @return The result of the register tracking operation.
*
* @throws InternalTranslationException Thrown if the graph from the code could not be translated
* to REIL.
*/
public static CTrackingResult track(final INaviView view, final INaviInstruction startInstruction, final String trackedRegister, final RegisterTrackingOptions options) throws InternalTranslationException {
Preconditions.checkNotNull(view, "IE01660: View argument can not be null");
Preconditions.checkNotNull(startInstruction, "IE01661: Start instruction argument can not be null");
Preconditions.checkNotNull(trackedRegister, "IE01662: Register argument can not be null");
final MonoReilSolverResult<RegisterSetLatticeElement> result = RegisterTracker.track(view.getContent().getReilCode(), startInstruction, trackedRegister, options);
final Map<IAddress, INaviInstruction> instructionMap = CRegisterTrackingHelper.getInstructionMap(view);
final List<CInstructionResult> instructionResultList = new ArrayList<CInstructionResult>();
final Map<IAddress, RegisterSetLatticeElement> perInstructionElement = result.generateAddressToStateMapping(startInstruction, options.trackIncoming());
for (final Map.Entry<IAddress, RegisterSetLatticeElement> addressToStateMapEntry : perInstructionElement.entrySet()) {
final RegisterSetLatticeElement element = addressToStateMapEntry.getValue();
if (!element.getReadRegisters().isEmpty() || !element.getNewlyTaintedRegisters().isEmpty() || !element.getUntaintedRegisters().isEmpty() || !element.getUpdatedRegisters().isEmpty()) {
final CAddress concreteAddress = new CAddress(addressToStateMapEntry.getKey().toLong() >> 8);
instructionResultList.add(new CInstructionResult(instructionMap.get(concreteAddress), addressToStateMapEntry.getValue()));
}
}
return new CTrackingResult(startInstruction, trackedRegister, instructionResultList);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class CViewPruner method convertNodes.
/**
* Converts the nodes from the original view to the pruned view.
*
* @param view The original view.
* @param prunedView The pruned view.
* @param keptInstructions Instructions to add to the new view.
*
* @return A mapping between nodes of the original view and nodes of the pruned view.
*/
private static Map<INaviViewNode, INaviViewNode> convertNodes(final INaviView view, final INaviView prunedView, final List<INaviInstruction> keptInstructions) {
final Map<INaviViewNode, INaviViewNode> nodeMap = new HashMap<INaviViewNode, INaviViewNode>();
for (final INaviViewNode node : view.getGraph().getNodes()) {
if (node instanceof INaviCodeNode) {
final INaviCodeNode cnode = (INaviCodeNode) node;
final ArrayList<INaviInstruction> newInstructions = Lists.newArrayList(cnode.getInstructions());
newInstructions.retainAll(keptInstructions);
if (!newInstructions.isEmpty()) {
CCodeNode newNode;
try {
newNode = prunedView.getContent().createCodeNode(cnode.getParentFunction(), newInstructions);
} catch (final MaybeNullException e) {
newNode = prunedView.getContent().createCodeNode(null, newInstructions);
}
newNode.setBorderColor(node.getBorderColor());
newNode.setColor(node.getColor());
nodeMap.put(node, newNode);
}
} else if (node instanceof INaviFunctionNode) {
final INaviFunction function = ((INaviFunctionNode) node).getFunction();
final CFunctionNode newNode = prunedView.getContent().createFunctionNode(function);
nodeMap.put(node, newNode);
}
}
return nodeMap;
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class LocalInstructionCommentAccessor method getAllComments.
@Override
public ArrayList<Pair<INaviInstruction, IComment>> getAllComments() {
final ArrayList<Pair<INaviInstruction, IComment>> values = new ArrayList<>();
final CCodeNodeComments currentComments = m_codeNode.getComments();
for (final INaviInstruction instruction : m_codeNode.getInstructions()) {
final List<IComment> comments = currentComments.getLocalInstructionComment(instruction);
if ((comments == null) || comments.isEmpty()) {
values.add(new Pair<INaviInstruction, IComment>(instruction, new EmptyComment()));
continue;
} else {
for (final IComment comment : comments) {
values.add(new Pair<INaviInstruction, IComment>(instruction, comment));
}
values.add(new Pair<INaviInstruction, IComment>(instruction, new EmptyComment()));
}
}
return values;
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class CSteppingHelper method getAddress.
/**
* Determines the start address of a node.
*
* @param node Node whose address is determined.
*
* @return The start address of the given node or null if the node does not have an address.
*/
private static BreakpointAddress getAddress(final INaviViewNode node) {
if (node instanceof INaviCodeNode) {
final INaviCodeNode ccnode = (INaviCodeNode) node;
final INaviInstruction instruction = Iterables.getFirst(ccnode.getInstructions(), null);
return new BreakpointAddress(instruction.getModule(), new UnrelocatedAddress(instruction.getAddress()));
} else if (node instanceof INaviFunctionNode) {
final INaviFunction function = ((INaviFunctionNode) node).getFunction();
final INaviModule module = function.getModule();
return new BreakpointAddress(module, new UnrelocatedAddress(function.getAddress()));
} else {
// Node types we can not step to
return null;
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class CGraphSynchronizer method updateInstructionMap.
/**
* Updates the cached Address => Instruction map.
*/
private void updateInstructionMap() {
m_instructionMap.clear();
for (final INaviViewNode node : m_graph.getRawView().getGraph()) {
if (node instanceof INaviCodeNode) {
final INaviCodeNode cnode = (INaviCodeNode) node;
for (final INaviInstruction instruction : cnode.getInstructions()) {
final IAddress address = instruction.getAddress();
m_instructionMap.put(address, instruction);
}
}
}
}
Aggregations