use of com.google.security.zynamics.binnavi.Exceptions.MaybeNullException in project binnavi by google.
the class BreakpointConditionParser method parse.
/**
* Parses a breakpoint condition string.
*
* @param conditionString The condition string to parse.
*
* @return The parsed breakpoint condition tree.
*
* @throws RecognitionException Thrown if the condition string could not be parsed.
* @throws MaybeNullException Thrown if an empty condition string is passed to the function.
*/
public static ConditionNode parse(final String conditionString) throws RecognitionException, MaybeNullException {
if (conditionString.trim().isEmpty()) {
throw new MaybeNullException();
}
final CharStream charStream = new ANTLRStringStream(conditionString);
final ConditionLexer lexer = new ConditionLexer(charStream);
final CommonTokenStream tokens = new CommonTokenStream();
tokens.setTokenSource(lexer);
final ConditionParser parser = new ConditionParser(tokens);
parser.setTreeAdaptor(adaptor);
try {
final ConditionParser.prog_return parserResult = parser.prog();
final CommonTree ast = (CommonTree) parserResult.getTree();
if (parser.input.index() < parser.input.size()) {
throw new RecognitionException();
}
return convert(ast);
} catch (final IllegalArgumentException e) {
throw new RecognitionException();
}
}
use of com.google.security.zynamics.binnavi.Exceptions.MaybeNullException in project binnavi by google.
the class SuspendThreadSynchronizer method handleError.
@Override
protected void handleError(final SuspendThreadReply reply) {
try {
final TargetProcessThread thread = getDebugger().getProcessManager().getThread(reply.getThreadId());
// TODO: In case we can not suspend the thread, we assume that it is really running.
// This is not correct, however. What really needs to happen is that the debug client
// sends the real state of the thread in the error message.
thread.setState(ThreadState.RUNNING);
} catch (final MaybeNullException exception) {
// Note: This is not necessary an error situation. Imagine the following
//
// 1. Send SuspendThread to the debug client
// 2. While the command is sent, the thread is closed
// 3. Debug client can not suspend the thread
// 4. We land here
NaviLogger.severe("Error: Tried to suspend unknown thread '%d'", reply.getThreadId());
}
}
use of com.google.security.zynamics.binnavi.Exceptions.MaybeNullException 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.Exceptions.MaybeNullException in project binnavi by google.
the class CDebuggerSynchronizerTest method testInfoString_Wellformed.
@Test
public void testInfoString_Wellformed() throws DebugExceptionWrapper, MaybeNullException {
// Set breakpoints while the debugger is not connected
breakpointManager.addBreakpoints(BreakpointType.REGULAR, CommonTestObjects.BP_ADDRESS_123_SET);
breakpointManager.addBreakpoints(BreakpointType.REGULAR, CommonTestObjects.BP_ADDRESS_456_SET);
breakpointManager.setBreakpointStatus(CommonTestObjects.BP_ADDRESS_456_SET, BreakpointType.REGULAR, BreakpointStatus.BREAKPOINT_DISABLED);
assertEquals(BreakpointStatus.BREAKPOINT_INACTIVE, breakpointManager.getBreakpointStatus(BreakpointType.REGULAR, 0));
mockDebugger.connect();
debuggerSynchronizer.receivedEvent(DebuggerMessageBuilder.buildProcessStartReply(CommonTestObjects.MEMORY_MODULE));
assertEquals(0, listener.exception);
assertNotNull(mockDebugger.getProcessManager().getThread(CommonTestObjects.THREAD_ID));
assertEquals(ThreadState.RUNNING, mockDebugger.getProcessManager().getThread(CommonTestObjects.THREAD_ID).getState());
debuggerSynchronizer.receivedEvent(new ThreadClosedReply(0, 0, CommonTestObjects.THREAD_ID));
try {
mockDebugger.getProcessManager().getThread(CommonTestObjects.THREAD_ID);
fail();
} catch (final MaybeNullException exception) {
CUtilityFunctions.logException(exception);
}
// On receiving an info string we request the memory map and the thread created reply triggers
// read registers
assertEquals("CONNECT;READREGS;SET_BREAKPOINTS/" + String.format("%08d", CommonTestObjects.THREAD_ID) + "/REGULAR;RESUME;", mockDebugger.requests);
// Enabled breakpoints are activated
assertEquals(BreakpointStatus.BREAKPOINT_ENABLED, breakpointManager.getBreakpointStatus(BreakpointType.REGULAR, 0));
assertEquals(BreakpointStatus.BREAKPOINT_DISABLED, breakpointManager.getBreakpointStatus(BreakpointType.REGULAR, 1));
}
use of com.google.security.zynamics.binnavi.Exceptions.MaybeNullException in project binnavi by google.
the class NodeCache method addNodes.
public void addNodes(final List<INaviViewNode> nodes) {
nodeByIdCache.putAll(Maps.uniqueIndex(nodes, new Function<INaviViewNode, Integer>() {
@Override
public Integer apply(final INaviViewNode node) {
return node.getId();
}
}));
for (final INaviViewNode node : nodes) {
if (node instanceof INaviCodeNode) {
final IAddress nodeAddress = ((INaviCodeNode) node).getAddress();
Integer moduleId = null;
try {
moduleId = ((INaviCodeNode) node).getParentFunction().getModule().getConfiguration().getId();
} catch (final MaybeNullException e) {
continue;
}
if (moduleId != null) {
UpdateAddressModuleIdCache(nodeAddress, moduleId, node);
}
}
}
}
Aggregations