Search in sources :

Example 56 with IAddress

use of com.google.security.zynamics.zylib.disassembly.IAddress in project binnavi by google.

the class EdgeCache method addEdges.

public void addEdges(final List<INaviEdge> edges) {
    final ImmutableMap<Integer, INaviEdge> edgesMap = Maps.uniqueIndex(edges, new Function<INaviEdge, Integer>() {

        @Override
        public Integer apply(final INaviEdge edge) {
            return edge.getId();
        }
    });
    edgesByIdCache.putAll(edgesMap);
    for (final INaviEdge edge : edges) {
        if (edge.getSource() instanceof IAddressNode && edge.getTarget() instanceof IAddressNode) {
            final IAddress sourceAddress = ((IAddressNode) edge.getSource()).getAddress();
            final IAddress targetAddress = ((IAddressNode) edge.getTarget()).getAddress();
            Integer sourceModuleId = null;
            Integer targetModuleId = null;
            if (edge.getSource() instanceof INaviCodeNode) {
                sourceModuleId = getModuleId((INaviCodeNode) edge.getSource());
            } else if (edge.getSource() instanceof INaviFunctionNode) {
                sourceModuleId = getModuleId((INaviFunctionNode) edge.getSource());
            }
            if (edge.getTarget() instanceof INaviCodeNode) {
                targetModuleId = getModuleId((INaviCodeNode) edge.getTarget());
            } else if (edge.getTarget() instanceof INaviFunctionNode) {
                targetModuleId = getModuleId((INaviFunctionNode) edge.getTarget());
            }
            if (targetModuleId != null && sourceModuleId != null) {
                UpdateAddressModuleIdCache(sourceAddress, sourceModuleId, targetAddress, targetModuleId, edge);
            }
        }
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) IAddressNode(com.google.security.zynamics.binnavi.disassembly.IAddressNode) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress)

Example 57 with IAddress

use of com.google.security.zynamics.zylib.disassembly.IAddress in project binnavi by google.

the class NodeCache method addNodes.

public void addNodes(final List<INaviViewNode> nodes) {
    nodeByIdCache.putAll(Maps.uniqueIndex(nodes, new Function<INaviViewNode, Integer>() {

        @Override
        public Integer apply(final INaviViewNode node) {
            return node.getId();
        }
    }));
    for (final INaviViewNode node : nodes) {
        if (node instanceof INaviCodeNode) {
            final IAddress nodeAddress = ((INaviCodeNode) node).getAddress();
            Integer moduleId = null;
            try {
                moduleId = ((INaviCodeNode) node).getParentFunction().getModule().getConfiguration().getId();
            } catch (final MaybeNullException e) {
                continue;
            }
            if (moduleId != null) {
                UpdateAddressModuleIdCache(nodeAddress, moduleId, node);
            }
        }
    }
}
Also used : Function(com.google.common.base.Function) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress)

Example 58 with IAddress

use of com.google.security.zynamics.zylib.disassembly.IAddress in project binnavi by google.

the class PostgreSQLFunctionNotificationParser method parseFunctionNotification.

private FunctionNotificationContainer parseFunctionNotification(final PGNotification notification, final SQLProvider provider) {
    final Pattern pattern = Pattern.compile(functionNotificationPattern);
    final Matcher matcher = pattern.matcher(notification.getParameter());
    if (!matcher.find()) {
        throw new IllegalStateException("IE02739: compiled pattern: " + pattern.toString() + " did not match notification: " + notification.getParameter());
    }
    final String databaseOperation = matcher.group(2);
    final Integer moduleId = Integer.parseInt(matcher.group(3));
    final IAddress functionAddress = new CAddress(new BigInteger(matcher.group(4)));
    final INaviModule module = provider.findModule(moduleId);
    return new FunctionNotificationContainer(moduleId, module, functionAddress, databaseOperation);
}
Also used : BigInteger(java.math.BigInteger) Pattern(java.util.regex.Pattern) FunctionNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionNotificationContainer) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) Matcher(java.util.regex.Matcher) BigInteger(java.math.BigInteger) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 59 with IAddress

