Search in sources :

Example 6 with INaviView

use of com.google.security.zynamics.binnavi.disassembly.views.INaviView in project binnavi by google.

the class ViewTest method setUp.

@SuppressWarnings("deprecation")
@Before
public void setUp() throws LoadCancelledException, com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException, FileReadException, CouldntLoadDataException {
    ConfigManager.instance().read();
    final TagManager tagManager = new TagManager(new MockTagManager(TagType.NODE_TAG));
    final CTagManager internalTagManager = new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(1, "", "", TagType.VIEW_TAG, m_provider))), TagType.VIEW_TAG, m_provider);
    m_viewTagManager = new TagManager(internalTagManager);
    final Database database = new Database(new MockDatabase());
    internalModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, m_provider);
    internalModule.load();
    module = new Module(database, internalModule, tagManager, m_viewTagManager);
    final Calendar cal = Calendar.getInstance();
    cal.setTime(module.getModificationDate());
    cal.add(Calendar.DATE, 1);
    m_modificationDate = cal.getTime();
    m_creationDate = new Date();
    final ITreeNode<CTag> tag = internalTagManager.addTag(internalTagManager.getRootTag(), "foo");
    final CModuleViewGenerator generator = new CModuleViewGenerator(m_provider, internalModule);
    final INaviView internalView = generator.generate(1, "My View", "My View Description", com.google.security.zynamics.zylib.disassembly.ViewType.NonNative, GraphType.MIXED_GRAPH, m_creationDate, m_modificationDate, 1, 2, Sets.newHashSet(tag.getObject()), new HashSet<CTag>(), false);
    m_view = new View(module, internalView, tagManager, m_viewTagManager);
}
Also used : CModuleViewGenerator(com.google.security.zynamics.binnavi.Database.CModuleViewGenerator) Calendar(java.util.Calendar) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) ITreeNode(com.google.security.zynamics.zylib.types.trees.ITreeNode) TreeNode(com.google.security.zynamics.zylib.types.trees.TreeNode) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Before(org.junit.Before)

Example 7 with INaviView

use of com.google.security.zynamics.binnavi.disassembly.views.INaviView in project binnavi by google.

the class PostgreSQLFunctionsLoader method parseFunctionInformation.

/**
   * This function parses a {@link ResultSet result set} from a database query and generates a
   * {@link List} of {@link INaviFunction} from it.
   *
   * @param resultSet The {@link ResultSet} in which the result from the database query is stored.
   * @param provider The {@link SQLProvider} to access the database with.
   * @param module The {@link INaviModule} to which the {@link INaviFunction function(s)} are
   *        associated.
   *
   * @return A {@link List} of {@link INaviFunction functions} parsed from the {@link ResultSet
   *         resultSet}.
   *
   * @throws SQLException if the {@link ResultSet} could not be parsed.
   * @throws CouldntLoadDataException if the associated comments could not be loaded from the
   *         database.
   */
