Search in sources :

Example 1 with TypeManager

use of com.google.security.zynamics.binnavi.disassembly.types.TypeManager in project binnavi by google.

the class PostgreSQLTypesNotificationParser method informExpressionTypesNotification.

/**
   * Informs about necessary state changes related to {@link TypeSubstitution type substitutions}.
   *
   * @param container The {@link TypesNotificationContainer} holding the parsed
   *        {@link PGNotification notification} information.
   * @param provider The {@link SQLProvider} used to access the database with.
   *
   * @throws CouldntLoadDataException if the required information could not be loaded from the
   *         database.
   */
private void informExpressionTypesNotification(final TypesNotificationContainer container, final SQLProvider provider) throws CouldntLoadDataException {
    final INaviModule module = provider.findModule(container.getModuleId());
    final TypeManager typeManager = module.getTypeManager();
    final INaviOperandTreeNode node = findOperandTreeNode(provider, container.getModuleId(), new CAddress(container.getAddress().get()), container.position().get(), container.expressionId().get());
    if (node == null) {
        return;
    }
    if (container.getDatabaseOperation().equals("INSERT")) {
        final RawTypeSubstitution rawSubstitution = provider.loadTypeSubstitution(module, container.getAddress().get(), container.position().get(), container.expressionId().get());
        typeManager.initializeTypeSubstitution(node, rawSubstitution);
    } else if (container.getDatabaseOperation().equals("UPDATE")) {
        final RawTypeSubstitution rawSubstitution = provider.loadTypeSubstitution(module, container.getAddress().get(), container.position().get(), container.expressionId().get());
        typeManager.updateTypeSubstitution(node, rawSubstitution.getBaseTypeId(), rawSubstitution.getPath(), rawSubstitution.getOffset());
    } else if (container.getDatabaseOperation().equals("DELETE")) {
        typeManager.removeTypeSubstitutionInstance(node.getTypeSubstitution());
    } else {
        throw new IllegalStateException("Error: the database operation " + container.getDatabaseOperation() + " is currently not supported.");
    }
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) TypeManager(com.google.security.zynamics.binnavi.disassembly.types.TypeManager) RawTypeSubstitution(com.google.security.zynamics.binnavi.disassembly.types.RawTypeSubstitution) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 2 with TypeManager

use of com.google.security.zynamics.binnavi.disassembly.types.TypeManager in project binnavi by google.

the class InstructionConverter method generateTree.

/**
   * Converts a raw operand tree into a proper operand tree.
   *
   * @param rawTree The raw operand tree.
   * @param provider The connection to the database.
   * @param module
   *
   * @return The proper operand tree.
   */
private static COperandTree generateTree(final OperandTree rawTree, final SQLProvider provider, final INaviModule module) {
    final ArrayList<COperandTreeNode> realNodes = new ArrayList<COperandTreeNode>();
    final HashMap<COperandTreeNode, OperandTreeNode> realToRawMapping = new HashMap<COperandTreeNode, OperandTreeNode>();
    final HashMap<Integer, COperandTreeNode> idToRealMapping = new HashMap<Integer, COperandTreeNode>();
    COperandTreeNode root = null;
    final TypeManager typeManager = module.getTypeManager();
    final TypeInstanceContainer instanceContainer = module.getContent().getTypeInstanceContainer();
    for (final OperandTreeNode rawNode : rawTree.getNodes()) {
        final COperandTreeNode node = new COperandTreeNode(rawNode.getId(), rawNode.getType(), rawNode.getValue(), rawNode.getReplacement(), rawNode.getReferences(), provider, typeManager, instanceContainer);
        if (rawNode.getTypeSubstitution() != null) {
            typeManager.initializeTypeSubstitution(node, rawNode.getTypeSubstitution());
        }
        if (rawNode.getTypeInstanceId() != null) {
            instanceContainer.initializeTypeInstanceReference(rawNode.getAddress(), rawNode.getPosition(), rawNode.getId(), node);
        }
        realToRawMapping.put(node, rawNode);
        idToRealMapping.put(rawNode.getId(), node);
        if (rawNode.getParentId() == null) {
            root = node;
        }
        realNodes.add(node);
    }
    for (final COperandTreeNode realNode : realNodes) {
        // Link the real nodes here.
        // To link two real nodes, it is necessary to know
        // which node is the parent and which node is the
        // child.
        final OperandTreeNode rawNode = realToRawMapping.get(realNode);
        final Integer parentId = rawNode.getParentId();
        if (parentId == null) {
            continue;
        }
        final COperandTreeNode realParent = idToRealMapping.get(parentId);
        COperandTreeNode.link(realParent, realNode);
    }
    return new COperandTree(root, provider, typeManager, instanceContainer);
}
Also used : HashMap(java.util.HashMap) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) ArrayList(java.util.ArrayList) TypeManager(com.google.security.zynamics.binnavi.disassembly.types.TypeManager) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) TypeInstanceContainer(com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceContainer)

