use of com.google.security.zynamics.binnavi.disassembly.INaviCodeNode in project binnavi by google.
the class ViewGraphHelpersTest method setUp.
@Before
public void setUp() throws CouldntLoadDataException, LoadCancelledException, com.google.security.zynamics.binnavi.API.disassembly.CouldntLoadDataException, PartialLoadException {
final MockSqlProvider provider = new MockSqlProvider();
final TagManager tagManager = new TagManager(new MockTagManager(TagType.NODE_TAG));
final TagManager viewTagManager = new TagManager(new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(1, "", "", TagType.VIEW_TAG, provider))), TagType.VIEW_TAG, provider));
final Database database = new Database(new MockDatabase());
final CModule internalModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, provider);
internalModule.load();
final Module module = new Module(database, internalModule, tagManager, viewTagManager);
final CModuleViewGenerator generator = new CModuleViewGenerator(provider, internalModule);
final INaviView internalView = generator.generate(1, "My View", "My View Description", com.google.security.zynamics.zylib.disassembly.ViewType.NonNative, GraphType.MIXED_GRAPH, new Date(), new Date(), 1, 2, new HashSet<CTag>(), new HashSet<CTag>(), false);
m_view = new View(module, internalView, tagManager, viewTagManager);
m_view.load();
final List<INaviInstruction> instructions = new ArrayList<INaviInstruction>();
instructions.add(new CInstruction(false, internalModule, new CAddress(0x123), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", provider));
instructions.add(new CInstruction(false, internalModule, new CAddress(0x124), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", provider));
instructions.add(new CInstruction(false, internalModule, new CAddress(0x125), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", provider));
final INaviCodeNode codeNode = internalView.getContent().createCodeNode(null, instructions);
final List<INaviViewNode> nodes1 = new ArrayList<INaviViewNode>();
nodes1.add(codeNode);
final List<INaviEdge> edges1 = new ArrayList<INaviEdge>();
final CFunction internalFunction = new CFunction(internalModule, new MockView(nodes1, edges1, provider), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, provider);
internalFunction.load();
final Function function = new Function(module, internalFunction);
final CFunctionNode functionNode = new CFunctionNode(0, internalFunction, 0, 0, 0, 0, Color.RED, false, false, null, new HashSet<CTag>(), provider);
m_codeNode = new CodeNode(m_view, codeNode, tagManager);
m_functionNode = new FunctionNode(m_view, functionNode, function, tagManager);
m_textNode = new TextNode(m_view, new MockTextNode(), tagManager);
final List<ViewNode> nodes = Lists.newArrayList(m_codeNode, m_functionNode, m_textNode);
final List<ViewEdge> edges = Lists.newArrayList(new ViewEdge(new MockEdge(1, provider), nodes.get(0), nodes.get(0)));
m_graph = new ViewGraph(nodes, edges);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviCodeNode in project binnavi by google.
the class CodeNodeTest method setUp.
@Before
public void setUp() {
final Database database = new Database(new MockDatabase());
final MockModule mockModule = new MockModule();
final TagManager nodeTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.NODE_TAG));
final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
final Module module = new Module(database, mockModule, nodeTagManager, viewTagManager);
final MockView mockView = new MockView();
final View view = new View(module, mockView, nodeTagManager, viewTagManager);
final MockSqlProvider provider = new MockSqlProvider();
final CModule internalModule = new CModule(123, "Name", "Comment", new Date(), new Date(), "12345678123456781234567812345678", "1234567812345678123456781234567812345678", 55, 66, new CAddress(0x555), new CAddress(0x666), new DebuggerTemplate(1, "Mock Debugger", "localhaus", 88, provider), null, Integer.MAX_VALUE, false, provider);
final CFunction internalFunction = new CFunction(internalModule, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, provider);
final CComment m_globalComment = new CComment(null, CommonTestObjects.TEST_USER_1, null, "Global Comment");
final INaviCodeNode codeNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, false, Lists.<IComment>newArrayList(m_globalComment), internalFunction, new HashSet<CTag>(), new MockSqlProvider());
codeNode.addInstruction(new CInstruction(true, internalModule, new CAddress(0x123), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", provider), null);
m_node = new CodeNode(view, codeNode, nodeTagManager);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviCodeNode in project binnavi by google.
the class CCodeNodeParser method addInstruction.
/**
* Adds an instruction to a code node.
*
* @param node The code node where the instruction is added.
* @param line The raw instruction data to add.
*/
private void addInstruction(final CCodeNode node, final InstructionLine line) {
final CInstruction instruction = InstructionConverter.createInstruction(line, sqlProvider);
InstructionCache.get(sqlProvider).addInstruction(instruction);
localCommentIdToInstruction.put(line.getLocalInstructionCommentId(), new Pair<INaviInstruction, INaviCodeNode>(instruction, node));
globalCommentIdToInstruction.put(line.getGlobalInstructionComment(), instruction);
localCommentIdToCodeNode.put(line.getLocalNodeCommentId(), node);
globalCommentIdToCodeNode.put(line.getGlobalNodeCommentId(), node);
node.addInstruction(instruction, null);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviCodeNode in project binnavi by google.
the class CCodeNodeParser method parse.
/**
* Takes the information from the components passed into the constructor and creates a list of
* nodes from that information.
*
* @return The list of nodes created by the parser.
*
* @throws ParserException Thrown if the instruction data could not be loaded.
* @throws CPartialLoadException Thrown if not all necessary modules are loaded.
*/
public List<CCodeNode> parse() throws ParserException, CPartialLoadException {
// it to point to the proper data.
if (!dataProvider.next()) {
return new ArrayList<CCodeNode>();
}
// Generate the nodes from the raw data.
while (true) {
if (dataProvider.isAfterLast()) {
if (currentNode != null) {
nodes.add(currentNode);
}
break;
}
nodes.add(extractNode(dataProvider));
}
final HashSet<Integer> allComments = Sets.newHashSet();
allComments.addAll(localCommentIdToCodeNode.keySet());
allComments.addAll(globalCommentIdToCodeNode.keySet());
allComments.addAll(globalCommentIdToInstruction.keySet());
allComments.addAll(localCommentIdToInstruction.keySet());
try {
final HashMap<Integer, ArrayList<IComment>> commentIdToComments = sqlProvider.loadMultipleCommentsById(allComments);
for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdToComments.entrySet()) {
if (localCommentIdToCodeNode.containsKey(commentIdToComment.getKey())) {
localCommentIdToCodeNode.get(commentIdToComment.getKey()).getComments().initializeLocalCodeNodeComment(commentIdToComment.getValue());
}
if (globalCommentIdToCodeNode.containsKey(commentIdToComment.getKey())) {
globalCommentIdToCodeNode.get(commentIdToComment.getKey()).getComments().initializeGlobalCodeNodeComment(commentIdToComment.getValue());
}
if (localCommentIdToInstruction.containsKey(commentIdToComment.getKey())) {
final Pair<INaviInstruction, INaviCodeNode> instructionToCodeNode = localCommentIdToInstruction.get(commentIdToComment.getKey());
instructionToCodeNode.second().getComments().initializeLocalInstructionComment(instructionToCodeNode.first(), commentIdToComment.getValue());
}
if (globalCommentIdToInstruction.containsKey(commentIdToComment.getKey())) {
globalCommentIdToInstruction.get(commentIdToComment.getKey()).initializeGlobalComment(commentIdToComment.getValue());
}
}
} catch (final CouldntLoadDataException exception) {
throw new CPartialLoadException("Error: Comments could not be loaded.", null);
}
return nodes;
}
use of com.google.security.zynamics.binnavi.disassembly.INaviCodeNode in project binnavi by google.
the class PostgreSQLEdgeFunctions method deleteGlobalEdgeComment.
/**
* This function deletes a global edge comment from the database.
*
* @param provider The provider to access the database.
* @param edge The edge to which the comment is associated.
* @param commentId The comment id of the comment to be deleted.
* @param userId The user id of the currently active user.
*
* @throws CouldntDeleteException if the comment could not be deleted from the database.
*/
public static void deleteGlobalEdgeComment(final AbstractSQLProvider provider, final INaviEdge edge, final Integer commentId, final Integer userId) throws CouldntDeleteException {
Preconditions.checkNotNull(provider, "IE00505: provider argument can not be null");
Preconditions.checkNotNull(edge, "IE00506: codeNode argument can not be null");
Preconditions.checkNotNull(commentId, "IE00507: comment argument can not be null");
Preconditions.checkNotNull(userId, "IE00508: userId argument can not be null");
final String function = " { ? = call delete_global_edge_comment(?, ?, ?, ?, ?, ?) } ";
try {
final CallableStatement deleteCommentFunction = provider.getConnection().getConnection().prepareCall(function);
try {
deleteCommentFunction.registerOutParameter(1, Types.INTEGER);
deleteCommentFunction.setInt(2, getModuleId(edge.getSource()));
deleteCommentFunction.setInt(3, getModuleId(edge.getTarget()));
deleteCommentFunction.setObject(4, ((INaviCodeNode) edge.getSource()).getAddress().toBigInteger(), Types.BIGINT);
deleteCommentFunction.setObject(5, ((INaviCodeNode) edge.getTarget()).getAddress().toBigInteger(), Types.BIGINT);
deleteCommentFunction.setInt(6, commentId);
deleteCommentFunction.setInt(7, userId);
deleteCommentFunction.execute();
deleteCommentFunction.getInt(1);
if (deleteCommentFunction.wasNull()) {
throw new IllegalArgumentException("Error: the comment id returned from the database was null");
}
} finally {
deleteCommentFunction.close();
}
} catch (SQLException | MaybeNullException exception) {
throw new CouldntDeleteException(exception);
}
}
Aggregations