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);
}
}
}
}
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);
}
}
}
}
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);
}
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);
}
}
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);
}
Aggregations