use of com.google.security.zynamics.binnavi.disassembly.CCodeNode in project binnavi by google.
the class CReilViewCreator method create.
/**
* Creates a REIL view from a view.
*
* @param container The container in which the new REIL view is created.
* @param view The view to be translated to REIL code.
*
* @return The created REIL code view.
*
* @throws InternalTranslationException Thrown if the view could not be translated to REIL code.
* @throws CouldntLoadDataException
*/
public static INaviView create(final INaviModule container, final INaviView view) throws InternalTranslationException, CouldntLoadDataException {
Preconditions.checkNotNull(container, "IE01768: Container argument can not be null");
Preconditions.checkNotNull(view, "IE01769: View argument can not be null");
final Map<IAddress, String> textMap = new HashMap<IAddress, String>();
for (final CCodeNode node : view.getBasicBlocks()) {
for (final INaviInstruction instruction : node.getInstructions()) {
textMap.put(instruction.getAddress(), instruction.toString());
}
}
final INaviView reilView = CReilViewCreator.create(container, view.getContent().getReilCode().getGraph());
for (final CCodeNode node : reilView.getBasicBlocks()) {
for (final INaviInstruction reilInstruction : node.getInstructions()) {
if ((reilInstruction.getAddress().toLong() & 0xFF) == 0) {
try {
node.getComments().appendLocalInstructionComment(reilInstruction, textMap.get(ReilHelpers.toNativeAddress(reilInstruction.getAddress())));
} catch (final CouldntSaveDataException e) {
// Not possible for unsaved views.
CUtilityFunctions.logException(e);
}
}
}
}
return reilView;
}
use of com.google.security.zynamics.binnavi.disassembly.CCodeNode in project binnavi by google.
the class ViewTest method testGraph.
@Test
public void testGraph() {
final List<INaviViewNode> nodes = new ArrayList<INaviViewNode>();
final List<INaviEdge> edges = new ArrayList<INaviEdge>();
final MutableDirectedGraph<INaviViewNode, INaviEdge> graph = new MutableDirectedGraph<INaviViewNode, INaviEdge>(nodes, edges);
final int viewId = new BigInteger(31, new SecureRandom()).intValue();
final INaviView internalView = new CView(viewId, internalModule, "My View", "My View Description", com.google.security.zynamics.zylib.disassembly.ViewType.NonNative, m_creationDate, m_modificationDate, graph, new HashSet<CTag>(), false, m_provider);
final INaviFunction internalFunction = internalModule.getContent().getFunctionContainer().getFunctions().get(0);
final CCodeNode codeNode = internalView.getContent().createCodeNode(internalFunction, Lists.newArrayList(new MockInstruction()));
final CFunctionNode functionNode = internalView.getContent().createFunctionNode(internalFunction);
@SuppressWarnings("unused") final CTextNode textNode = internalView.getContent().createTextNode(Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Foo")));
@SuppressWarnings("unused") final CGroupNode groupNode = internalView.getContent().createGroupNode(internalView.getGraph().getNodes());
internalView.getContent().createEdge(codeNode, functionNode, com.google.security.zynamics.zylib.gui.zygraph.edges.EdgeType.JUMP_UNCONDITIONAL);
final TagManager tagManager = new TagManager(new MockTagManager(TagType.NODE_TAG));
final MockViewListener listener = new MockViewListener();
final View view = new View(module, internalView, tagManager, m_viewTagManager);
view.addListener(listener);
assertEquals(4, view.getGraph().getNodes().size());
assertEquals(1, view.getGraph().getEdges().size());
internalView.getContent().deleteNodes(internalView.getContent().getGraph().getNodes());
assertEquals("deletedEdge;deletedNode;deletedNode;deletedNode;", listener.events);
}
use of com.google.security.zynamics.binnavi.disassembly.CCodeNode in project binnavi by google.
the class CodeNodeTest method setUp.
@Before
public void setUp() {
final Database database = new Database(new MockDatabase());
final MockModule mockModule = new MockModule();
final TagManager nodeTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.NODE_TAG));
final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
final Module module = new Module(database, mockModule, nodeTagManager, viewTagManager);
final MockView mockView = new MockView();
final View view = new View(module, mockView, nodeTagManager, viewTagManager);
final MockSqlProvider provider = new MockSqlProvider();
final CModule internalModule = new CModule(123, "Name", "Comment", new Date(), new Date(), "12345678123456781234567812345678", "1234567812345678123456781234567812345678", 55, 66, new CAddress(0x555), new CAddress(0x666), new DebuggerTemplate(1, "Mock Debugger", "localhaus", 88, provider), null, Integer.MAX_VALUE, false, provider);
final CFunction internalFunction = new CFunction(internalModule, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, provider);
final CComment m_globalComment = new CComment(null, CommonTestObjects.TEST_USER_1, null, "Global Comment");
final INaviCodeNode codeNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, false, Lists.<IComment>newArrayList(m_globalComment), internalFunction, new HashSet<CTag>(), new MockSqlProvider());
codeNode.addInstruction(new CInstruction(true, internalModule, new CAddress(0x123), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", provider), null);
m_node = new CodeNode(view, codeNode, nodeTagManager);
}
use of com.google.security.zynamics.binnavi.disassembly.CCodeNode in project binnavi by google.
the class PostgreSQLNodeSaver method saveNodes.
/**
* Saves the nodes to the nodes table. As a side effect, this function also fills index lists that
* store the indices into the nodes list for all node types. TODO: This method should probably be
* split into two methods.
*
* @param provider Provides the connection to the database.
* @param newViewId ID of the new view that is being saved.
* @param nodes The nodes to save.
* @param functionNodeIndices Index into the nodes list that identifies the function nodes.
* @param codeNodeIndices Index into the nodes list that identifies the code nodes.
* @param textNodeIndices Index into the nodes list that identifies the text nodes.
* @param groupNodeIndices Index into the nodes list that identifies the group nodes.
* @param groupNodeMap Maps between node IDs and group node objects.
* @return The ID of the first node saved to the database.
* @throws SQLException Thrown if saving the nodes failed.
*/
private static int saveNodes(final AbstractSQLProvider provider, final int newViewId, final List<INaviViewNode> nodes, final List<Integer> functionNodeIndices, final List<Integer> codeNodeIndices, final List<Integer> textNodeIndices, final List<Integer> groupNodeIndices, final BiMap<Integer, INaviGroupNode> groupNodeMap) throws SQLException {
final String query = "INSERT INTO " + CTableNames.NODES_TABLE + "( view_id, parent_id, type, x, y, width, height, color, bordercolor, " + " selected, visible) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
final PreparedStatement preparedStatement = provider.getConnection().getConnection().prepareStatement(query, java.sql.Statement.RETURN_GENERATED_KEYS);
int counter = 0;
for (final INaviViewNode node : nodes) {
String nodeType = null;
if (node instanceof CCodeNode) {
nodeType = CODE;
codeNodeIndices.add(counter);
} else if (node instanceof CFunctionNode) {
nodeType = FUNCTION;
functionNodeIndices.add(counter);
} else if (node instanceof INaviGroupNode) {
nodeType = GROUP;
groupNodeIndices.add(counter);
groupNodeMap.put(counter, (INaviGroupNode) node);
} else if (node instanceof CTextNode) {
nodeType = TEXT;
textNodeIndices.add(counter);
}
counter++;
preparedStatement.setInt(1, newViewId);
preparedStatement.setNull(2, Types.INTEGER);
preparedStatement.setObject(3, nodeType, Types.OTHER);
preparedStatement.setDouble(4, node.getX());
preparedStatement.setDouble(5, node.getY());
preparedStatement.setDouble(6, node.getWidth());
preparedStatement.setDouble(7, node.getHeight());
preparedStatement.setInt(8, node.getColor().getRGB());
preparedStatement.setInt(9, node.getBorderColor().getRGB());
preparedStatement.setBoolean(10, node.isSelected());
preparedStatement.setBoolean(11, node.isVisible());
preparedStatement.addBatch();
}
preparedStatement.executeBatch();
final ResultSet resultSet = preparedStatement.getGeneratedKeys();
int lastId = 0;
try {
while (resultSet.next()) {
if (resultSet.isFirst()) {
lastId = resultSet.getInt(1);
break;
}
}
} finally {
preparedStatement.close();
resultSet.close();
}
return lastId;
}
use of com.google.security.zynamics.binnavi.disassembly.CCodeNode in project binnavi by google.
the class CGraphDebuggerTest method testGetDebugger2.
@Test
public void testGetDebugger2() {
final MockModule module = new MockModule();
module.getConfiguration().setDebugger(m_debugger);
final DebugTargetSettings target = new ModuleTargetSettings(module);
final DebuggerProvider debuggerProvider = new DebuggerProvider(target);
debuggerProvider.addDebugger(m_debugger);
final CFunction function = new CFunction(module, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, m_provider);
final ArrayList<IComment> comments = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Mock Comment"));
final INaviCodeNode codeNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, false, comments, function, new HashSet<CTag>(), new MockSqlProvider());
codeNode.addInstruction(new CInstruction(true, module, new CAddress(0x123), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", m_provider), null);
assertEquals(m_debugger, CGraphDebugger.getDebugger(debuggerProvider, Iterables.getFirst(codeNode.getInstructions(), null)));
}
Aggregations