Search in sources :

Example 1 with TypeInstanceContainer

use of com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceContainer 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 2 with TypeInstanceContainer

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

the class COperandTreeNode method close.

@Override
public void close() {
    if (replacement != null) {
        replacement.close();
        replacement.removeListener(listener);
    }
    if (substitution != null) {
        operandTree.getInstruction().getModule().getTypeManager().removeTypeSubstitutionInstance(substitution);
    }
    if (instanceReferences != null && !instanceReferences.isEmpty()) {
        final TypeInstanceContainer container = operandTree.getInstruction().getModule().getContent().getTypeInstanceContainer();
        for (final TypeInstanceReference reference : instanceReferences) {
            container.deactivateTypeInstanceReference(reference);
        }
    }
}
Also used : TypeInstanceReference(com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceReference) TypeInstanceContainer(com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceContainer)

Example 3 with TypeInstanceContainer

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

the class PostgreSQLTypeInstancesNotificationParserTest method setUp.

@Before
public void setUp() throws NumberFormatException, CouldntSaveDataException, CouldntLoadDataException {
    view = MockViewGenerator.generate(provider, module, function);
    baseType = module.getTypeManager().getTypes().get(0);
    final Section section = module.getContent().getSections().createSection("TEST_SECTION", new CAddress("01000000", 16), new CAddress("0100FFFF", 16), SectionPermission.READ_WRITE_EXECUTE, null);
    final TypeInstanceContainer container = module.getContent().getTypeInstanceContainer();
    instance = container.createInstance("TEST_INSTANCE", null, baseType, section, new Long("11143"));
    final CCodeNode node = view.getBasicBlocks().get(0);
    final INaviInstruction instruction = node.getInstructions().iterator().next();
    final INaviOperandTreeNode operandNode = instruction.getOperands().get(0).getNodes().get(0);
    reference = container.createReference(instruction.getAddress(), 0, operandNode, instance, view);
    assertNotNull(reference);
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) TypeInstanceContainer(com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceContainer) Section(com.google.security.zynamics.binnavi.disassembly.types.Section) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) Before(org.junit.Before)

Example 4 with TypeInstanceContainer

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

the class PostgreSQLTypeInstanceFunctionsTests method loadSingleTypeInstanceReference6.

@Test
public void loadSingleTypeInstanceReference6() throws CouldntLoadDataException, LoadCancelledException, CPartialLoadException {
    module.load();
    for (final INaviView view : module.getContent().getViewContainer().getViews().subList(10, 20)) {
        view.load();
        final TypeInstanceContainer container = module.getContent().getTypeInstanceContainer();
        for (final TypeInstance typeInstance : container.getTypeInstances()) {
            for (final TypeInstanceReference reference : container.getReferences(typeInstance)) {
                if (reference.getTreeNode().isPresent()) {
                    final RawTypeInstanceReference rawReference = provider.loadTypeInstanceReference(module, typeInstance.getId(), reference.getAddress().toBigInteger(), reference.getPosition(), reference.getTreeNode().get().getId());
                    Assert.assertEquals(reference.getAddress(), rawReference.getAddress());
                }
            }
        }
        view.close();
    }
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) TypeInstanceReference(com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceReference) RawTypeInstanceReference(com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstanceReference) RawTypeInstanceReference(com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstanceReference) RawTypeInstance(com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstance) TypeInstance(com.google.security.zynamics.binnavi.disassembly.types.TypeInstance) TypeInstanceContainer(com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceContainer) Test(org.junit.Test)

Example 5 with TypeInstanceContainer

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

the class CPostgreSQLModuleContentTest method testCModuleContentConstructor.

