Search in sources :

Example 1 with CUserManager

use of com.google.security.zynamics.binnavi.Gui.Users.CUserManager in project binnavi by google.

the class CDatabase method loadUserManager.

/**
   * Loads the user manager and initializes it.
   *
   * @return The loaded user manager.
   *
   * @throws CouldntLoadDataException if the manager could not be initialized.
   */
private CUserManager loadUserManager() throws CouldntLoadDataException {
    final CUserManager userManager = CUserManager.get(provider);
    final String userName = getConfiguration().getIdentity();
    if (userManager.containsUserName(userName)) {
        userManager.setCurrentActiveUser(userManager.getUserByUserName(userName));
    } else {
        try {
            userManager.setCurrentActiveUser(userManager.addUser(userName));
        } catch (final CouldntSaveDataException e) {
            CUtilityFunctions.logException(e);
            throw new CouldntLoadDataException(e);
        }
    }
    return userManager;
}
Also used : CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CUserManager(com.google.security.zynamics.binnavi.Gui.Users.CUserManager)

Example 2 with CUserManager

use of com.google.security.zynamics.binnavi.Gui.Users.CUserManager in project binnavi by google.

the class CViewInserterTest method test.

@Test
public void test() throws CouldntLoadDataException, CPartialLoadException, LoadCancelledException, FileReadException, CouldntSaveDataException {
    ConfigManager.instance().read();
    final INaviModule mockModule = new MockModule();
    final MockSqlProvider mockProvider = new MockSqlProvider();
    final CUserManager userManager = CUserManager.get(mockProvider);
    final IUser user = userManager.addUser(" VIEW INSERTER USER ");
    userManager.setCurrentActiveUser(user);
    final CModuleViewGenerator generator = new CModuleViewGenerator(mockProvider, mockModule);
    final CView view = generator.generate(1, "", "", ViewType.NonNative, GraphType.MIXED_GRAPH, new Date(), new Date(), 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
    view.load();
    final MockFunction mockFunction = new MockFunction(mockProvider);
    final CFunctionNode fnode1 = view.getContent().createFunctionNode(mockFunction);
    final CFunctionNode fnode2 = view.getContent().createFunctionNode(mockFunction);
    @SuppressWarnings("unused") final CNaviViewEdge edge1 = view.getContent().createEdge(fnode1, fnode2, EdgeType.JUMP_UNCONDITIONAL);
    final MockInstruction instruction1 = new MockInstruction();
    final CCodeNode cnode1 = view.getContent().createCodeNode(mockFunction, Lists.newArrayList(instruction1));
    final CCodeNode cnode2 = view.getContent().createCodeNode(mockFunction, Lists.newArrayList(instruction1));
    @SuppressWarnings("unused") final CNaviViewEdge edge2 = view.getContent().createEdge(cnode1, cnode2, EdgeType.JUMP_UNCONDITIONAL);
    final ArrayList<IComment> comments = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Foo"));
    final CTextNode tnode1 = view.getContent().createTextNode(comments);
    @SuppressWarnings("unused") final CNaviViewEdge edge3 = view.getContent().createEdge(cnode1, tnode1, EdgeType.JUMP_UNCONDITIONAL);
    final CGroupNode gnode1 = view.getContent().createGroupNode(Lists.newArrayList((INaviViewNode) fnode1, (INaviViewNode) fnode2));
    gnode1.appendComment("TEST GROUP NODE COMMENT 1");
    final CView view2 = generator.generate(2, "", "", ViewType.NonNative, GraphType.MIXED_GRAPH, new Date(), new Date(), 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
    view2.load();
    CViewInserter.insertView(view, view2);
    final List<INaviViewNode> nodes = view2.getGraph().getNodes();
    assertEquals(view2.getNodeCount(), 6);
    assertEquals(mockFunction, ((INaviFunctionNode) nodes.get(0)).getFunction());
    assertEquals(nodes.get(5), ((INaviFunctionNode) nodes.get(0)).getParentGroup());
}
Also used : MockFunction(com.google.security.zynamics.binnavi.disassembly.MockFunction) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) CModuleViewGenerator(com.google.security.zynamics.binnavi.Database.CModuleViewGenerator) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CUserManager(com.google.security.zynamics.binnavi.Gui.Users.CUserManager) Date(java.util.Date) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) Test(org.junit.Test)

Example 3 with CUserManager

use of com.google.security.zynamics.binnavi.Gui.Users.CUserManager in project binnavi by google.

the class CCodeNodeTest method testMiscFunctions.

