use of com.google.security.zynamics.binnavi.disassembly.INaviFunction in project binnavi by google.
the class PostgreSQLFunctionsLoader method parseFunctionInformation.
/**
* This function parses a {@link ResultSet result set} from a database query and generates a
* {@link List} of {@link INaviFunction} from it.
*
* @param resultSet The {@link ResultSet} in which the result from the database query is stored.
* @param provider The {@link SQLProvider} to access the database with.
* @param module The {@link INaviModule} to which the {@link INaviFunction function(s)} are
* associated.
*
* @return A {@link List} of {@link INaviFunction functions} parsed from the {@link ResultSet
* resultSet}.
*
* @throws SQLException if the {@link ResultSet} could not be parsed.
* @throws CouldntLoadDataException if the associated comments could not be loaded from the
* database.
*/
private static List<INaviFunction> parseFunctionInformation(final ResultSet resultSet, final SQLProvider provider, final INaviModule module) throws SQLException, CouldntLoadDataException {
final List<INaviFunction> functions = Lists.newArrayList();
final Map<Integer, INaviFunction> commentIdToFunction = new HashMap<Integer, INaviFunction>();
try {
while (resultSet.next()) {
final IAddress address = PostgreSQLHelpers.loadAddress(resultSet, "address");
final String name = resultSet.getString("name");
final String originalName = resultSet.getString("original_name");
Integer globalCommentId = resultSet.getInt("global_comment");
if (resultSet.wasNull()) {
globalCommentId = null;
}
final String description = resultSet.getString("description");
final FunctionType type = FunctionType.valueOf(resultSet.getString("type").toUpperCase());
final String parentModuleName = resultSet.getString("parent_module_name");
final int parentModuleId = resultSet.getInt("parent_module_id");
final IAddress parentModuleFunction = resultSet.wasNull() ? null : PostgreSQLHelpers.loadAddress(resultSet, "parent_module_function");
final Integer nodeCount = resultSet.getInt("bbcount");
final Integer edgeCount = resultSet.getInt("edgeCount");
final Integer indegree = resultSet.getInt("incount");
final Integer outdegree = resultSet.getInt("outcount");
Integer stackFrameId = resultSet.getInt("stack_frame");
if (resultSet.wasNull()) {
stackFrameId = null;
}
Integer prototypeId = resultSet.getInt("prototype");
if (resultSet.wasNull()) {
prototypeId = null;
}
final INaviView view = ViewManager.get(provider).getView(resultSet.getInt("view_id"));
final BaseType stackFrame = stackFrameId == null ? null : module.getTypeManager().getBaseType(stackFrameId);
if (stackFrameId != null) {
module.getTypeManager().setStackFrame(stackFrame);
}
final BaseType prototype = prototypeId == null ? null : module.getTypeManager().getBaseType(prototypeId);
final CFunction function = new CFunction(module, view, address, name, originalName, description, indegree, outdegree, nodeCount, edgeCount, type, parentModuleName, parentModuleId, parentModuleFunction, stackFrame, prototype, provider);
if (globalCommentId != null) {
commentIdToFunction.put(globalCommentId, function);
}
functions.add(function);
}
} finally {
resultSet.close();
}
if (!commentIdToFunction.isEmpty()) {
final HashMap<Integer, ArrayList<IComment>> commentIdToComments = PostgreSQLCommentFunctions.loadMultipleCommentsById(provider, commentIdToFunction.keySet());
for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdToComments.entrySet()) {
CommentManager.get(provider).initializeGlobalFunctionComment(commentIdToFunction.get(commentIdToComment.getKey()), commentIdToComment.getValue());
}
}
return functions;
}
use of com.google.security.zynamics.binnavi.disassembly.INaviFunction in project binnavi by google.
the class CReferenceFinder method fetchReferenceMap.
/**
* Fetch for outgoing code references of a tree node and all of its children.
*
* @param node The start node of the search.
* @param instruction The instruction the operand tree belongs to.
* @param functions The map of code references.
*/
private static void fetchReferenceMap(final IOperandTreeNode node, final INaviInstruction instruction, final Map<INaviInstruction, INaviFunction> functions) {
final List<IReference> references = node.getReferences();
for (final IReference reference : references) {
if (ReferenceType.isCodeReference(reference.getType())) {
final IAddress target = reference.getTarget();
final INaviFunction function = instruction.getModule().getContent().getFunctionContainer().getFunction(target);
if (function != null) {
functions.put(instruction, function);
}
}
}
for (final IOperandTreeNode child : node.getChildren()) {
fetchReferenceMap(child, instruction, functions);
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviFunction in project binnavi by google.
the class BreakpointHelpersTest method setUp.
@Before
public void setUp() throws DebugExceptionWrapper, CouldntLoadDataException, LoadCancelledException, FileReadException {
ConfigManager.instance().read();
final CDatabase database = new CDatabase("", "", "", "", "", "", "", false, false);
final Database apiDatabase = new Database(database);
final SQLProvider mockProvider = new MockSqlProvider();
final ITreeNode<CTag> nodeRootNode = new TreeNode<CTag>(new CTag(0, "", "", TagType.NODE_TAG, mockProvider));
final Tree<CTag> nodeTagTree = new Tree<CTag>(nodeRootNode);
final TagManager nodeTagManager = new TagManager(new CTagManager(nodeTagTree, TagType.NODE_TAG, mockProvider));
final ITreeNode<CTag> viewRootNode = new TreeNode<CTag>(new CTag(0, "", "", TagType.VIEW_TAG, mockProvider));
final Tree<CTag> viewTagTree = new Tree<CTag>(viewRootNode);
final TagManager viewTagManager = new TagManager(new CTagManager(viewTagTree, TagType.VIEW_TAG, mockProvider));
m_module = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, mockProvider);
m_module.load();
m_mockDebugger = new MockDebugger(m_moduleDebugSettings);
m_mockDebugger.connect();
m_debugger = new Debugger(m_mockDebugger);
final INaviFunction parentFunction = m_module.getContent().getFunctionContainer().getFunctions().get(0);
m_mockDebugger.setAddressTranslator(m_module, new CAddress(0), new CAddress(0x1000));
final ViewContainer viewContainer = new Module(apiDatabase, m_module, nodeTagManager, viewTagManager);
final INaviView naviView = new MockView(mockProvider);
final Function apiFunction = new Function(ModuleFactory.get(), parentFunction);
final COperandTreeNode rootNode1 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "eax", null, new ArrayList<IReference>(), mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
final COperandTreeNode rootNode2 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "ebx", null, new ArrayList<IReference>(), mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
final COperandTree operand1 = new COperandTree(rootNode1, mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
final COperandTree operand2 = new COperandTree(rootNode2, mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
final List<COperandTree> operands = Lists.newArrayList(operand1, operand2);
final CInstruction internalInstruction = new CInstruction(true, m_module, new CAddress(0x1234), "mov", operands, new byte[] { 1, 2, 3 }, "x86-32", mockProvider);
m_view = new View(viewContainer, naviView, nodeTagManager, viewTagManager);
m_node = m_view.createCodeNode(apiFunction, Lists.newArrayList(new Instruction(internalInstruction)));
setM_functionNode(m_view.createFunctionNode(apiFunction));
}
use of com.google.security.zynamics.binnavi.disassembly.INaviFunction in project binnavi by google.
the class CGraphInliner method inlineAll.
/**
* Inlines all function calls of a given graph.
*
* @param parent Parent window used for dialogs.
* @param container Contains the functions to be inlined.
* @param graph Graph where the inline operation takes place.
*/
public static void inlineAll(final JFrame parent, final IViewContainer container, final ZyGraph graph) {
Preconditions.checkNotNull(parent, "IE02285: Parent argument can not be null");
Preconditions.checkNotNull(container, "IE02286: Container argument can not be null");
Preconditions.checkNotNull(graph, "IE02287: Graph Argument can not be null");
final MutableDirectedGraph<INaviViewNode, INaviEdge> mutableGraph = (MutableDirectedGraph<INaviViewNode, INaviEdge>) graph.getRawView().getGraph();
final List<INaviViewNode> nodes = mutableGraph.getNodes();
final HashMap<INaviInstruction, INaviFunction> instructionToFunctionMap = new HashMap<INaviInstruction, INaviFunction>();
for (final INaviViewNode iNaviViewNode : nodes) {
if (iNaviViewNode instanceof INaviCodeNode) {
instructionToFunctionMap.putAll(CReferenceFinder.getCodeReferenceMap((INaviCodeNode) iNaviViewNode));
}
}
for (final INaviInstruction iNaviInstruction : instructionToFunctionMap.keySet()) {
INaviCodeNode updatedNode = null;
for (final INaviViewNode iNaviViewNode2 : graph.getRawView().getGraph().getNodes()) {
final INaviCodeNode codeNode = (INaviCodeNode) iNaviViewNode2;
if (codeNode.hasInstruction(iNaviInstruction)) {
updatedNode = codeNode;
}
}
if (updatedNode != null) {
inlineFunctionSilently(parent, container, graph, updatedNode, iNaviInstruction, instructionToFunctionMap.get(iNaviInstruction));
} else {
throw new IllegalStateException("IE01174: Graph final has been rendered final to an final inconsitant state");
}
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviFunction in project binnavi by google.
the class CGraphInliner method inlineFunction.
/**
* Replaces a function node with the basic blocks of a function.
*
* @param parent Parent window that is used to display error messages.
* @param graph Graph where the inlining operation happens.
* @param node The function node that is replaced by the basic blocks of the corresponding
* function.
*/
public static void inlineFunction(final JFrame parent, final ZyGraph graph, final INaviFunctionNode node) {
Preconditions.checkNotNull(parent, "IE01743: Parent argument can not be null");
Preconditions.checkNotNull(graph, "IE01744: Graph argument can not be null");
Preconditions.checkNotNull(node, "IE01745: Node argument can not be null");
final INaviView view = graph.getRawView();
final INaviFunction function = node.getFunction();
try {
if (!function.isLoaded()) {
function.load();
}
CInliningHelper.inlineFunctionNode(view, node);
if (graph.getSettings().getLayoutSettings().getAutomaticLayouting()) {
CGraphLayouter.refreshLayout(parent, graph);
}
} catch (final CouldntLoadDataException e) {
exceptionDialog(parent, function, e);
}
}
Aggregations