@Test
public void testCModuleContentConstructor() throws LoadCancelledException, CouldntLoadDataException {
    final CModule module = (CModule) getDatabase().getContent().getModules().get(0);
    module.load();
    final ListenerProvider<IModuleListener> listeners = new ListenerProvider<IModuleListener>();
    final CCallgraph callgraph = module.getContent().getNativeCallgraph();
    final IFilledList<INaviFunction> functions = new FilledList<INaviFunction>();
    functions.add(module.getContent().getFunctionContainer().getFunctions().get(0));
    final ICallgraphView nativeCallgraph = module.getContent().getViewContainer().getNativeCallgraphView();
    final ImmutableList<IFlowgraphView> nativeFlowgraphs = module.getContent().getViewContainer().getNativeFlowgraphViews();
    final List<INaviView> customViews = new ArrayList<INaviView>();
    final ImmutableBiMap<INaviView, INaviFunction> viewFunctionMap = new ImmutableBiMap.Builder<INaviView, INaviFunction>().build();
    new Pair<HashMap<INaviView, INaviFunction>, HashMap<INaviFunction, INaviView>>(null, null);
    final IFilledList<TraceList> traces = new FilledList<TraceList>();
    final SectionContainer sections = new SectionContainer(new SectionContainerBackend(getProvider(), module));
    final TypeInstanceContainer instances = new TypeInstanceContainer(new TypeInstanceContainerBackend(getProvider(), module, module.getTypeManager(), sections), getProvider());
    final CModuleContent moduleContent1 = new CModuleContent(module, getProvider(), listeners, callgraph, functions, nativeCallgraph, nativeFlowgraphs, customViews, viewFunctionMap, traces, sections, instances);
    assertNotNull(moduleContent1);
    try {
        @SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(null, null, null, null, null, null, null, null, null, null, sections, instances);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        @SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, null, null, null, null, null, null, null, null, null, null, null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        @SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), null, null, null, null, null, null, null, null, null, null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        @SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, null, null, null, null, null, null, null, null, null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        @SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, callgraph, null, null, null, null, null, null, null, null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        @SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, callgraph, functions, null, null, null, null, null, null, null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        @SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, callgraph, functions, nativeCallgraph, null, null, null, null, null, null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        @SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, callgraph, functions, nativeCallgraph, nativeFlowgraphs, null, null, null, null, null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        @SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, callgraph, functions, nativeCallgraph, nativeFlowgraphs, customViews, null, null, null, null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        @SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, callgraph, functions, nativeCallgraph, nativeFlowgraphs, customViews, viewFunctionMap, null, null, null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        @SuppressWarnings("unused") final CModuleContent moduleContent = new CModuleContent(module, getProvider(), listeners, callgraph, functions, nativeCallgraph, nativeFlowgraphs, customViews, viewFunctionMap, traces, null, null);
        fail();
    } catch (final NullPointerException e) {
    }
}
Also used : IFlowgraphView(com.google.security.zynamics.binnavi.disassembly.IFlowgraphView) FilledList(com.google.security.zynamics.zylib.types.lists.FilledList) IFilledList(com.google.security.zynamics.zylib.types.lists.IFilledList) ArrayList(java.util.ArrayList) TypeInstanceContainerBackend(com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceContainerBackend) Pair(com.google.security.zynamics.zylib.general.Pair) SectionContainerBackend(com.google.security.zynamics.binnavi.disassembly.types.SectionContainerBackend) CCallgraph(com.google.security.zynamics.binnavi.disassembly.CCallgraph) ICallgraphView(com.google.security.zynamics.binnavi.disassembly.ICallgraphView) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) SectionContainer(com.google.security.zynamics.binnavi.disassembly.types.SectionContainer) TraceList(com.google.security.zynamics.binnavi.debug.models.trace.TraceList) ListenerProvider(com.google.security.zynamics.zylib.general.ListenerProvider) TypeInstanceContainer(com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceContainer) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Aggregations

TypeInstanceContainer (com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceContainer)7 TypeInstanceReference (com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceReference)3 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)3 ArrayList (java.util.ArrayList)3 TraceList (com.google.security.zynamics.binnavi.debug.models.trace.TraceList)2 CCallgraph (com.google.security.zynamics.binnavi.disassembly.CCallgraph)2 ICallgraphView (com.google.security.zynamics.binnavi.disassembly.ICallgraphView)2 IFlowgraphView (com.google.security.zynamics.binnavi.disassembly.IFlowgraphView)2 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)2 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)2 INaviOperandTreeNode (com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode)2 SectionContainer (com.google.security.zynamics.binnavi.disassembly.types.SectionContainer)2 SectionContainerBackend (com.google.security.zynamics.binnavi.disassembly.types.SectionContainerBackend)2 TypeInstanceContainerBackend (com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceContainerBackend)2 TypeManager (com.google.security.zynamics.binnavi.disassembly.types.TypeManager)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)1 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)1 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)1