use of com.google.security.zynamics.zylib.disassembly.IAddress in project binnavi by google.

the class PostgreSQLViewsLoader method loadViewFunctionMapping.

/**
 * Loads the view -> function mapping from the database.
 *
 * @param provider The SQL provider that provides the connection.
 * @param flowgraphs List of all native Flow graph views of a module.
 * @param functions List of all functions of a module.
 * @param module The module from which to load the mapping.
 *
 * @return A view -> function mapping and a function -> view mapping.
 *
 * @throws CouldntLoadDataException Thrown if the mapping could not be loaded.
 */
public static final ImmutableBiMap<INaviView, INaviFunction> loadViewFunctionMapping(final AbstractSQLProvider provider, final List<IFlowgraphView> flowgraphs, final List<INaviFunction> functions, final CModule module) throws CouldntLoadDataException {
    checkArguments(provider, module, flowgraphs, functions);
    final HashMap<Integer, INaviView> viewmap = new HashMap<Integer, INaviView>();
    for (final IFlowgraphView view : flowgraphs) {
        viewmap.put(view.getConfiguration().getId(), view);
    }
    final HashMap<IAddress, INaviFunction> functionMap = new HashMap<IAddress, INaviFunction>();
    for (final INaviFunction function : functions) {
        functionMap.put(function.getAddress(), function);
    }
    final CConnection connection = provider.getConnection();
    final String query = "SELECT view_id, function FROM " + CTableNames.FUNCTION_VIEWS_TABLE + " WHERE module_id = " + module.getConfiguration().getId();
    final HashMap<INaviView, INaviFunction> viewFunctionMap = new HashMap<INaviView, INaviFunction>();
    try {
        final ResultSet resultSet = connection.executeQuery(query, true);
        try {
            while (resultSet.next()) {
                final INaviView view = viewmap.get(resultSet.getInt("view_id"));
                final INaviFunction function = functionMap.get(PostgreSQLHelpers.loadAddress(resultSet, "function"));
                if ((view != null) && (function != null)) {
                    viewFunctionMap.put(view, function);
                }
            }
        } finally {
            resultSet.close();
        }
        return new ImmutableBiMap.Builder<INaviView, INaviFunction>().putAll(viewFunctionMap).build();
    } catch (final SQLException e) {
        throw new CouldntLoadDataException(e);
    }
}
Also used : IFlowgraphView(com.google.security.zynamics.binnavi.disassembly.IFlowgraphView) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CConnection(com.google.security.zynamics.binnavi.Database.CConnection) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) ResultSet(java.sql.ResultSet) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Example 60 with IAddress

use of com.google.security.zynamics.zylib.disassembly.IAddress in project binnavi by google.

the class ReadMemoryParser method parseSuccess.

@Override
public ReadMemoryReply parseSuccess(final int packetId, final int argumentCount) throws IOException {
    final IAddress address = parseAddress();
    final byte[] data = parseData();
    return new ReadMemoryReply(packetId, 0, address, data);
}
Also used : ReadMemoryReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.ReadMemoryReply) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress)

Aggregations

IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)82 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)28 ArrayList (java.util.ArrayList)23 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)19 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)16 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)15 Test (org.junit.Test)14 SQLException (java.sql.SQLException)12 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)11 ResultSet (java.sql.ResultSet)11 BigInteger (java.math.BigInteger)10 HashMap (java.util.HashMap)10 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)9 COperandTree (com.google.security.zynamics.binnavi.disassembly.COperandTree)7 INaviOperandTreeNode (com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode)7 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)7 CConnection (com.google.security.zynamics.binnavi.Database.CConnection)6 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)6 ReilFunction (com.google.security.zynamics.reil.ReilFunction)6 List (java.util.List)6