Example 3 with TypeManager

use of com.google.security.zynamics.binnavi.disassembly.types.TypeManager in project binnavi by google.

the class TypesTreeModelTests method initializeTypeSystem.

@Before
public void initializeTypeSystem() throws CouldntLoadDataException {
    typeManager = new TypeManager(new TypeManagerMockBackend());
    typeSystem = new TestTypeSystem(typeManager);
}
Also used : TypeManager(com.google.security.zynamics.binnavi.disassembly.types.TypeManager) TestTypeSystem(com.google.security.zynamics.binnavi.disassembly.types.TestTypeSystem) TypeManagerMockBackend(com.google.security.zynamics.binnavi.disassembly.types.TypeManagerMockBackend) Before(org.junit.Before)

Example 4 with TypeManager

use of com.google.security.zynamics.binnavi.disassembly.types.TypeManager in project binnavi by google.

the class CModule method load.

@Override
public void load() throws CouldntLoadDataException, LoadCancelledException {
    synchronized (m_loadReporter) {
        if (isLoaded()) {
            return;
        }
        if (!isInitialized()) {
            throw new IllegalStateException("IE02617: The module is not initialized yet");
        }
        m_isLoading = true;
        try {
            if (!m_loadReporter.report(ModuleLoadEvents.Starting)) {
                throw new LoadCancelledException();
            }
            if (!m_loadReporter.report(ModuleLoadEvents.LoadingCallgraphView)) {
                throw new LoadCancelledException();
            }
            final ICallgraphView nativeCallgraph = m_provider.loadNativeCallgraph(this);
            if (!m_loadReporter.report(ModuleLoadEvents.LoadingFlowgraphs)) {
                throw new LoadCancelledException();
            }
            // When loading views, an empty flow graph (imported function) can not
            // be distinguished
            // from an empty call graph. This leads to problems in modules without
            // functions. In
            // these cases, the empty call graph is loaded as an imported function
            // view. This is
            // obviously wrong, so we are correcting this here.
            final ImmutableList<IFlowgraphView> nativeFlowgraphs = nativeCallgraph.getNodeCount() == 0 ? new ImmutableList.Builder<IFlowgraphView>().build() : m_provider.loadNativeFlowgraphs(this);
            if (!m_loadReporter.report(ModuleLoadEvents.LoadingCallgraphViews)) {
                throw new LoadCancelledException();
            }
            final List<ICallgraphView> userCallgraphs = m_provider.loadCallgraphViews(this);
            if (!m_loadReporter.report(ModuleLoadEvents.LoadingFlowgraphViews)) {
                throw new LoadCancelledException();
            }
            final ImmutableList<IFlowgraphView> userFlowgraphs = m_provider.loadFlowgraphs(this);
            if (!m_loadReporter.report(ModuleLoadEvents.LoadingMixedViews)) {
                throw new LoadCancelledException();
            }
            final List<INaviView> userMixedGraphs = m_provider.loadMixedgraphs(this);
            if (!m_loadReporter.report(ModuleLoadEvents.LoadingCallgraph)) {
                throw new LoadCancelledException();
            }
            if (!m_loadReporter.report(ModuleLoadEvents.LoadingFunctions)) {
                throw new LoadCancelledException();
            }
            // Note: the type manager needs to be loaded prior to functions, since a function might
            // have an associated stack frame, which in turn needs the type system.
            typeManager = new TypeManager(new TypeManagerDatabaseBackend(m_provider, this));
            final List<INaviFunction> functions = m_provider.loadFunctions(this, nativeFlowgraphs);
            final ImmutableBiMap<INaviView, INaviFunction> viewFunctionMap = m_provider.loadViewFunctionMapping(nativeFlowgraphs, functions, this);
            final CCallgraph callgraph = m_provider.loadCallgraph(this, nativeCallgraph.getConfiguration().getId(), functions);
            if (!m_loadReporter.report(ModuleLoadEvents.LoadingTraces)) {
                throw new LoadCancelledException();
            }
            final List<TraceList> traces = m_provider.loadTraces(this);
            if (!m_loadReporter.report(ModuleLoadEvents.LoadingGlobalVariables)) {
                throw new LoadCancelledException();
            }
            final List<INaviView> customViews = new ArrayList<INaviView>();
            customViews.addAll(userCallgraphs);
            customViews.addAll(userFlowgraphs);
            customViews.addAll(userMixedGraphs);
            final List<INaviView> currentViews = new ArrayList<INaviView>(nativeFlowgraphs);
            currentViews.addAll(customViews);
            Collections.sort(currentViews, new Comparator<INaviView>() {

                @Override
                public int compare(final INaviView lhs, final INaviView rhs) {
                    return lhs.getConfiguration().getId() - rhs.getConfiguration().getId();
                }
            });
            // Map viewId to corresponding index in currentViews.
            final Map<Integer, Integer> viewIdToIndex = new HashMap<Integer, Integer>();
            for (int i = 0; i < currentViews.size(); ++i) {
                viewIdToIndex.put(currentViews.get(i).getConfiguration().getId(), i);
            }
            if (!m_loadReporter.report(ModuleLoadEvents.LoadingTypes)) {
                throw new LoadCancelledException();
            }
            final SectionContainer sections = new SectionContainer(new SectionContainerBackend(m_provider, this));
            final TypeInstanceContainer typeInstances = new TypeInstanceContainer(new TypeInstanceContainerBackend(m_provider, this, typeManager, sections), m_provider);
            m_content = new CModuleContent(this, m_provider, m_listeners, callgraph, functions, nativeCallgraph, nativeFlowgraphs, customViews, viewFunctionMap, traces, sections, typeInstances);
            typeInstances.initialize();
        } catch (final CouldntLoadDataException e) {
            m_isLoading = false;
            throw e;
        } catch (final LoadCancelledException e) {
            m_isLoading = false;
            throw e;
        } finally {
            m_loadReporter.report(ModuleLoadEvents.Finished);
        }
        for (final IModuleListener listener : m_listeners) {
            try {
                listener.loadedModule(this);
            } catch (final Exception exception) {
                CUtilityFunctions.logException(exception);
            }
        }
        m_isLoading = false;
    }
}
Also used : IFlowgraphView(com.google.security.zynamics.binnavi.disassembly.IFlowgraphView) HashMap(java.util.HashMap) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ArrayList(java.util.ArrayList) TypeInstanceContainerBackend(com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceContainerBackend) SectionContainerBackend(com.google.security.zynamics.binnavi.disassembly.types.SectionContainerBackend) CCallgraph(com.google.security.zynamics.binnavi.disassembly.CCallgraph) 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) ICallgraphView(com.google.security.zynamics.binnavi.disassembly.ICallgraphView) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) TypeManagerDatabaseBackend(com.google.security.zynamics.binnavi.disassembly.types.TypeManagerDatabaseBackend) SectionContainer(com.google.security.zynamics.binnavi.disassembly.types.SectionContainer) TypeManager(com.google.security.zynamics.binnavi.disassembly.types.TypeManager) TraceList(com.google.security.zynamics.binnavi.debug.models.trace.TraceList) LoadCancelledException(com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException) TypeInstanceContainer(com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceContainer) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Example 5 with TypeManager