private static List<INaviFunction> parseFunctionInformation(final ResultSet resultSet, final SQLProvider provider, final INaviModule module) throws SQLException, CouldntLoadDataException {
    final List<INaviFunction> functions = Lists.newArrayList();
    final Map<Integer, INaviFunction> commentIdToFunction = new HashMap<Integer, INaviFunction>();
    try {
        while (resultSet.next()) {
            final IAddress address = PostgreSQLHelpers.loadAddress(resultSet, "address");
            final String name = resultSet.getString("name");
            final String originalName = resultSet.getString("original_name");
            Integer globalCommentId = resultSet.getInt("global_comment");
            if (resultSet.wasNull()) {
                globalCommentId = null;
            }
            final String description = resultSet.getString("description");
            final FunctionType type = FunctionType.valueOf(resultSet.getString("type").toUpperCase());
            final String parentModuleName = resultSet.getString("parent_module_name");
            final int parentModuleId = resultSet.getInt("parent_module_id");
            final IAddress parentModuleFunction = resultSet.wasNull() ? null : PostgreSQLHelpers.loadAddress(resultSet, "parent_module_function");
            final Integer nodeCount = resultSet.getInt("bbcount");
            final Integer edgeCount = resultSet.getInt("edgeCount");
            final Integer indegree = resultSet.getInt("incount");
            final Integer outdegree = resultSet.getInt("outcount");
            Integer stackFrameId = resultSet.getInt("stack_frame");
            if (resultSet.wasNull()) {
                stackFrameId = null;
            }
            Integer prototypeId = resultSet.getInt("prototype");
            if (resultSet.wasNull()) {
                prototypeId = null;
            }
            final INaviView view = ViewManager.get(provider).getView(resultSet.getInt("view_id"));
            final BaseType stackFrame = stackFrameId == null ? null : module.getTypeManager().getBaseType(stackFrameId);
            if (stackFrameId != null) {
                module.getTypeManager().setStackFrame(stackFrame);
            }
            final BaseType prototype = prototypeId == null ? null : module.getTypeManager().getBaseType(prototypeId);
            final CFunction function = new CFunction(module, view, address, name, originalName, description, indegree, outdegree, nodeCount, edgeCount, type, parentModuleName, parentModuleId, parentModuleFunction, stackFrame, prototype, provider);
            if (globalCommentId != null) {
                commentIdToFunction.put(globalCommentId, function);
            }
            functions.add(function);
        }
    } finally {
        resultSet.close();
    }
    if (!commentIdToFunction.isEmpty()) {
        final HashMap<Integer, ArrayList<IComment>> commentIdToComments = PostgreSQLCommentFunctions.loadMultipleCommentsById(provider, commentIdToFunction.keySet());
        for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdToComments.entrySet()) {
            CommentManager.get(provider).initializeGlobalFunctionComment(commentIdToFunction.get(commentIdToComment.getKey()), commentIdToComment.getValue());
        }
    }
    return functions;
}
Also used : HashMap(java.util.HashMap) FunctionType(com.google.security.zynamics.zylib.disassembly.FunctionType) ArrayList(java.util.ArrayList) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) BaseType(com.google.security.zynamics.binnavi.disassembly.types.BaseType) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Example 8 with INaviView

use of com.google.security.zynamics.binnavi.disassembly.views.INaviView in project binnavi by google.

the class TypeInstanceContainerBackend method loadTypeInstanceReference.

/**
   * Load a single type instance reference from the database.
   *
   * @param typeInstanceId the id of the {@link TypeInstanceReference reference}.
   * @param address The address of the {@link INaviInstruction instruction} where the
   *        {@link TypeInstanceReference reference} is associated.
   * @param position The {@link OperandTree operand tree} position in the {@link INaviInstruction
   *        instruction} the {@link TypeInstanceReference reference} is associated to.
   * @param expressionId The {@link OperandTreeNode operand tree node} id within the
   *        {@link OperandTree operand tree}.
   *
   * @return The {@link TypeInstanceReference} loaded from the database.
   * @throws CouldntLoadDataException
   */
