Search in sources :

Example 66 with IAddress

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

the class CReferenceFinder method fetchReferenceList.

/**
 * Searches for outgoing references of a tree node and its children.
 *
 * @param node The start node of the search,
 * @param instruction The instruction the node belongs to.
 * @param functions List where the found references are stored.
 */
private static void fetchReferenceList(final IOperandTreeNode node, final INaviInstruction instruction, final List<Pair<INaviInstruction, INaviFunction>> functions) {
    final List<IReference> references = node.getReferences();
    for (final IReference reference : references) {
        if (ReferenceType.isCodeReference(reference.getType())) {
            final IAddress target = reference.getTarget();
            final INaviFunction function = instruction.getModule().getContent().getFunctionContainer().getFunction(target);
            if (function != null) {
                functions.add(new Pair<INaviInstruction, INaviFunction>(instruction, function));
            }
        }
    }
    for (final IOperandTreeNode child : node.getChildren()) {
        fetchReferenceList(child, instruction, functions);
    }
}
Also used : IReference(com.google.security.zynamics.zylib.disassembly.IReference) IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 67 with IAddress

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

the class TypeInstanceContainerBackend method loadTypeInstanceReferences.

/**
 * Loads all type instance references for the module this {@link TypeInstanceContainerBackend} was
 * initialized with.
 *
 * @return A {@link List} of {@link TypeInstanceReference references} loaded from the database.
 *
 * @throws CouldntLoadDataException if the data could not be loaded from the database.
 */
public List<TypeInstanceReference> loadTypeInstanceReferences() throws CouldntLoadDataException {
    final List<RawTypeInstanceReference> rawReferences = provider.loadTypeInstanceReferences(module);
    final List<TypeInstanceReference> references = Lists.newArrayList();
    for (final RawTypeInstanceReference rawReference : rawReferences) {
        final TypeInstance typeInstance = instancesById.get(rawReference.getTypeInstanceId());
        final INaviView view = ViewManager.get(provider).getView(rawReference.getViewId());
        if (view != null) {
            final Optional<INaviOperandTreeNode> node = Optional.absent();
            final IAddress address = rawReference.getAddress();
            final int position = rawReference.getOperandPosition();
            final int expressionId = rawReference.getExpressionId();
            final TypeInstanceReference reference = new TypeInstanceReference(address, position, node, typeInstance, view);
            references.add(reference);
            referenceLookup.put(new InstanceReferenceLookup(address, position, expressionId), reference);
        }
    }
    return references;
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress)

Example 68 with IAddress

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

the class CCodeNodeParser method extractLine.

/**
 * Extracts a single line from the dataset.
 *
 * @param dataset The dataset which provides the information about the instructions.
 *
 * @return The generated instruction line. Null is returned when there are no more lines left in
 *         the dataset.
 *
 * @throws ParserException
 */
private InstructionLine extractLine(final ICodeNodeProvider dataset) throws ParserException {
    if (dataset.isAfterLast()) {
        return null;
    }
    final InstructionLine row = createLine(dataset);
    OperandTree tree = new OperandTree(dataset.getExpressionTreeId());
    int operandPositionCounter = 0;
    do {
        final IAddress currentAddress = dataset.getInstructionAddress();
        if (!row.getAddress().equals(currentAddress) || (row.getBasicBlock() != dataset.getNodeId())) {
            break;
        }
        final Integer position = dataset.getOperandPosition();
        if ((position == null) || (position != operandPositionCounter)) {
            // New operand found => Save the old operand
            if (tree.getNodes().size() != 0) {
                row.getOperands().add(tree);
            }
            // Create a new tree for the new operand.
            tree = new OperandTree(dataset.getExpressionTreeId());
            operandPositionCounter = position == null ? 0 : position;
        }
        if (position != null) {
            // No matter what happened before this if, at this
            // point the right operand tree is stored in the tree
            // variable. That means we can simply create the new
            // operand tree node and put it into the tree.
            // Note that at this point we assume that IDs of 0 are invalid. This
            // might not be the case at other databases and we need to look into
            // it.
            final int moduleId = dataset.getModule();
            final INaviModule module = modules.get(moduleId);
            tree.getNodes().add(createNewOperand(module, dataset));
        }
    } while (dataset.next());
    // without operands.
    if (tree.getNodes().size() != 0) {
        row.getOperands().add(tree);
    }
    return row;
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress)

Example 69 with IAddress

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

the class CCodeNodeParser method createNewOperand.

/**
 * Creates a new operand tree node object from data from a code node provider.
 *
 * @param module The module the loaded function belongs to.
 * @param dataset Provides the operand data.
 *
 * @return The created operand tree node object.
 *
 * @throws ParserException Thrown if not all data for the operand tree node object could be read.
 */
private static OperandTreeNode createNewOperand(final INaviModule module, final ICodeNodeProvider dataset) throws ParserException {
    final int expressionId = dataset.getExpressionTreeId();
    final int type = dataset.getExpressionTreeType();
    final String value = getValue(dataset, type);
    final Integer parentId = dataset.getParentId();
    final String replacementString = dataset.getReplacement();
    final IAddress functionAddress = dataset.getFunctionAddress();
    final Integer typeId = dataset.getSubstitutionTypeId();
    RawTypeSubstitution substitution = null;
    if (typeId != null) {
        substitution = new RawTypeSubstitution(dataset.getInstructionAddress(), dataset.getSubstitutionPosition(), expressionId, typeId, dataset.getSubstitutionPath(), dataset.getSubstitutionOffset());
    }
    final Integer instanceId = dataset.getTypeInstanceId() == null ? null : dataset.getTypeInstanceId();
    final int operandPosition = dataset.getOperandPosition();
    final IAddress address = dataset.getInstructionAddress();
    // The function parse references moves the dataset around quite heavily therefore all direct
    // access to the dataset must be done before.
    final List<CReference> references = parseReferences(expressionId, dataset);
    final INaviReplacement replacement = lookupReplacement(replacementString, module, functionAddress);
    return new OperandTreeNode(expressionId, type, value, getParentId(parentId), replacement, references, substitution, instanceId, operandPosition, address);
}
Also used : INaviReplacement(com.google.security.zynamics.binnavi.disassembly.INaviReplacement) RawTypeSubstitution(com.google.security.zynamics.binnavi.disassembly.types.RawTypeSubstitution) INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) CReference(com.google.security.zynamics.binnavi.disassembly.CReference) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress)

Example 70 with IAddress

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

the class CSearchResultComparator method compare.

@Override
public // NO_UCD
int compare(// NO_UCD
final SearchResult first, // NO_UCD
final SearchResult second) {
    IAddress firstAddress = null;
    IAddress secondAddress = null;
    if (first.getObject() instanceof NaviEdge) {
        firstAddress = getAddress((NaviEdge) first.getObject());
    } else if (first.getObject() instanceof NaviNode) {
        firstAddress = getAddress(((NaviNode) first.getObject()).getRawNode());
    }
    if (second.getObject() instanceof NaviEdge) {
        secondAddress = getAddress((NaviEdge) second.getObject());
    } else if (second.getObject() instanceof NaviNode) {
        secondAddress = getAddress(((NaviNode) second.getObject()).getRawNode());
    }
    if ((firstAddress == null) || (secondAddress == null)) {
        throw new IllegalStateException("IE01155: Address can't be null.");
    }
    return firstAddress.toBigInteger().compareTo(secondAddress.toBigInteger());
}
Also used : NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge)

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