use of com.google.security.zynamics.binnavi.disassembly.types.TypeManager in project binnavi by google.

the class CCodeNodeMenu method addRegisterOperandMenu.

private void addRegisterOperandMenu(final CGraphModel model, final COperandTreeNode treeNode, final INaviInstruction instruction, final List<ICodeNodeExtension> extensions, final INaviCodeNode codeNode) {
    try {
        add(new COperandsMenu(codeNode, instruction, extensions));
    } catch (final InternalTranslationException | MaybeNullException exception) {
        CUtilityFunctions.logException(exception);
    }
    final TypeManager typeManager = model.getViewContainer().getModules().get(0).getTypeManager();
    if (treeNode.getTypeSubstitution() == null) {
        add(TypeSubstitutionAction.instantiateCreateTypeSubstitution(model.getParent(), typeManager, getStackFrame(model), treeNode));
    } else {
        add(new DeleteTypeSubstitutionMenuAction(typeManager, treeNode));
        add(TypeSubstitutionAction.instantiateEditTypeSubstitution(model.getParent(), typeManager, getStackFrame(model), treeNode));
    }
    addSeparator();
}
Also used : MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) TypeManager(com.google.security.zynamics.binnavi.disassembly.types.TypeManager) InternalTranslationException(com.google.security.zynamics.reil.translators.InternalTranslationException)

Aggregations

TypeManager (com.google.security.zynamics.binnavi.disassembly.types.TypeManager)6 TestTypeSystem (com.google.security.zynamics.binnavi.disassembly.types.TestTypeSystem)2 TypeInstanceContainer (com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceContainer)2 TypeManagerMockBackend (com.google.security.zynamics.binnavi.disassembly.types.TypeManagerMockBackend)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Before (org.junit.Before)2 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)1 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)1 LoadCancelledException (com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException)1 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)1 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)1 TraceList (com.google.security.zynamics.binnavi.debug.models.trace.TraceList)1 CCallgraph (com.google.security.zynamics.binnavi.disassembly.CCallgraph)1 COperandTree (com.google.security.zynamics.binnavi.disassembly.COperandTree)1 COperandTreeNode (com.google.security.zynamics.binnavi.disassembly.COperandTreeNode)1 ICallgraphView (com.google.security.zynamics.binnavi.disassembly.ICallgraphView)1 IFlowgraphView (com.google.security.zynamics.binnavi.disassembly.IFlowgraphView)1 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)1 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)1