use of com.google.security.zynamics.zylib.disassembly.CAddress in project binnavi by google.
the class SectionContainerTests method createSectionTest3.
@Test(expected = NullPointerException.class)
public void createSectionTest3() throws CouldntLoadDataException, CouldntSaveDataException {
final SectionContainer sectionContainer = new SectionContainer(backend);
Assert.assertNotNull(sectionContainer);
Assert.assertEquals(0, sectionContainer.getSections().size());
sectionContainer.createSection(".text", new CAddress("100", 16), null, null, null);
}
use of com.google.security.zynamics.zylib.disassembly.CAddress in project binnavi by google.
the class SectionTests method getRawSizeTest1.
@Test
public void getRawSizeTest1() {
final Section section = new Section(1, "SECTION1", commentManager, module, new CAddress("100", 16), new CAddress("200", 16), SectionPermission.READ, null);
Assert.assertEquals(0, section.getRawSize());
}
use of com.google.security.zynamics.zylib.disassembly.CAddress in project binnavi by google.
the class ZyGraphFactory method generateTestGraph.
public static ZyGraph generateTestGraph() throws FileReadException, CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException {
ConfigManager.instance().read();
final MockDatabase database = new MockDatabase();
final SQLProvider provider = new MockSqlProvider();
final CModule module = new CModule(1, "", "", new Date(), new Date(), CommonTestObjects.MD5, CommonTestObjects.SHA1, 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, provider);
final ZyGraphViewSettings settings = new ZyGraphViewSettings(new CallGraphSettingsConfigItem());
settings.getLayoutSettings().setDefaultGraphLayout(LayoutStyle.CIRCULAR);
database.getContent().addModule(module);
final MockDatabaseManager manager = new MockDatabaseManager();
manager.addDatabase(database);
module.load();
final CView m_view = module.getContent().getViewContainer().createView("name", "description");
final LinkedHashMap<Node, NaviNode> nodeMap = new LinkedHashMap<Node, NaviNode>();
final ZyGraph2DView g2dView = new ZyGraph2DView();
final LinkedHashMap<Edge, NaviEdge> edgeMap = new LinkedHashMap<Edge, NaviEdge>();
final Node node1 = g2dView.getGraph2D().createNode();
final COperandTreeNode rootNode1 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final COperandTreeNode childNode1 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "eax", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
COperandTreeNode.link(rootNode1, childNode1);
final COperandTreeNode rootNode2 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final COperandTreeNode childNode2 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "ebx", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
COperandTreeNode.link(rootNode2, childNode2);
final COperandTree operand1 = new COperandTree(rootNode1, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final COperandTree operand2 = new COperandTree(rootNode2, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final ArrayList<COperandTree> operands1 = Lists.newArrayList(operand1, operand2);
final List<INaviInstruction> instructions1 = Lists.newArrayList((INaviInstruction) new MockInstruction(new CAddress(0x123456), "mov", operands1, null, module));
final INaviCodeNode rawNode1 = m_view.getContent().createCodeNode(null, instructions1);
final ZyLabelContent content = ZyCodeNodeBuilder.buildContent(rawNode1, settings, null);
nodeMap.put(node1, new NaviNode(node1, new ZyNormalNodeRealizer<NaviNode>(content), rawNode1));
final Node node2 = g2dView.getGraph2D().createNode();
final List<INaviInstruction> instructions2 = Lists.newArrayList((INaviInstruction) new MockInstruction());
final INaviCodeNode rawNode2 = m_view.getContent().createCodeNode(null, instructions2);
final ZyLabelContent content2 = ZyCodeNodeBuilder.buildContent(rawNode2, settings, null);
nodeMap.put(node2, new NaviNode(node2, new ZyNormalNodeRealizer<NaviNode>(content2), rawNode2));
rawNode2.setColor(Color.RED);
rawNode2.setVisible(false);
final CTag tag = new CTag(0, "Tag", "Description", TagType.NODE_TAG, new MockSqlProvider());
rawNode2.tagNode(tag);
final Node node3 = g2dView.getGraph2D().createNode();
final String mnemonicName = "call";
final List<COperandTree> operandTrees = new ArrayList<COperandTree>();
final int type = ExpressionType.REGISTER.ordinal();
final CReference reference = new CReference(new CAddress(0x123), ReferenceType.CALL_DIRECT);
final List<IReference> referencea = new ArrayList<IReference>();
referencea.add(reference);
final COperandTreeNode root = new COperandTreeNode(0, type, "eax", null, referencea, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final COperandTree operandTree = new COperandTree(root, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
operandTrees.add(0, operandTree);
final List<INaviInstruction> instructions3 = Lists.newArrayList((INaviInstruction) new MockInstruction(mnemonicName, operandTrees, m_globalComment));
final INaviCodeNode rawNode3 = m_view.getContent().createCodeNode(null, instructions3);
final ZyLabelContent content3 = ZyCodeNodeBuilder.buildContent(rawNode3, settings, null);
nodeMap.put(node3, new NaviNode(node3, new ZyNormalNodeRealizer<NaviNode>(content3), rawNode3));
final Edge edge = g2dView.getGraph2D().createEdge(node1, node2);
final INaviEdge rawEdge = m_view.getContent().createEdge(rawNode1, rawNode2, EdgeType.JUMP_UNCONDITIONAL);
edgeMap.put(edge, new NaviEdge(nodeMap.get(node1), nodeMap.get(node2), edge, new ZyEdgeRealizer<NaviEdge>(new ZyLabelContent(null), null), rawEdge));
final Edge edge2 = g2dView.getGraph2D().createEdge(node2, node3);
final INaviEdge rawEdge2 = m_view.getContent().createEdge(rawNode2, rawNode3, EdgeType.JUMP_UNCONDITIONAL);
edgeMap.put(edge2, new NaviEdge(nodeMap.get(node2), nodeMap.get(node3), edge, new ZyEdgeRealizer<NaviEdge>(new ZyLabelContent(null), null), rawEdge2));
return new ZyGraph(m_view, nodeMap, edgeMap, settings, g2dView);
}
use of com.google.security.zynamics.zylib.disassembly.CAddress in project binnavi by google.
the class PostgreSQLSectionFunctions method loadSections.
/**
* Loads all sections that are associated with the given module.
*
* @param provider The SQL provider that holds the database connection.
* @param module The module whose sections should be loaded.
* @return The list of sections loaded from the database.
* @throws CouldntLoadDataException Thrown if the sections could not be loaded from the database.
*/
public static Map<Section, Integer> loadSections(final SQLProvider provider, final INaviModule module) throws CouldntLoadDataException {
Preconditions.checkNotNull(provider, "Error: provider argument can not be null");
Preconditions.checkNotNull(module, "Error: module argument can not be null");
final HashMap<Section, Integer> sections = Maps.newHashMap();
final String query = "SELECT * FROM get_sections(?)";
try (PreparedStatement statement = provider.getConnection().getConnection().prepareStatement(query)) {
statement.setInt(1, module.getConfiguration().getId());
final ResultSet result = statement.executeQuery();
while (result.next()) {
final int id = result.getInt("id");
final String name = result.getString("name");
Integer commentId = result.getInt("comment_id");
if (result.wasNull()) {
commentId = null;
}
final IAddress startAddress = new CAddress(result.getLong("start_address"));
final IAddress endAddress = new CAddress(result.getLong("end_address"));
final SectionPermission permission = SectionPermission.valueOf(result.getString("permission"));
final byte[] data = result.getBytes("data");
sections.put(new Section(id, name, CommentManager.get(provider), module, startAddress, endAddress, permission, data), commentId);
}
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
return sections;
}
use of com.google.security.zynamics.zylib.disassembly.CAddress in project binnavi by google.
the class PostgreSQLTypeFunctions method loadRawTypeInstanceReference.
/**
* Loads a single {@link RawTypeInstanceReference cross reference} from the database.
*
* @param provider The {@link SQLProvider} to access the database with.
* @param module The {@link INaviModule} the {@link RawTypeInstanceReference cross reference} is
* associated to.
* @param typeInstanceId The id of the {@link RawTypeInstance type instance} this
* {@link RawTypeInstanceReference cross reference} references.
* @param address The {@link INaviInstruction instruction} address where this
* {@link RawTypeInstanceReference cross reference} is associated to.
* @param position The {@link INaviOperandTree operand tree} position to which this
* {@link RawTypeInstanceReference type reference} is associated to.
* @param expressionId The {@link INaviOperandTreeNode operand node} where this
* {@link RawTypeInstanceReference type reference} is associated to.
*
* @return The {@link RawTypeInstanceReference type reference} from the database which matches the
* given arguments.
* @throws CouldntLoadDataException
*/
public static RawTypeInstanceReference loadRawTypeInstanceReference(final SQLProvider provider, final INaviModule module, final Integer typeInstanceId, final BigInteger address, final Integer position, final Integer expressionId) throws CouldntLoadDataException {
Preconditions.checkNotNull(provider, "Error: provider argument can not be null");
Preconditions.checkNotNull(module, "Error: module argument can not be null");
Preconditions.checkNotNull(typeInstanceId, "Error: typeInstanceId argument can not be null");
Preconditions.checkNotNull(address, "Error: address argument can not be null");
Preconditions.checkNotNull(position, "Error: position argument can not be null");
Preconditions.checkNotNull(expressionId, "Error: expressionId argument can not be null");
final String query = " SELECT * FROM load_expression_type_instance(?, ?, ?, ?, ?) ";
try {
final PreparedStatement statement = provider.getConnection().getConnection().prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
statement.setInt(1, module.getConfiguration().getId());
statement.setInt(2, typeInstanceId);
statement.setObject(3, address, Types.BIGINT);
statement.setInt(4, position);
statement.setInt(5, expressionId);
final ResultSet resultSet = statement.executeQuery();
try {
while (resultSet.next()) {
if (resultSet.isFirst()) {
final int viewId = resultSet.getInt("view_id");
final int moduleId = resultSet.getInt("module_id");
return new RawTypeInstanceReference(moduleId, viewId, new CAddress(address), position, expressionId, typeInstanceId);
}
}
} finally {
resultSet.close();
statement.close();
}
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
throw new CouldntLoadDataException("Error: could not load single cross reference from the database.");
}
Aggregations