@Test
public void testMiscFunctions() throws MaybeNullException, CouldntSaveDataException, CouldntLoadDataException {
    final MockSqlProvider provider = new MockSqlProvider();
    final CUserManager userManager = CUserManager.get(provider);
    final IUser currentUser = userManager.addUser("TEST USER 1");
    userManager.setCurrentActiveUser(currentUser);
    final CModule internalModule = new CModule(1, "", "", new Date(), new Date(), CommonTestObjects.MD5, CommonTestObjects.SHA1, 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, provider);
    final CFunction parentFunction = 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 CCodeNode node = new CCodeNode(1, 0, 0, 0, 0, Color.BLACK, Color.BLACK, false, true, Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "foobar")), parentFunction, new LinkedHashSet<CTag>(), provider);
    final MockInstruction i1 = new MockInstruction(new CAddress(0x123), "nop", new ArrayList<COperandTree>(), null);
    final MockInstruction i2 = new MockInstruction(new CAddress(0x124), "nop", new ArrayList<COperandTree>(), null);
    final MockInstruction i3 = new MockInstruction(new CAddress(0x125), "nop", new ArrayList<COperandTree>(), null);
    final MockInstruction i4 = new MockInstruction(new CAddress(0x126), "nop", new ArrayList<COperandTree>(), m_globalComment);
    final MockInstruction i5 = new MockInstruction(new CAddress(0x127), "nop", new ArrayList<COperandTree>(), null);
    node.addInstruction(i1, Lists.<IComment>newArrayList(new CComment(null, currentUser, null, "Foo\nBar")));
    node.addInstruction(i2, Lists.<IComment>newArrayList(new CComment(null, currentUser, null, "\n")));
    node.addInstruction(i3, null);
    node.addInstruction(i4, null);
    final INaviCodeNodeListener listener = new CNaviCodeNodeListenerAdapter();
    node.addListener(listener);
    node.addInstruction(i5, null);
    assertNotNull(node.cloneNode());
    assertFalse(CCodeNodeHelpers.containsAddress(node, new CAddress(0xFFFFFFFEL)));
    assertEquals(null, node.getComments().getGlobalCodeNodeComment());
    assertEquals(new CAddress(0x123L), node.getAddress());
    assertEquals(0, CCodeNodeHelpers.getInstruction(node, new CAddress(0x123L)));
    assertEquals(-1, CCodeNodeHelpers.getInstruction(node, new CAddress(0x129L)));
    assertEquals(i1, Iterables.getFirst(node.getInstructions(), null));
    assertEquals(5, Iterables.size(node.getInstructions()));
    assertEquals(5, node.instructionCount());
    assertNotNull(node.getParentFunction());
    node.removeInstruction(i5);
    assertEquals(4, node.instructionCount());
    try {
        node.removeInstruction(null);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        node.removeInstruction(i5);
        fail();
    } catch (final IllegalArgumentException e) {
    }
    final List<IComment> comments = node.getComments().appendGlobalCodeNodeComment("barfoos");
    assertEquals(comments, node.getComments().getGlobalCodeNodeComment());
    try {
        node.getComments().appendGlobalCodeNodeComment(null);
        fail();
    } catch (final Exception e) {
    }
    node.setInstructionColor(i4, 0, Color.YELLOW);
    try {
        node.setInstructionColor(null, 0, null);
        fail();
    } catch (final Exception e) {
    }
    try {
        node.setInstructionColor(i5, 0, null);
        fail();
    } catch (final Exception e) {
    }
    node.setBorderColor(Color.GRAY);
    assertEquals(Color.GRAY, node.getBorderColor());
    final List<IComment> comments2 = node.getComments().appendLocalCodeNodeComment("barfoos2");
    assertEquals(comments2, node.getComments().getLocalCodeNodeComment());
    final List<IComment> appendedComments = node.getComments().appendLocalInstructionComment(i4, "foo");
    assertEquals(appendedComments, node.getComments().getLocalInstructionComment(i4));
    try {
        node.getComments().appendLocalInstructionComment(i5, " INSTRUCTION i5 COMMENT ");
        fail();
    } catch (final IllegalArgumentException e) {
    }
    node.getComments().appendLocalCodeNodeComment("foo");
    node.toString();
    node.removeListener(listener);
    node.close();
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CUserManager(com.google.security.zynamics.binnavi.Gui.Users.CUserManager) Date(java.util.Date) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Test(org.junit.Test)

Example 4 with CUserManager

use of com.google.security.zynamics.binnavi.Gui.Users.CUserManager in project binnavi by google.

the class CUserManagerTest method deleteUserCorrectArgumentTest.

@Test
public void deleteUserCorrectArgumentTest() throws CouldntSaveDataException, CouldntDeleteException {
    final CUserManager manager = CUserManager.get(m_sql);
    final IUser user = manager.addUser("ONE");
    manager.deleteUser(user);
}
Also used : IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) CUserManager(com.google.security.zynamics.binnavi.Gui.Users.CUserManager) Test(org.junit.Test)

Example 5 with CUserManager

use of com.google.security.zynamics.binnavi.Gui.Users.CUserManager in project binnavi by google.

the class CUserManagerTest method editUserWrongArgumentsTest3.

@Test(expected = IllegalStateException.class)
public void editUserWrongArgumentsTest3() throws CouldntSaveDataException {
    final CUserManager manager = CUserManager.get(m_sql);
    final IUser user = new CUser(2123, "TEST USER 12412");
    manager.editUserName(user, "FOOBAR");
}
Also used : CUser(com.google.security.zynamics.binnavi.Gui.Users.CUser) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) CUserManager(com.google.security.zynamics.binnavi.Gui.Users.CUserManager) Test(org.junit.Test)

Aggregations

CUserManager (com.google.security.zynamics.binnavi.Gui.Users.CUserManager)22 Test (org.junit.Test)20 IUser (com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser)11 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)4 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)3 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)3 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)3 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)2 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)2 CUser (com.google.security.zynamics.binnavi.Gui.Users.CUser)2 CGroupNode (com.google.security.zynamics.binnavi.disassembly.CGroupNode)2 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)2 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)2 Date (java.util.Date)2 CModuleViewGenerator (com.google.security.zynamics.binnavi.Database.CModuleViewGenerator)1 SQLProvider (com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider)1 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)1 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)1 MockTagManager (com.google.security.zynamics.binnavi.Tagging.MockTagManager)1 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)1