Search in sources :

Example 11 with IAddress

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);
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 12 with IAddress

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;
}
Also used : HashMap(java.util.HashMap) FunctionType(com.google.security.zynamics.zylib.disassembly.FunctionType) ArrayList(java.util.ArrayList) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) BaseType(com.google.security.zynamics.binnavi.disassembly.types.BaseType) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Example 13 with IAddress

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);
}
Also used : BigInteger(java.math.BigInteger) CommentOperation(com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation) FunctionCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionCommentNotificationContainer) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) Matcher(java.util.regex.Matcher) BigInteger(java.math.BigInteger) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 14 with IAddress

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;
}
Also used : IInstructionGraphEdge(com.google.security.zynamics.reil.algorithms.mono2.common.instructiongraph.interfaces.IInstructionGraphEdge) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) Pair(com.google.security.zynamics.zylib.general.Pair)

Example 15 with IAddress

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);
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) MockOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.MockOperandTreeNode) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

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