use of com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode in project binnavi by google.
the class CExpressionEvaluator method evaluateOperator.
/**
* Evaluates an operator node.
*
* @param node The operator node to evaluate.
* @param registers Register values to use during expression evaluation.
* @param debugger The active debugger.
* @param module The module the node belongs to.
*
* @return The evaluated value.
*
* @throws CExpressionEvaluationException Thrown if the expression could not be evaluated.
*/
private static BigInteger evaluateOperator(final INaviOperandTreeNode node, final ImmutableList<RegisterValue> registers, final IDebugger debugger, final INaviModule module) throws CExpressionEvaluationException {
final List<INaviOperandTreeNode> children = node.getChildren();
BigInteger initial = evaluateExpression(children.get(0), registers, debugger, module);
for (int i = 1; i < children.size(); i++) {
if (node.getValue().equals("+")) {
initial = initial.add(evaluateExpression(children.get(i), registers, debugger, module));
} else if (node.getValue().equals("-")) {
initial = initial.subtract(evaluateExpression(children.get(i), registers, debugger, module));
} else if (node.getValue().equals("*")) {
initial = initial.multiply(evaluateExpression(children.get(i), registers, debugger, module));
} else {
throw new CExpressionEvaluationException(String.format("Unknown operand '%s'", node.getValue()));
}
}
return initial;
}
use of com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode in project binnavi by google.
the class CCodeNodeUpdater method initializeListeners.
/**
* Initializes the listeners that are responsible for updating the code node.
*/
private void initializeListeners() {
try {
codeNode.getParentFunction().addListener(functionUpdater);
codeNode.getParentFunction().getModule().addListener(moduleUpdater);
} catch (final MaybeNullException exception) {
// The code nodes does not have a parent function, therefore the information
// about the parent function is not shown in the code and does not have to
// be processed when updating.
}
final HashMap<INaviInstruction, INaviFunction> referenceMap = CReferenceFinder.getCodeReferenceMap(codeNode);
for (final INaviFunction functionReference : Sets.newHashSet(referenceMap.values())) {
functionReference.addListener(functionUpdater);
}
codeNode.addListener(codeNodeListener);
for (final INaviInstruction instruction : codeNode.getInstructions()) {
instruction.addListener(instructionUpdater);
for (final COperandTree tree : instruction.getOperands()) {
for (final INaviOperandTreeNode currentNode : tree.getNodes()) {
currentNode.addListener(operandTreeUpdater);
}
}
}
final Iterator<CTag> it = codeNode.getTagsIterator();
while (it.hasNext()) {
it.next().addListener(tagUpdater);
}
for (final IDebugger debugger : provider.getDebuggers()) {
debugger.getProcessManager().addListener(debuggerUpdater);
}
provider.addListener(debuggerProviderListener);
graph.getSettings().getDisplaySettings().addListener(settingsUpdater);
try {
codeNode.getParentFunction().getModule().getTypeManager().addListener(substitutionsUpdater);
} catch (final MaybeNullException exception) {
// If the code node doesn't have a a parent function, it is not in the database and therefore
// cannot receive type substitutions.
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode in project binnavi by google.
the class BaseTypeTransferHandler method createOrUpdateTypeSubstitution.
/**
* Locate operand tree node and use type manager to assign type substitution.
*/
private boolean createOrUpdateTypeSubstitution(final DragAndDropSupportWrapper wrapper) throws UnsupportedFlavorException, IOException, CouldntSaveDataException {
final INaviOperandTreeNode node = wrapper.determineDropNode();
if (!isLegalDropNode(node)) {
return false;
}
final BaseType baseType = wrapper.getDroppedBaseType();
if (node.getTypeSubstitution() != null) {
typeManager.updateTypeSubstitution(node, node.getTypeSubstitution(), baseType, new ArrayList<TypeMember>(), 0);
} else {
// When creating a substitution via drag and drop, the offset is always zero to have a
// better workflow for the user (otherwise we would need an additional dialog each time).
typeManager.createTypeSubstitution(node, baseType, node.getOperandPosition(), 0, /* offset */
node.getInstructionAddress());
}
return true;
}
use of com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode in project binnavi by google.
the class ZyOperandBuilder method getUnsignedBigIntegerString.
private static String getUnsignedBigIntegerString(final BigInteger value, final COperandTreeNode node, final int radix) {
// We only need to take care of values which are less than zero.
if (value.signum() != -1) {
return value.toString(radix);
}
INaviOperandTreeNode currentNode = node.getParent();
while (currentNode.getType() != ExpressionType.SIZE_PREFIX) {
if (currentNode.getParent() == null) {
throw new IllegalStateException("Error: could not determine size of operand.");
}
currentNode = currentNode.getParent();
}
final BigInteger twosComplement = value.abs().not().add(BigInteger.ONE);
// information of an operand node need to be stored in different fields. b/11566525
switch(currentNode.getValue()) {
case "byte":
return twosComplement.and(new BigInteger("FF", 16)).toString(radix);
case "word":
return twosComplement.and(new BigInteger("FFFF", 16)).toString(radix);
case "dword":
return twosComplement.and(new BigInteger("FFFFFFFF", 16)).toString(radix);
case "fword":
return twosComplement.and(new BigInteger("FFFFFFFFFFFF", 16)).toString(radix);
case "qword":
return twosComplement.and(new BigInteger("FFFFFFFFFFFFFFFF", 16)).toString(radix);
case "oword":
return twosComplement.and(new BigInteger("FFFFFFFFFFFFFFFFFFFF", 16)).toString(radix);
default:
throw new IllegalStateException("Error: size of operand tree node is not supported.");
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode in project binnavi by google.
the class ZyOperandBuilder method isOperatorVariableAccess.
/**
* Determines whether a given node is a variable access node that can be simplified.
*
* @param node The node to check.
*
* @return True, if the node can be simplified. False, otherwise.
*/
private static boolean isOperatorVariableAccess(final INaviOperandTreeNode node) {
final List<INaviOperandTreeNode> children = node.getChildren();
if (children.size() == 2) {
// An expression can be simplified if it is of the form 'REGISTER + VARIABLE'
final INaviOperandTreeNode child0 = children.get(0);
final INaviOperandTreeNode child1 = children.get(1);
return isVariable(child0) ^ isVariable(child1);
} else {
return false;
}
}
Aggregations