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;
}
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());
}
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();
}
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);
}
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");
}
Aggregations