use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class COperandsDeterminer method getRegisters.
/**
* Returns the registers read and written by a native instruction.
*
* @param instruction The instruction whose accessed registers are returned.
*
* @return The read and written registers of the instruction.
*
* @throws InternalTranslationException Thrown if the instruction could not be translated to REIL.
*/
public static Pair<Set<String>, Set<String>> getRegisters(final INaviInstruction instruction) throws InternalTranslationException {
final Set<String> inSet = new HashSet<String>();
final Set<String> outSet = new HashSet<String>();
final ReilTranslator<INaviInstruction> translator = new ReilTranslator<INaviInstruction>();
final DirectedGraph<ReilBlock, ReilEdge> reilCode = translator.translate(new StandardEnvironment(), instruction);
final boolean translatingReil = instruction.getArchitecture().equals("REIL");
for (final ReilBlock reilBlock : reilCode) {
for (final ReilInstruction reilInstruction : reilBlock) {
if (writesThirdOperand(reilInstruction, translatingReil)) {
outSet.add(reilInstruction.getThirdOperand().getValue());
}
if (!writesThirdOperand(reilInstruction, translatingReil) && isRegister(reilInstruction.getThirdOperand(), translatingReil)) {
// JCC + STM
inSet.add(reilInstruction.getThirdOperand().getValue());
}
if (isRegister(reilInstruction.getFirstOperand(), translatingReil)) {
inSet.add(reilInstruction.getFirstOperand().getValue());
}
if (isRegister(reilInstruction.getSecondOperand(), translatingReil)) {
inSet.add(reilInstruction.getSecondOperand().getValue());
}
}
}
return new Pair<Set<String>, Set<String>>(inSet, outSet);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class CReilViewCreator method create.
/**
* Creates a REIL view object from a REIL graph.
*
* @param container The container in which the new REIL view is created.
* @param graph The graph that contains the REIL code to be shown in the view.
*
* @return The created REIL code view.
*/
public static INaviView create(final INaviModule container, final ReilGraph graph) {
Preconditions.checkNotNull(container, "IE01809: Container argument can not be null");
Preconditions.checkNotNull(graph, "IE01815: Graph argument can not be null");
final INaviView view = container.getContent().getViewContainer().createView("REIL View", "");
final Map<ReilBlock, CCodeNode> nodeMap = new HashMap<ReilBlock, CCodeNode>();
for (final ReilBlock block : graph) {
final List<INaviInstruction> instructions = new ArrayList<INaviInstruction>();
for (final ReilInstruction reilInstruction : block) {
final List<COperandTree> operands = new ArrayList<COperandTree>();
if (reilInstruction.getFirstOperand().getType() == OperandType.EMPTY) {
operands.add(getEmptyOperand(container));
} else {
operands.add(convert(container, reilInstruction.getFirstOperand()));
}
if (reilInstruction.getSecondOperand().getType() == OperandType.EMPTY) {
operands.add(getEmptyOperand(container));
} else {
operands.add(convert(container, reilInstruction.getSecondOperand()));
}
if (reilInstruction.getThirdOperand().getType() == OperandType.EMPTY) {
operands.add(getEmptyOperand(container));
} else {
operands.add(convert(container, reilInstruction.getThirdOperand()));
}
final INaviInstruction convertedInstruction = container.createInstruction(reilInstruction.getAddress(), reilInstruction.getMnemonic(), operands, new byte[0], "REIL");
instructions.add(convertedInstruction);
}
final CCodeNode node = view.getContent().createCodeNode(null, instructions);
node.setColor(ConfigManager.instance().getColorSettings().getBasicBlocksColor());
nodeMap.put(block, node);
}
for (final ReilEdge edge : graph.getEdges()) {
final CNaviViewEdge reilEdge = view.getContent().createEdge(nodeMap.get(edge.getSource()), nodeMap.get(edge.getTarget()), edge.getType());
EdgeInitializer.adjustColor(reilEdge);
}
return view;
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class OpenInLastWindowAndZoomToAddressAction method actionPerformed.
@Override
public void actionPerformed(final ActionEvent event) {
final FutureCallback<Boolean> callBack = new FutureCallback<Boolean>() {
@Override
public void onFailure(final Throwable t) {
CUtilityFunctions.logException(t);
}
@Override
public void onSuccess(final Boolean result) {
ZyGraph graph = null;
final List<CGraphWindow> windows = CWindowManager.instance().getOpenWindows();
for (final CGraphWindow graphContainer : windows) {
for (final IGraphPanel window : graphContainer) {
if (reference.getView().equals(window.getModel().getGraph().getRawView())) {
graph = window.getModel().getGraph();
}
}
}
for (final NaviNode node : graph.getNodes()) {
if (node.getRawNode() instanceof INaviCodeNode) {
final INaviCodeNode codeNode = (INaviCodeNode) node.getRawNode();
for (final INaviInstruction instruction : codeNode.getInstructions()) {
if (instruction.getAddress().equals(reference.getAddress())) {
ZyZoomHelpers.zoomToAddress(graph, reference.getAddress());
CrossReferencePainter.paintCrossReference(node, codeNode, reference, instruction);
}
}
}
}
}
};
CShowViewFunctions.showViewsAndPerformCallBack(m_parent, m_container, m_views, CWindowManager.instance().getLastWindow(), callBack);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class CReadsDescription method visit.
@Override
public Collection<CSpecialInstruction> visit(final ReilFunction reilCode, final ListMultimap<IAddress, INaviInstruction> instructionMap) {
final Collection<CSpecialInstruction> instructions = new ArrayList<CSpecialInstruction>();
final Set<INaviInstruction> calls = new HashSet<INaviInstruction>();
for (final ReilBlock block : reilCode.getGraph()) {
for (final ReilInstruction reilInstruction : block) {
if (ReilHelpers.isFunctionCall(reilInstruction)) {
calls.addAll(instructionMap.get(ReilHelpers.toNativeAddress(reilInstruction.getAddress())));
}
}
}
for (final ReilBlock block : reilCode.getGraph()) {
for (final ReilInstruction reilInstruction : block) {
if (reilInstruction.getMnemonic().equals(ReilHelpers.OPCODE_LDM)) {
final List<INaviInstruction> firstInstructions = instructionMap.get(ReilHelpers.toNativeAddress(reilInstruction.getAddress()));
if (isAnyCall(firstInstructions, calls)) {
continue;
}
final List<INaviInstruction> nativeInstructions = instructionMap.get(ReilHelpers.toNativeAddress(reilInstruction.getAddress()));
for (final INaviInstruction naviInstruction : nativeInstructions) {
instructions.add(new CSpecialInstruction(this, naviInstruction));
}
}
}
}
return instructions;
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class CWritesDescription method visit.
@Override
public Collection<CSpecialInstruction> visit(final ReilFunction reilCode, final ListMultimap<IAddress, INaviInstruction> instructionMap) {
final Collection<CSpecialInstruction> instructions = new ArrayList<CSpecialInstruction>();
final Set<INaviInstruction> calls = new HashSet<INaviInstruction>();
for (final ReilBlock block : reilCode.getGraph()) {
for (final ReilInstruction reilInstruction : block) {
if (ReilHelpers.isFunctionCall(reilInstruction)) {
calls.addAll(instructionMap.get(ReilHelpers.toNativeAddress(reilInstruction.getAddress())));
}
}
}
for (final ReilBlock block : reilCode.getGraph()) {
for (final ReilInstruction reilInstruction : block) {
if (reilInstruction.getMnemonic().equals(ReilHelpers.OPCODE_STM)) {
final List<INaviInstruction> firstInstructions = instructionMap.get(ReilHelpers.toNativeAddress(reilInstruction.getAddress()));
if (isAnyCall(firstInstructions, calls)) {
continue;
}
final List<INaviInstruction> nativeInstructions = instructionMap.get(ReilHelpers.toNativeAddress(reilInstruction.getAddress()));
for (final INaviInstruction naviInstruction : nativeInstructions) {
instructions.add(new CSpecialInstruction(this, naviInstruction));
}
}
}
}
return instructions;
}
Aggregations