use of com.google.security.zynamics.zylib.disassembly.IAddress in project binnavi by google.
the class CGotoAddressField method buildAddressSelectionPopUp.
/**
* In the case of multiple modules zoom to address does not work therefore the user must select in
* which module to search.
*/
private void buildAddressSelectionPopUp() {
final CAddressSelectionDialog dlg = new CAddressSelectionDialog(m_parent, m_modules);
dlg.setVisible(true);
final INaviModule result = dlg.getSelectionResult();
final IAddress address = new CAddress(Long.parseLong(getText(), 16));
ZyZoomHelpers.zoomToAddress(m_graph, address, result, true);
}
use of com.google.security.zynamics.zylib.disassembly.IAddress 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;
}
use of com.google.security.zynamics.zylib.disassembly.IAddress in project binnavi by google.
the class PostgreSQLCommentNotificationParser method processFunctionCommentNotification.
/**
* Parses the notifications from the database back end for function comments by using a regular
* expression. If the regular expression matches the supplied {@link PGNotification} notification,
* a {@link CommentNotificationContainer} is build with the data from the notification.
*
* @param notification The {@link PGNotification} from the PostgreSQL database server.
* @param provider The {@link SQLProvider} which is used to communicate with the database.
*/
static CommentNotification processFunctionCommentNotification(final PGNotification notification, final SQLProvider provider) {
final Matcher matcher = FUNCTION_PATTERN.matcher(notification.getParameter());
if (!matcher.find()) {
return null;
}
final Integer notificationModuleId = Integer.parseInt(matcher.group(3));
final IAddress notificationFunctionAddress = new CAddress(new BigInteger(matcher.group(4)));
final Integer commentId = matcher.group(5).equals("null") ? null : Integer.parseInt(matcher.group(5));
final INaviModule module = provider.findModule(notificationModuleId);
if ((module == null) || !module.isLoaded()) {
return null;
}
final INaviFunction function = module.getContent().getFunctionContainer().getFunction(notificationFunctionAddress);
if (function == null) {
return null;
}
final CommentOperation operation = commentId == null ? CommentOperation.DELETE : CommentOperation.APPEND;
return new FunctionCommentNotificationContainer(function, operation, commentId);
}
use of com.google.security.zynamics.zylib.disassembly.IAddress in project binnavi by google.
the class MonoReilSolverResult method generateAddressToStateMapping.
/**
* Collect lattice results and generate a map which associates a lattice result with each address.
*
* @param startInstruction The instruction where collecting the results is started.
* @param trackIncoming Flag whether to start collecting immediately before or after the start
* instruction.
*
* @return The map which associates addresses with lattice results.
*/
@Override
public Map<IAddress, LatticeElementType> generateAddressToStateMapping(final IInstruction startInstruction, final boolean trackIncoming) {
final Map<IAddress, LatticeElementType> addressToLatticeElementMap = new TreeMap<>();
final Iterator<Pair<IInstructionGraphEdge, LatticeElementType>> iter = resultIterator();
while (iter.hasNext()) {
final Pair<IInstructionGraphEdge, LatticeElementType> edgeToLatticeElement = iter.next();
if (edgeToLatticeElement.first().isInstructionExit()) {
IAddress address;
if (hasResult(edgeToLatticeElement.first())) {
if (direction == AnalysisDirection.DOWN) {
address = graph.getSource(edgeToLatticeElement.first()).getReilInstruction().getAddress();
} else {
address = graph.getDestination(edgeToLatticeElement.first()).getReilInstruction().getAddress();
}
if (addressToLatticeElementMap.containsKey(address)) {
final ArrayList<LatticeElementType> combinelist = new ArrayList<>();
combinelist.add(edgeToLatticeElement.second());
combinelist.add(addressToLatticeElementMap.get(address));
addressToLatticeElementMap.put(address, lattice.combine(combinelist));
} else {
addressToLatticeElementMap.put(address, edgeToLatticeElement.second());
}
} else if (ReilHelpers.toNativeAddress(graph.getSource(edgeToLatticeElement.first()).getReilInstruction().getAddress()).equals(startInstruction.getAddress()) && (direction == AnalysisDirection.DOWN) && !trackIncoming) {
address = graph.getSource(edgeToLatticeElement.first()).getReilInstruction().getAddress();
addressToLatticeElementMap.put(address, edgeToLatticeElement.second());
} else if (ReilHelpers.toNativeAddress(graph.getDestination(edgeToLatticeElement.first()).getReilInstruction().getAddress()).equals(startInstruction.getAddress()) && (direction == AnalysisDirection.UP) && trackIncoming) {
address = graph.getDestination(edgeToLatticeElement.first()).getReilInstruction().getAddress();
addressToLatticeElementMap.put(address, edgeToLatticeElement.second());
}
}
}
return addressToLatticeElementMap;
}
use of com.google.security.zynamics.zylib.disassembly.IAddress in project binnavi by google.
the class TypeManagerTest method testNotifySubstitutionUpdated.
@Test
public void testNotifySubstitutionUpdated() throws CouldntSaveDataException {
final IAddress address = new CAddress(0x1000);
final INaviOperandTreeNode node = new MockOperandTreeNode();
final TypeSubstitution substitution = typeManager.createTypeSubstitution(node, typeSystem.intType, 0, 0, address);
final TypeSubstitutionChangedEventCollector events = new TypeSubstitutionChangedEventCollector();
typeManager.addListener(events);
typeManager.updateTypeSubstitution(node, substitution, typeSystem.uintType, new ArrayList<TypeMember>(), 0);
typeManager.updateTypeSubstitution(node, typeSystem.uintType.getId(), new Integer[0], 0);
final TypeSubstitutionChangedEventCollector expectedEvents = new TypeSubstitutionChangedEventCollector();
expectedEvents.substitutionsChanged(Sets.newHashSet(substitution));
expectedEvents.substitutionsChanged(Sets.newHashSet(substitution));
Assert.assertEquals(expectedEvents, events);
}
Aggregations