use of com.google.security.zynamics.binnavi.Exceptions.MaybeNullException in project binnavi by google.
the class CLoadProgressPainter method getLoadPercentage.
/**
* Calculates the load percentage of the rendered view to display a progress bar.
*
* @param view The view to be loaded.
*
* @return The calculated load percentage.
*/
private static double getLoadPercentage(final INaviView view) {
final int totalSteps = ViewLoadEvents.values().length + GraphBuilderEvents.values().length;
final int loadState = view.getLoadState();
if (loadState == IDatabaseLoadProgressReporter.INACTIVE) {
try {
// The view was previously loaded and only needs to be built.
final ZyGraphBuilder builder = ZyGraphBuilderManager.instance().getBuilder(view);
return (1.0 * (ViewLoadEvents.values().length + builder.getBuildStep())) / totalSteps;
} catch (final MaybeNullException exception) {
return 0;
}
} else {
return (1.0 * view.getLoadState()) / totalSteps;
}
}
use of com.google.security.zynamics.binnavi.Exceptions.MaybeNullException in project binnavi by google.
the class CViewInserter method insertCodeNode.
/**
* Clones a source node and inserts the cloned node into the target view.
*
* @param target The target view where the node is inserted.
* @param node Node from the source view that is cloned.
*
* @return The cloned code node.
*/
private static INaviCodeNode insertCodeNode(final INaviView target, final INaviCodeNode node) {
// TODO: cloning the node is a bad solution since this just fixes the symptoms: instructions are
// closed two times
final INaviCodeNode sourceNode = (INaviCodeNode) node.cloneNode();
final Iterable<INaviInstruction> instructions = sourceNode.getInstructions();
final ArrayList<INaviInstruction> instructionList = Lists.newArrayList(instructions);
CCodeNode codeNode;
try {
codeNode = target.getContent().createCodeNode(sourceNode.getParentFunction(), instructionList);
} catch (final MaybeNullException e) {
codeNode = target.getContent().createCodeNode(null, instructionList);
}
if (sourceNode.getComments().getGlobalCodeNodeComment() != null) {
codeNode.getComments().initializeGlobalCodeNodeComment(sourceNode.getComments().getGlobalCodeNodeComment());
}
if (sourceNode.getComments().getLocalCodeNodeComment() != null) {
codeNode.getComments().initializeLocalCodeNodeComment(sourceNode.getComments().getLocalCodeNodeComment());
}
final Iterable<INaviInstruction> newInstructions = codeNode.getInstructions();
for (int i = 0; i < Iterables.size(instructions); i++) {
codeNode.getComments().initializeLocalInstructionComment(Iterables.get(newInstructions, i), sourceNode.getComments().getLocalInstructionComment(Iterables.get(instructions, i)));
}
return codeNode;
}
use of com.google.security.zynamics.binnavi.Exceptions.MaybeNullException in project binnavi by google.
the class CCodeNodeMenu method addRenameFunctionMenu.
private void addRenameFunctionMenu(final INaviCodeNode codeNode, final CGraphModel model) {
try {
final INaviFunction function = codeNode.getParentFunction();
final INaviView view = function.getModule().getContent().getViewContainer().getView(function);
add(new CChangeFunctionNameAction(model.getParent(), view));
} catch (final MaybeNullException e) {
// no parent function no menu entry we are ok with this.
}
}
use of com.google.security.zynamics.binnavi.Exceptions.MaybeNullException in project binnavi by google.
the class CCodeNodeMenu method addOpenOriginalFunctionMenu.
private void addOpenOriginalFunctionMenu(final CGraphModel model, final NaviNode node) {
final INaviCodeNode rawNode = (INaviCodeNode) node.getRawNode();
try {
final INaviFunction nodeFunction = rawNode.getParentFunction();
final INaviFunction viewFunction = model.getViewContainer().getFunction(model.getGraph().getRawView());
if (nodeFunction != viewFunction) {
add(CActionProxy.proxy(new COpenOriginalFunction(model.getParent(), model.getViewContainer(), nodeFunction)));
}
} catch (final MaybeNullException e) {
// If there is no original function then we can not open it.
}
}
use of com.google.security.zynamics.binnavi.Exceptions.MaybeNullException 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.
}
}
Aggregations