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