use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.
the class PostgreSQLProviderTest method testCviewFunctionsUntagView3.
@Test
public void testCviewFunctionsUntagView3() throws CouldntLoadDataException, LoadCancelledException, CPartialLoadException, CouldntSaveDataException {
final INaviModule module = getProvider().loadModules().get(0);
module.load();
final CView view = (CView) module.getContent().getViewContainer().getViews().get(224);
view.load();
final Set<CTag> viewTags = view.getConfiguration().getViewTags();
if (viewTags.isEmpty()) {
final CTagManager tagManager = getProvider().loadTagManager(TagType.VIEW_TAG);
final CTag tag = tagManager.getRootTag().getChildren().get(0).getObject();
getProvider().tagView(view, tag);
} else {
getProvider().removeTag(view, viewTags.iterator().next());
}
}
use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.
the class PostgreSQLProviderTest method testSave.
@Test
public void testSave() throws CouldntSaveDataException, CouldntLoadDataException, CouldntDeleteException, CPartialLoadException, InternalTranslationException, LoadCancelledException, MaybeNullException {
final CTagManager tagManager = getProvider().loadTagManager(TagType.NODE_TAG);
tagManager.addTag(tagManager.getRootTag(), "Node Tag I");
tagManager.addTag(tagManager.getRootTag(), "Node Tag II");
final ITreeNode<CTag> tag1 = tagManager.getRootTag().getChildren().get(0);
final ITreeNode<CTag> tag2 = tagManager.getRootTag().getChildren().get(1);
final INaviModule module = getProvider().loadModules().get(0);
module.load();
final CView view = module.getContent().getViewContainer().createView("Save View", "Save View Description");
final INaviFunction function = module.getContent().getFunctionContainer().getFunction("sub_1002B87");
function.load();
final List<COperandTree> operands = new ArrayList<COperandTree>();
final COperandTreeNode root1 = module.createOperandExpression("dword", ExpressionType.SIZE_PREFIX);
final COperandTreeNode child1 = module.createOperandExpression("eax", ExpressionType.REGISTER);
COperandTreeNode.link(root1, child1);
final COperandTreeNode root2 = module.createOperandExpression("dword", ExpressionType.SIZE_PREFIX);
final COperandTreeNode child2 = module.createOperandExpression("16", ExpressionType.IMMEDIATE_INTEGER);
COperandTreeNode.link(root2, child2);
final COperandTree operand1 = module.createOperand(root1);
final COperandTree operand2 = module.createOperand(root2);
operands.add(operand1);
operands.add(operand2);
final Iterable<INaviInstruction> instructions = function.getBasicBlocks().get(0).getInstructions();
final Iterable<INaviInstruction> instructions2 = function.getBasicBlocks().get(1).getInstructions();
final CCodeNode codeNode = view.getContent().createCodeNode(function, Lists.newArrayList(instructions));
codeNode.tagNode(tag1.getObject());
codeNode.getComments().appendLocalCodeNodeComment("XXX");
codeNode.getComments().appendLocalInstructionComment(Iterables.getLast(codeNode.getInstructions()), "YYY");
Iterables.getLast(codeNode.getInstructions()).appendGlobalComment(" GLOBAL INSTRUCTION COMMENT ");
@SuppressWarnings("unused") final CCodeNode codeNode2 = view.getContent().createCodeNode(null, Lists.newArrayList(instructions2));
final CFunctionNode functionNode = view.getContent().createFunctionNode(function);
functionNode.tagNode(tag2.getObject());
functionNode.appendLocalFunctionComment("ZZZ");
@SuppressWarnings("unused") final CNaviViewEdge edge = view.getContent().createEdge(codeNode, functionNode, EdgeType.JUMP_UNCONDITIONAL);
view.save();
view.close();
view.load();
assertEquals(3, view.getGraph().getNodes().size());
assertEquals(1, view.getGraph().getEdges().size());
assertTrue(view.getGraph().getNodes().get(0).isTagged(tag1.getObject()));
assertTrue(view.getGraph().getNodes().get(2).isTagged(tag2.getObject()));
final CCodeNode loadedCodeNode = (CCodeNode) view.getGraph().getNodes().get(0);
final CCodeNode loadedCodeNode2 = (CCodeNode) view.getGraph().getNodes().get(1);
assertEquals("XXX", loadedCodeNode.getComments().getLocalCodeNodeComment().get(0).getComment());
final INaviInstruction customInstruction = Iterables.getLast(loadedCodeNode.getInstructions());
assertEquals(" GLOBAL INSTRUCTION COMMENT ", customInstruction.getGlobalComment().get(0).getComment());
assertEquals("YYY", loadedCodeNode.getComments().getLocalInstructionComment(customInstruction).get(0).getComment());
final ReilTranslator<INaviInstruction> translator = new ReilTranslator<INaviInstruction>();
translator.translate(new StandardEnvironment(), loadedCodeNode);
translator.translate(new StandardEnvironment(), loadedCodeNode2);
final CFunctionNode loadedFunctionNode = (CFunctionNode) view.getGraph().getNodes().get(2);
assertEquals("ZZZ", loadedFunctionNode.getLocalFunctionComment().get(0).getComment());
tagManager.deleteTag(tag1);
tagManager.deleteTag(tag2);
}
use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.
the class PostgreSQLProviderTest method testInsertTag.
@Test
public void testInsertTag() throws CouldntLoadDataException, CouldntSaveDataException {
final CTagManager tagManager = getProvider().loadTagManager(TagType.VIEW_TAG);
final CTag newTag = getProvider().insertTag(tagManager.getRootTag(), "Tag Name", "Tag Description", TagType.VIEW_TAG);
assertEquals("Tag Name", newTag.getName());
assertEquals("Tag Description", newTag.getDescription());
assertEquals(TagType.VIEW_TAG, newTag.getType());
getProvider().createTag(newTag, "Tag Name", "Tag Description", TagType.VIEW_TAG);
// Create more tags for the delete test later
getProvider().createTag(tagManager.getRootTag().getObject(), "Tag Name", "Tag Description", TagType.VIEW_TAG);
final CTag tag4 = getProvider().createTag(tagManager.getRootTag().getObject(), "Tag Name", "Tag Description", TagType.VIEW_TAG);
getProvider().createTag(tag4, "Tag Name", "Tag Description", TagType.VIEW_TAG);
}
use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.
the class PostgreSQLProviderTest method testSetDescription1.
@Test
public void testSetDescription1() throws CouldntSaveDataException, CouldntLoadDataException, LoadCancelledException {
final INaviProject project = getProvider().loadProjects().get(0);
final CAddressSpace addressSpace = getProvider().createAddressSpace(project, "SOME_OTHER_ADDRESS_SPACE");
final INaviModule module = getProvider().loadModules().get(0);
module.load();
final CFunction function = (CFunction) module.getContent().getFunctionContainer().getFunctions().get(0);
final CView view = (CView) module.getContent().getViewContainer().getViews().get(0);
final CTagManager tagManager = getProvider().loadTagManager(TagType.VIEW_TAG);
final ITreeNode<CTag> tag = tagManager.getRootTag().getChildren().get(0);
getProvider().setDescription(addressSpace, "New Description");
getProvider().setDescription(function, "New Description");
getProvider().setDescription(module, "New Description");
getProvider().setDescription(project, "New Description");
getProvider().setDescription(tag.getObject(), "New Description");
getProvider().setDescription(module.getContent().getTraceContainer().getTraces().get(0), "New Description");
getProvider().setDescription(view, "New Description");
}
use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.
the class PostgreSQLProviderTestSetup method testCreateTag.
@Test
public void testCreateTag() throws CouldntSaveDataException, CouldntLoadDataException {
final CTagManager tagManager = getProvider().loadTagManager(TagType.VIEW_TAG);
final CTag newTag = getProvider().createTag(tagManager.getRootTag().getObject(), "Tag Name", "Tag Description", TagType.VIEW_TAG);
assertEquals("Tag Name", newTag.getName());
assertEquals("Tag Description", newTag.getDescription());
assertEquals(TagType.VIEW_TAG, newTag.getType());
getProvider().createTag(newTag, "Tag Name", "Tag Description", TagType.VIEW_TAG);
// Create more tags for the delete test later
getProvider().createTag(tagManager.getRootTag().getObject(), "Tag Name", "Tag Description", TagType.VIEW_TAG);
final CTag tag4 = getProvider().createTag(tagManager.getRootTag().getObject(), "Tag Name", "Tag Description", TagType.VIEW_TAG);
getProvider().createTag(tag4, "Tag Name", "Tag Description", TagType.VIEW_TAG);
}
Aggregations