public TypeInstanceReference loadTypeInstanceReference(final Integer typeInstanceId, final BigInteger address, final Integer position, final Integer expressionId) throws CouldntLoadDataException {
    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 RawTypeInstanceReference rawReference = provider.loadTypeInstanceReference(module, typeInstanceId, address, position, expressionId);
    final TypeInstance typeInstance = instancesById.get(rawReference.getTypeInstanceId());
    final INaviView view = module.getContent().getViewContainer().getView(rawReference.getViewId());
    final TypeInstanceReference reference = new TypeInstanceReference(new CAddress(address), position, Optional.<INaviOperandTreeNode>absent(), typeInstance, view);
    referenceLookup.put(new InstanceReferenceLookup(new CAddress(address), position, expressionId), reference);
    return reference;
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 9 with INaviView

use of com.google.security.zynamics.binnavi.disassembly.views.INaviView in project binnavi by google.

the class CViewContainer method delete.

private void delete(final INaviView view) {
    final INaviView currentStoredView = m_customViews.get(m_customViews.indexOf(view));
    m_customViews.remove(currentStoredView);
    viewIdView.remove(view.getConfiguration().getId());
    currentStoredView.removeListener(m_viewListener);
    for (final IModuleListener listener : m_listeners) {
        try {
            listener.deletedView(m_module, currentStoredView);
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
        }
    }
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) LoadCancelledException(com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CPartialLoadException(com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)

Example 10 with INaviView

use of com.google.security.zynamics.binnavi.disassembly.views.INaviView in project binnavi by google.

the class CDataflowViewCreator method create.

/**
   * Creates a new dataflow view.
   * 
   * @param container The container in which the dataflow view is created.
   * @param view The normal view that provides the control-flow information.
   * 
   * @return The created dataflow view.
   * 
   * @throws InternalTranslationException Thrown if the input view could not be translated to REIL.
   */
public static INaviView create(final IViewContainer container, final INaviView view) throws InternalTranslationException {
    Preconditions.checkNotNull(container, "IE00411: Module argument can not be null");
    Preconditions.checkNotNull(view, "IE00414: View argument can not be null");
    final Map<IAddress, INaviInstruction> instructions = new HashMap<IAddress, INaviInstruction>();
    for (final CCodeNode codeNode : view.getBasicBlocks()) {
        for (final INaviInstruction instruction : codeNode.getInstructions()) {
            instructions.put(instruction.getAddress(), instruction);
        }
    }
    final ReilFunction function = view.getContent().getReilCode();
    final OperandGraph operandGraph = OperandGraph.create(function.getGraph());
    final INaviView dfView = container.createView(String.format("Data flow view of '%s'", view.getName()), "");
    final Map<OperandGraphNode, INaviCodeNode> nodeMap = new HashMap<OperandGraphNode, INaviCodeNode>();
    final Map<INaviInstruction, CCodeNode> instructionMap = new HashMap<INaviInstruction, CCodeNode>();
    for (final OperandGraphNode operandGraphNode : operandGraph) {
        final ReilInstruction reilInstruction = operandGraphNode.getInstruction();
        final INaviInstruction instruction = instructions.get(ReilHelpers.toNativeAddress(reilInstruction.getAddress()));
        if (instructionMap.containsKey(instruction)) {
            nodeMap.put(operandGraphNode, instructionMap.get(instruction));
            continue;
        }
        final CCodeNode codeNode = dfView.getContent().createCodeNode(null, Lists.newArrayList(instruction));
        codeNode.setColor(ConfigManager.instance().getColorSettings().getBasicBlocksColor());
        nodeMap.put(operandGraphNode, codeNode);
        instructionMap.put(instruction, codeNode);
    }
    for (final OperandGraphEdge edge : operandGraph.getEdges()) {
        final INaviCodeNode source = nodeMap.get(edge.getSource());
        final INaviCodeNode target = nodeMap.get(edge.getTarget());
        if (source.equals(target)) {
            continue;
        }
        dfView.getContent().createEdge(source, target, EdgeType.JUMP_UNCONDITIONAL);
    }
    return dfView;
}
Also used : ReilInstruction(com.google.security.zynamics.reil.ReilInstruction) HashMap(java.util.HashMap) ReilFunction(com.google.security.zynamics.reil.ReilFunction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) OperandGraph(com.google.security.zynamics.reil.algorithms.mono.OperandGraph) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) OperandGraphEdge(com.google.security.zynamics.reil.algorithms.mono.OperandGraphEdge) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) OperandGraphNode(com.google.security.zynamics.reil.algorithms.mono.OperandGraphNode) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Aggregations

INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)121 Test (org.junit.Test)54 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)29 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)26 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)18 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)14 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)13 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)11 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)10 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)10 ArrayList (java.util.ArrayList)10 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)9 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)8 HashMap (java.util.HashMap)8 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)7 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)7 CProjectContainer (com.google.security.zynamics.binnavi.disassembly.CProjectContainer)7 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)7 FilledList (com.google.security.zynamics.zylib.types.lists.FilledList)7 MockTagManager (com.google.security.zynamics.binnavi.Tagging.MockTagManager)6