use of com.google.security.zynamics.binnavi.disassembly.INaviFunction in project binnavi by google.
the class PostgreSQLProviderTest method testInstructionFunctionsAddReference6.
@Test(expected = CouldntSaveDataException.class)
public void testInstructionFunctionsAddReference6() 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;
PostgreSQLInstructionFunctions.addReference(getProvider(), node, address, type);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviFunction in project binnavi by google.
the class Module method createCallgraph.
/**
* Creates the native call graph.
*/
private void createCallgraph() {
final DirectedGraph<ICallgraphNode, ICallgraphEdge> graph = m_module.getContent().getNativeCallgraph();
final List<FunctionBlock> blocks = new ArrayList<FunctionBlock>();
final List<FunctionEdge> edges = new ArrayList<FunctionEdge>();
final HashMap<ICallgraphNode, FunctionBlock> blockMap = new HashMap<ICallgraphNode, FunctionBlock>();
final HashMap<INaviFunction, Function> functionMap = new HashMap<INaviFunction, Function>();
for (final Function function : m_functions) {
functionMap.put(function.getNative(), function);
}
for (final ICallgraphNode block : graph.getNodes()) {
final FunctionBlock newBlock = new FunctionBlock(functionMap.get(block.getFunction()));
blockMap.put(block, newBlock);
blocks.add(newBlock);
}
for (final ICallgraphEdge edge : graph.getEdges()) {
final FunctionBlock source = blockMap.get(edge.getSource());
final FunctionBlock target = blockMap.get(edge.getTarget());
edges.add(new FunctionEdge(source, target));
}
m_callgraph = new Callgraph(blocks, edges);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviFunction in project binnavi by google.
the class CCodeNodeParser method createLine.
/**
* Creates raw instruction data from a code node provider.
*
* @param instructionSet Provides the raw data.
*
* @return The generated raw data object.
*
* @throws ParserException Thrown if not all instruction data could be read.
*/
private InstructionLine createLine(final ICodeNodeProvider instructionSet) throws ParserException {
final InstructionLine row = new InstructionLine();
row.setBasicBlock(instructionSet.getNodeId());
row.setAddress(instructionSet.getInstructionAddress());
row.setMnemonic(instructionSet.getMnemonic());
row.setArchitecture(instructionSet.getInstructionArchitecture());
final int moduleId = instructionSet.getModule();
final IAddress parentFunction = instructionSet.getParentFunction();
final INaviModule module = modules.get(moduleId);
if (module == null) {
throw new ParserException(String.format("Instruction with ID %d has unknown module with ID %d", row.getId(), moduleId));
}
final INaviFunction function = parentFunction == null ? null : module.getContent().getFunctionContainer().getFunction(parentFunction);
row.setParentFunction(function);
if ((parentFunction != null) && (function == null)) {
throw new ParserException(String.format("Instruction with ID %d has unknown parent function with address %s", row.getId(), parentFunction.toHexString()));
}
row.setX(instructionSet.getX());
row.setY(instructionSet.getY());
row.setColor(new Color(instructionSet.getColor()));
row.setBorderColor(new Color(instructionSet.getBorderColor()));
row.setSelected(instructionSet.isSelected());
row.setVisible(instructionSet.isVisible());
row.setLocalNodeCommentId(instructionSet.getLocalNodeCommentId());
row.setGlobalNodeComment(instructionSet.getGlobalNodeCommentId());
row.setGlobalInstructionComment(instructionSet.getGlobalInstructionCommentId());
row.setLocalInstructionComment(instructionSet.getLocalInstructionCommentId());
row.setData(instructionSet.getData());
row.setModule(module);
return row;
}
use of com.google.security.zynamics.binnavi.disassembly.INaviFunction in project binnavi by google.
the class CCodeNodeParser method createCurrentNode.
/**
* Creates a new code node.
*
* @param resultSet Provides the data for the code node.
*
* @return The created code node object.
*
* @throws ParserException Thrown if the node data could not be read.
* @throws CPartialLoadException Thrown if not all required modules are loaded.
*/
private CCodeNode createCurrentNode(final ICodeNodeProvider resultSet) throws ParserException, CPartialLoadException {
final int nodeId = resultSet.getNodeId();
final int moduleId = resultSet.getModule();
final IAddress parentFunction = resultSet.getParentFunction();
final INaviModule module = modules.get(moduleId);
if (module == null) {
throw new ParserException(String.format("Node with ID %d has unknown parent module with ID %d", nodeId, moduleId));
}
if (!module.isLoaded()) {
try {
module.load();
} catch (final CouldntLoadDataException e) {
throw new CPartialLoadException("E00066: The view could not be loaded because not all modules that form the view could be loaded", module);
} catch (final LoadCancelledException e) {
throw new CPartialLoadException("E00067: The view could not be loaded because it was cancelled", module);
}
}
final INaviFunction function = parentFunction == null ? null : module.getContent().getFunctionContainer().getFunction(parentFunction);
if ((parentFunction != null) && (function == null)) {
throw new ParserException(String.format("Node with ID %d has unknown parent function with address %s", nodeId, parentFunction.toHexString()));
}
final double x = resultSet.getX();
final double y = resultSet.getY();
final double width = resultSet.getWidth();
final double height = resultSet.getHeight();
final Color color = new Color(resultSet.getColor());
final Color bordercolor = new Color(resultSet.getBorderColor());
final boolean selected = resultSet.isSelected();
final boolean visible = resultSet.isVisible();
final Integer localCodeNodeCommentId = resultSet.getLocalNodeCommentId();
final Integer globalCodeNodeCommentId = resultSet.getGlobalNodeCommentId();
// TODO(timkornau): final new Set<CTag>! must replaced by a set which
// contains the loaded node
// tags from the DB
final CCodeNode codeNode = new CCodeNode(nodeId, x, y, width, height, color, bordercolor, selected, visible, null, function, new HashSet<CTag>(), sqlProvider);
if (localCodeNodeCommentId != null) {
localCommentIdToCodeNode.put(localCodeNodeCommentId, codeNode);
}
if (globalCodeNodeCommentId != null) {
globalCommentIdToCodeNode.put(globalCodeNodeCommentId, codeNode);
}
return codeNode;
}
use of com.google.security.zynamics.binnavi.disassembly.INaviFunction in project binnavi by google.
the class CResolveAllFunctionDialog method resolveAllFunctions.
/**
* Takes the information from the GUI and forwards functions.
*/
private int resolveAllFunctions() {
int counter = 0;
for (final INaviModule currentModule : m_targetModules) {
for (final INaviFunction currentFunction : currentModule.getContent().getFunctionContainer().getFunctions()) {
final String originalName = currentFunction.getOriginalModulename();
if (!originalName.equalsIgnoreCase(currentModule.getConfiguration().getName()) && !originalName.equalsIgnoreCase("")) {
for (final INaviModule targetModule : m_sourceModules) {
final String targetModuleName = targetModule.getConfiguration().getName();
if (targetModuleName.toUpperCase().contains(originalName.toUpperCase()) && CFunctionHelpers.isForwardableFunction(currentFunction) && (currentFunction.getForwardedFunctionModuleId() == 0)) {
String currentFunctionName = currentFunction.getName();
if (currentFunctionName.startsWith("__imp_")) {
currentFunctionName = currentFunctionName.substring("__imp_".length());
}
try {
final INaviFunction targetFunction = targetModule.getContent().getFunctionContainer().getFunction(currentFunctionName);
currentFunction.setForwardedFunction(targetFunction);
++counter;
} catch (final MaybeNullException exception) {
} catch (final CouldntSaveDataException exception) {
CUtilityFunctions.logException(exception);
}
}
}
}
}
}
return counter;
}
Aggregations