use of com.google.security.zynamics.zylib.disassembly.OperandOrderIterator in project binnavi by google.
the class PostgreSQLTypesNotificationParser method findOperandTreeNode.
/**
* Only used internally to find the necessary {@link INaviOperandTreeNode operand node} where a
* {@link TypeSubstitution type substitution} is associated to.
*
* @param provider The {@link SQLProvider} used to differentiate between the different caches used
* for getting {@link INaviInstruction instructions}.
* @param moduleId The id of the {@link INaviModule module} this {@link TypeSubstitution type
* substitution} is associated to.
* @param address The {@link CAddress} of the {@link INaviInstruction instruction} where the
* {@link TypeSubstitution type substitution} is associated to.
* @param position The {@link INaviOperandTree operand tree} position where the
* {@link TypeSubstitution type substitution} is associated to.
* @param operandNodeId the id of the {@link INaviOperandTreeNode operand node} to which the
* {@link TypeSubstitution type substitution} is associated.
* @return A {@link INaviOperandTreeNode} if it is in the cache otherwise null;
*/
private INaviOperandTreeNode findOperandTreeNode(final SQLProvider provider, final int moduleId, final CAddress address, final int position, final int operandNodeId) {
final INaviInstruction instruction = InstructionCache.get(provider).getInstructionByAddress(address, moduleId);
if (instruction != null) {
final INaviOperandTree operandTree = instruction.getOperands().get(position);
final INaviOperandTreeNode root = operandTree.getRootNode();
final OperandOrderIterator iterator = new OperandOrderIterator(root);
while (iterator.next()) {
final INaviOperandTreeNode currentNode = (INaviOperandTreeNode) iterator.current();
if (currentNode.getId() == operandNodeId) {
return currentNode;
}
}
}
return null;
}
use of com.google.security.zynamics.zylib.disassembly.OperandOrderIterator in project binnavi by google.
the class ZyOperandBuilder method buildOperand.
/**
* Builds a single operand.
*
* @param instruction The instruction in question.
* @param operandTree Provides information about the operand to build.
* @param graphSettings Provides the graph settings.
* @param line String buffer where the operands string is added.
* @param styleRun Style runs list where the formatting information is added.
* @param modifier Calculates the address string (this argument can be null).
* @param counter The index of the operand in the operands list of the instruction.
*/
private static void buildOperand(final INaviInstruction instruction, final INaviOperandTree operandTree, final ZyGraphViewSettings graphSettings, final StringBuffer line, final List<CStyleRunData> styleRun, final INodeModifier modifier, final int counter) {
// We use an iterator that gives us the individual operands in correct (printing) order.
final OperandOrderIterator iter = new OperandOrderIterator(operandTree.getRootNode());
final boolean isVariableAccess = graphSettings.getDisplaySettings().getSimplifiedVariableAccess() && isVariableAccess(operandTree.getRootNode());
boolean hasMemderef = false;
boolean hasExpressionList = false;
boolean needsComma = false;
boolean hasExclamationMark = false;
COperandTreeNode memParent = null;
final ColorsConfigItem colors = ConfigManager.instance().getColorSettings();
while (iter.next()) {
if (isVariableAccess) {
skipMemoryAccess(iter);
}
// Process the next operand part
final COperandTreeNode treeNode = (COperandTreeNode) iter.current();
hasExclamationMark = "!".equals(treeNode.getValue());
if (skipOperand(treeNode, hasExpressionList)) {
continue;
}
if (needsComma) {
styleRun.add(new CStyleRunData(line.length(), 1, colors.getOperandSeparatorColor()));
line.append(',');
}
if (hasExpressionList) {
needsComma = true;
}
if (hasMemderef && !isAncestor(treeNode, memParent)) {
// Since closing "]" characters are not part of the operand trees,
// we have to handle memory dereference brackets manually.
styleRun.add(new CStyleRunData(line.length(), 1, colors.getMemRefColor()));
line.append(']');
hasMemderef = false;
}
hasExpressionList = (treeNode.getType() == ExpressionType.EXPRESSION_LIST) || hasExpressionList;
if (treeNode.getType() == ExpressionType.MEMDEREF) {
memParent = treeNode;
hasMemderef = true;
}
addOperand(line, styleRun, treeNode, modifier);
}
addClosingDelimiters(line, styleRun, hasMemderef, hasExpressionList, hasExclamationMark);
addCommaSeparator(line, styleRun, instruction.getOperands(), counter);
}
use of com.google.security.zynamics.zylib.disassembly.OperandOrderIterator in project binnavi by google.
the class PostgreSQLTypeInstancesNotificationParser method informExpressionTypeInstanceNotification.
/**
* This function informs the {@link TypeInstanceContainer} about changes related to expression
* type instances also known as cross references for type instances.
*
* @param container The {@link TypeInstancesNotificationContainer} holding the parsed information.
* @param provider The {@link SQLProvider} used to access the database.
* @throws CouldntLoadDataException
*/
private void informExpressionTypeInstanceNotification(final TypeInstancesNotificationContainer container, final SQLProvider provider) throws CouldntLoadDataException {
final TypeInstanceContainer typeContainer = provider.findModule(container.getModuleId()).getContent().getTypeInstanceContainer();
if (container.getDatabaseOperation().equals("INSERT")) {
final TypeInstanceReference reference = typeContainer.loadInstanceReference(container.getTypeInstanceId(), container.getAddress().get(), container.getPosition().get(), container.getExpressionId().get());
final INaviInstruction instruction = InstructionCache.get(provider).getInstructionByAddress(reference.getAddress(), reference.getTypeInstance().getModule().getConfiguration().getId());
if (instruction != null) {
final INaviOperandTree operandTree = instruction.getOperands().get(reference.getPosition());
final INaviOperandTreeNode root = operandTree.getRootNode();
final OperandOrderIterator iterator = new OperandOrderIterator(root);
while (iterator.next()) {
final INaviOperandTreeNode currentNode = (INaviOperandTreeNode) iterator.current();
if (currentNode.getId() == container.getExpressionId().get()) {
typeContainer.initializeTypeInstanceReference(reference.getAddress(), reference.getPosition(), container.getTypeInstanceId(), currentNode);
break;
}
}
}
} else if (container.getDatabaseOperation().equals("UPDATE")) {
// currently not be possible at all.
} else if (container.getDatabaseOperation().equals("DELETE")) {
typeContainer.deleteReference(container.getTypeInstanceId(), container.getAddress().get(), container.getPosition().get(), container.getExpressionId().get());
} else {
throw new IllegalStateException("Error: the database operation " + container.getDatabaseOperation() + " is currently not supported.");
}
}
Aggregations