Search in sources :

Example 1 with IReplacement

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

the class ZyOperandBuilder method addOperand.

/**
 * Adds an operand to the instruction line.
 *
 * @param line The operand is added to this string.
 * @param styleRuns The style run for the operand is added to this list.
 * @param treeNode Provides the operand information.
 * @param modifier Calculates the address string (this argument can be null).
 */
private static void addOperand(final StringBuffer line, final List<CStyleRunData> styleRuns, final COperandTreeNode treeNode, final INodeModifier modifier) {
    final ColorsConfigItem colors = ConfigManager.instance().getColorSettings();
    final String typeSubstitution = getTypeSubstitution(treeNode);
    if (!typeSubstitution.isEmpty()) {
        // TODO(jannewger): we might want to introduce an additional setting so the user is able to
        // customize the way types are displayed.
        styleRuns.add(new CStyleRunData(line.length(), typeSubstitution.length(), colors.getVariableColor(), treeNode));
        line.append(typeSubstitution);
        return;
    }
    final IReplacement replacement = treeNode.getDisplayStyle() == OperandDisplayStyle.OFFSET ? treeNode.getReplacement() : null;
    // Colorize the current part of the operand
    if (replacement == null) {
        final Color color = getOperandColor(treeNode.getType());
        final String value = adjustValue(treeNode, modifier);
        styleRuns.add(new CStyleRunData(line.length(), value.length(), color, treeNode));
        line.append(value);
    } else {
        final String replacementString = determineReplacementString(treeNode, replacement);
        if (replacementString.equalsIgnoreCase("")) {
            final Color color = getOperandColor(treeNode.getType());
            final String value = adjustValue(treeNode, modifier);
            styleRuns.add(new CStyleRunData(line.length(), value.length(), color, treeNode));
            line.append(value);
            return;
        }
        if (treeNode.getType() == ExpressionType.IMMEDIATE_INTEGER) {
            if (replacement instanceof CFunctionReplacement) {
                styleRuns.add(new CStyleRunData(line.length(), replacementString.length(), colors.getFunctionColor(), treeNode));
            } else {
                styleRuns.add(new CStyleRunData(line.length(), replacementString.length(), colors.getVariableColor(), treeNode));
            }
        } else {
            final Color color = getOperandColor(treeNode.getType());
            styleRuns.add(new CStyleRunData(line.length(), replacementString.length(), color, treeNode));
        }
        line.append(replacementString);
    }
}
Also used : ColorsConfigItem(com.google.security.zynamics.binnavi.config.ColorsConfigItem) CFunctionReplacement(com.google.security.zynamics.binnavi.disassembly.CFunctionReplacement) CStyleRunData(com.google.security.zynamics.zylib.gui.zygraph.realizers.CStyleRunData) Color(java.awt.Color) IReplacement(com.google.security.zynamics.zylib.disassembly.IReplacement)

Aggregations

ColorsConfigItem (com.google.security.zynamics.binnavi.config.ColorsConfigItem)1 CFunctionReplacement (com.google.security.zynamics.binnavi.disassembly.CFunctionReplacement)1 IReplacement (com.google.security.zynamics.zylib.disassembly.IReplacement)1 CStyleRunData (com.google.security.zynamics.zylib.gui.zygraph.realizers.CStyleRunData)1 Color (java.awt.Color)1