use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class CBreakpointPainter method paintBreakpoints.
/**
* Paints breakpoints into code nodes.
*
* @param manager The breakpoint manager that provides breakpoint information.
* @param node The visible BinNavi node where the breakpoint is painted.
* @param codeNode The code node that contains the raw data for the BinNavi node.
*/
public static void paintBreakpoints(final BreakpointManager manager, final NaviNode node, final INaviCodeNode codeNode) {
Preconditions.checkNotNull(manager, "IE02171: Manager argument can not be null");
Preconditions.checkNotNull(node, "IE02172: Node argument can not be null");
Preconditions.checkNotNull(codeNode, "IE02173: Code node argument can not be null");
for (final INaviInstruction instruction : codeNode.getInstructions()) {
final BreakpointAddress address = new BreakpointAddress(instruction.getModule(), new UnrelocatedAddress(instruction.getAddress()));
final int line = CCodeNodeHelpers.instructionToLine(codeNode, instruction);
if (manager.hasBreakpoint(BreakpointType.REGULAR, address)) {
// Only the address is highlighted when breakpoints are set on instructions
// visible in code nodes.
final int addressCharacters = address.getAddress().getAddress().toHexString().length();
node.setHighlighting(CHighlightLayers.BREAKPOINT_LAYER, line, 0, addressCharacters, BreakpointManager.getBreakpointColor(manager.getBreakpointStatus(address, BreakpointType.REGULAR)));
} else {
// If there is no breakpoint, clear potential older breakpoint line.
node.clearHighlighting(CHighlightLayers.BREAKPOINT_LAYER, line);
}
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class ZyCodeNodeBuilder method createLines.
/**
* Creates the instructions lines for a code node.
*
* @param node The node that provides the instructions.
* @param lines The created lines will be stored here.
* @param commentsToLineAssociation Information about the required comments is stored here.
* @param graphSettings Provides settings that influence node formatting.
* @param modifier Calculates the address strings. This argument can be null.
*
* @return The maximum size in characters of all lines put into the lines list.
*/
private static int createLines(final INaviCodeNode node, final List<Pair<String, List<CStyleRunData>>> lines, final HashMap<Pair<String, List<CStyleRunData>>, ArrayList<CommentContainer>> commentsToLineAssociation, final ZyGraphViewSettings graphSettings, final INodeModifier modifier) {
int maxLineWidth = 0;
final Map<INaviInstruction, INaviFunction> instructionToFunctionReferences = CReferenceFinder.getCodeReferenceMap(node);
for (final INaviInstruction instruction : node.getInstructions()) {
final Pair<String, List<CStyleRunData>> zyLineContent = ZyInstructionBuilder.buildInstructionLine(instruction, graphSettings, modifier);
final ArrayList<CommentContainer> commentLineContainerList = new ArrayList<CommentContainer>();
final List<IComment> localComments = node.getComments().getLocalInstructionComment(instruction);
if (localComments != null) {
for (final IComment localComment : localComments) {
commentLineContainerList.add(new CommentContainer(localComment));
}
}
final List<IComment> globalComments = instruction.getGlobalComment();
if (globalComments != null) {
for (final IComment globalComment : globalComments) {
commentLineContainerList.add(new CommentContainer(globalComment));
}
}
final List<IComment> functionComments = instructionToFunctionReferences.get(instruction) == null ? null : instructionToFunctionReferences.get(instruction).getGlobalComment();
if (functionComments != null) {
for (final IComment functionComment : functionComments) {
commentLineContainerList.add(new CommentContainer(functionComment));
}
}
commentsToLineAssociation.put(zyLineContent, commentLineContainerList);
final int lineWidth = zyLineContent.first().length();
if (lineWidth > maxLineWidth) {
maxLineWidth = lineWidth;
}
lines.add(zyLineContent);
}
return maxLineWidth;
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction 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.INaviInstruction in project binnavi by google.
the class PostgreSQLTypeInstanceFunctionsTests method createTypeInstanceReference5.
@Test
public void createTypeInstanceReference5() throws CouldntSaveDataException, CouldntLoadDataException, LoadCancelledException, CPartialLoadException {
module.load();
final TypeInstance typeInstance = module.getContent().getTypeInstanceContainer().getTypeInstances().get(0);
final TypeInstanceAddress address1 = typeInstance.getAddress();
final INaviFunction function = module.getContent().getFunctionContainer().getFunction(new CAddress("1001929", 16));
final INaviView view = module.getContent().getViewContainer().getView(function);
view.load();
final INaviInstruction instruction = view.getBasicBlocks().get(1).getInstructions().iterator().next();
Assert.assertNotNull(typeInstance);
provider.createTypeInstanceReference(typeInstance.getModule().getConfiguration().getId(), instruction.getAddress().toLong(), instruction.getOperandPosition(instruction.getOperands().get(0)), instruction.getOperands().get(0).getNodes().get(0).getId(), typeInstance.getId());
view.close();
module.close();
module.load();
view.load();
final TypeInstance typeInstance2 = module.getContent().getTypeInstanceContainer().getTypeInstance(typeInstance.getAddress());
Assert.assertEquals(address1, typeInstance2.getAddress());
final List<TypeInstanceReference> references = module.getContent().getTypeInstanceContainer().getReferences(typeInstance2);
Assert.assertTrue(!references.isEmpty());
Assert.assertEquals(instruction.getAddress(), references.get(0).getAddress());
Assert.assertEquals(instruction.getOperandPosition(instruction.getOperands().get(0)), references.get(0).getPosition());
Assert.assertEquals(instruction.getOperands().get(0).getNodes().get(0).getId(), references.get(0).getTreeNode().get().getId());
Assert.assertEquals(typeInstance.getId(), references.get(0).getTypeInstance().getId());
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class PostgreSQLProviderTest method testInstructionFunctionsAddReference1.
@Test
public void testInstructionFunctionsAddReference1() throws CouldntSaveDataException, CouldntLoadDataException, LoadCancelledException {
final INaviModule module = getProvider().loadModules().get(1);
module.load();
final INaviFunction function = module.getContent().getFunctionContainer().getFunctions().get(1800);
function.load();
final IBlockNode basicBlock = function.getBasicBlocks().get(0);
final INaviInstruction instruction = Iterables.get(basicBlock.getInstructions(), 1);
final COperandTree tree = instruction.getOperands().get(0);
final INaviOperandTreeNode node = tree.getRootNode();
final IAddress address = instruction.getAddress();
final ReferenceType type = ReferenceType.DATA;
final int references = node.getReferences().size();
PostgreSQLInstructionFunctions.addReference(getProvider(), node, address, type);
final INaviModule module2 = getProvider().loadModules().get(1);
module2.load();
final INaviFunction function2 = module2.getContent().getFunctionContainer().getFunctions().get(1800);
function2.load();
final IBlockNode basicBlock2 = function2.getBasicBlocks().get(0);
final INaviInstruction instruction2 = Iterables.get(basicBlock2.getInstructions(), 1);
final COperandTree tree2 = instruction2.getOperands().get(0);
final INaviOperandTreeNode node2 = tree2.getRootNode();
assertEquals(references + 1, node2.getReferences().size());
}
Aggregations