Search in sources :

Example 91 with INaviModule

use of com.google.security.zynamics.binnavi.disassembly.INaviModule in project binnavi by google.

the class CBreakpointFunctionsTest method test4DisableBreakpoints.

@Test
public void test4DisableBreakpoints() {
    final INaviModule mockModule = new MockModule();
    final DebugTargetSettings target = new ModuleTargetSettings(mockModule);
    final DebuggerProvider debuggerProvider = new DebuggerProvider(target);
    final MockDebugger debugger = new MockDebugger(new ModuleTargetSettings(mockModule));
    debugger.getBreakpointManager().addBreakpoints(BreakpointType.REGULAR, Sets.newHashSet(new BreakpointAddress(mockModule, new UnrelocatedAddress(new CAddress(0)))));
    final Breakpoint breakPoint = debugger.getBreakpointManager().getBreakpoint(BreakpointType.REGULAR, new BreakpointAddress(mockModule, new UnrelocatedAddress(new CAddress(0))));
    @SuppressWarnings("unused") final CAddress address = new CAddress(0);
    final BaseNode root = new BaseNode();
    final BreakpointCondition bpCondition = new BreakpointCondition("foo", root);
    breakPoint.setCondition(bpCondition);
    breakPoint.setDescription("purzel");
    debuggerProvider.addDebugger(debugger);
    @SuppressWarnings("unused") final CBreakpointTableModel tableModel = new CBreakpointTableModel(debuggerProvider);
    final int[] rows = { 0 };
    final int[] rows2 = { 1 };
    assertFalse(CBreakpointFunctions.allDisabled(debuggerProvider, rows));
    try {
        CBreakpointRemoveFunctions.disableBreakpoints(debuggerProvider, rows2);
    } catch (final IllegalArgumentException e) {
    }
    CBreakpointRemoveFunctions.disableBreakpoints(debuggerProvider, rows);
    assertTrue(CBreakpointFunctions.allDisabled(debuggerProvider, rows));
}
Also used : Breakpoint(com.google.security.zynamics.binnavi.debug.models.breakpoints.Breakpoint) BaseNode(com.google.security.zynamics.binnavi.debug.models.breakpoints.conditions.BaseNode) CBreakpointTableModel(com.google.security.zynamics.binnavi.Gui.Debug.BreakpointTable.CBreakpointTableModel) DebugTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.DebugTargetSettings) ModuleTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) DebuggerProvider(com.google.security.zynamics.binnavi.debug.debugger.DebuggerProvider) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) BreakpointCondition(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointCondition) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) Test(org.junit.Test)

Example 92 with INaviModule

use of com.google.security.zynamics.binnavi.disassembly.INaviModule in project binnavi by google.

the class CBreakpointFunctionsTest method test3disableAll.

@Test
public void test3disableAll() {
    final INaviModule mockModule = new MockModule();
    final DebugTargetSettings target = new ModuleTargetSettings(mockModule);
    final DebuggerProvider debuggerProvider = new DebuggerProvider(target);
    final MockDebugger debugger = new MockDebugger(new ModuleTargetSettings(mockModule));
    debugger.getBreakpointManager().addBreakpoints(BreakpointType.REGULAR, Sets.newHashSet(new BreakpointAddress(mockModule, new UnrelocatedAddress(new CAddress(0)))));
    final Breakpoint breakPoint = debugger.getBreakpointManager().getBreakpoint(BreakpointType.REGULAR, new BreakpointAddress(mockModule, new UnrelocatedAddress(new CAddress(0))));
    @SuppressWarnings("unused") final CAddress address = new CAddress(0);
    final BaseNode root = new BaseNode();
    final BreakpointCondition bpCondition = new BreakpointCondition("foo", root);
    breakPoint.setCondition(bpCondition);
    breakPoint.setDescription("purzel");
    debuggerProvider.addDebugger(debugger);
    @SuppressWarnings("unused") final CBreakpointTableModel tableModel = new CBreakpointTableModel(debuggerProvider);
    final int[] rows = { 0 };
    assertFalse(CBreakpointFunctions.allDisabled(debuggerProvider, rows));
    CBreakpointRemoveFunctions.disableAll(debuggerProvider);
    assertTrue(CBreakpointFunctions.allDisabled(debuggerProvider, rows));
}
Also used : Breakpoint(com.google.security.zynamics.binnavi.debug.models.breakpoints.Breakpoint) BaseNode(com.google.security.zynamics.binnavi.debug.models.breakpoints.conditions.BaseNode) CBreakpointTableModel(com.google.security.zynamics.binnavi.Gui.Debug.BreakpointTable.CBreakpointTableModel) DebugTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.DebugTargetSettings) ModuleTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) DebuggerProvider(com.google.security.zynamics.binnavi.debug.debugger.DebuggerProvider) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) BreakpointCondition(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointCondition) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) Test(org.junit.Test)

Example 93 with INaviModule

use of com.google.security.zynamics.binnavi.disassembly.INaviModule in project binnavi by google.

the class CBreakpointFunctionsTest method test5enableFunctions.

@Test
public void test5enableFunctions() {
    final INaviModule mockModule = new MockModule();
    final DebugTargetSettings target = new ModuleTargetSettings(mockModule);
    final DebuggerProvider debuggerProvider = new DebuggerProvider(target);
    final MockDebugger debugger = new MockDebugger(new ModuleTargetSettings(mockModule));
    debugger.getBreakpointManager().addBreakpoints(BreakpointType.REGULAR, Sets.newHashSet(new BreakpointAddress(mockModule, new UnrelocatedAddress(new CAddress(0)))));
    final Breakpoint breakPoint = debugger.getBreakpointManager().getBreakpoint(BreakpointType.REGULAR, new BreakpointAddress(mockModule, new UnrelocatedAddress(new CAddress(0))));
    @SuppressWarnings("unused") final CAddress address = new CAddress(0);
    final BaseNode root = new BaseNode();
    final BreakpointCondition bpCondition = new BreakpointCondition("foo", root);
    breakPoint.setCondition(bpCondition);
    breakPoint.setDescription("purzel");
    debuggerProvider.addDebugger(debugger);
    @SuppressWarnings("unused") final CBreakpointTableModel tableModel = new CBreakpointTableModel(debuggerProvider);
    final int[] rows = { 0 };
    assertFalse(CBreakpointFunctions.allDisabled(debuggerProvider, rows));
    CBreakpointRemoveFunctions.disableAll(debuggerProvider);
    assertTrue(CBreakpointFunctions.allDisabled(debuggerProvider, rows));
    CBreakpointSetFunctions.enableAll(debuggerProvider);
    assertFalse(CBreakpointFunctions.allDisabled(debuggerProvider, rows));
    CBreakpointRemoveFunctions.disableAll(debuggerProvider);
    assertTrue(CBreakpointFunctions.allDisabled(debuggerProvider, rows));
    CBreakpointSetFunctions.enableBreakpoints(debuggerProvider, rows);
    assertFalse(CBreakpointFunctions.allDisabled(debuggerProvider, rows));
}
Also used : Breakpoint(com.google.security.zynamics.binnavi.debug.models.breakpoints.Breakpoint) BaseNode(com.google.security.zynamics.binnavi.debug.models.breakpoints.conditions.BaseNode) CBreakpointTableModel(com.google.security.zynamics.binnavi.Gui.Debug.BreakpointTable.CBreakpointTableModel) DebugTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.DebugTargetSettings) ModuleTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) DebuggerProvider(com.google.security.zynamics.binnavi.debug.debugger.DebuggerProvider) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) BreakpointCondition(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointCondition) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) Test(org.junit.Test)

Example 94 with INaviModule

use of com.google.security.zynamics.binnavi.disassembly.INaviModule in project binnavi by google.

the class PostgreSQLCommentNotificationParser method processEdgeGlobalCommentNotification.

/**
   * Parses the notifications from the database back end for global edge comments by using a regular
   * expression. If the regular expression matches the supplied notification it tries to figure out
   * if the edge which was commented is loaded in BinNavi at this point in time. If the edge is
   * loaded determine the operation which was performed by the database and then return a
   * {@link CommentNotificationContainer} with the gathered results.
   *
   * @param notification The {@link PGNotification} from the PostgreSQL database server.
   * @param provider The {@link SQLProvider} which is used to communicate with the database.
   */
static Collection<CommentNotification> processEdgeGlobalCommentNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher matcher = EDGE_GLOBAL_PATTERN.matcher(notification.getParameter());
    if (!matcher.find()) {
        return new ArrayList<>();
    }
    final String databaseOperation = matcher.group(2);
    final Integer notificationSourceModuleId = Integer.parseInt(matcher.group(3));
    final Integer notificationDestinationModuleId = Integer.parseInt(matcher.group(4));
    final IAddress notificationEdgeSourceAddress = new CAddress(new BigInteger(matcher.group(5)));
    final IAddress notificationEdgeDestinationAddress = new CAddress(new BigInteger(matcher.group(6)));
    final Integer commentId = matcher.group(8) == null ? null : Integer.parseInt(matcher.group(8));
    final INaviModule notificationSourceModule = provider.findModule(notificationSourceModuleId);
    if ((notificationSourceModule == null) || !notificationSourceModule.isLoaded()) {
        return new ArrayList<>();
    }
    final INaviModule notificationDestinationModule = provider.findModule(notificationDestinationModuleId);
    if ((notificationDestinationModule == null) || !notificationDestinationModule.isLoaded()) {
        return new ArrayList<>();
    }
    final CommentOperation operation = databaseOperation.equalsIgnoreCase("DELETE") ? CommentOperation.DELETE : CommentOperation.APPEND;
    Collection<CommentNotification> notifications = new ArrayList<>();
    final ImmutableCollection<INaviEdge> edges = EdgeCache.get(provider).getEdgeBySourceAndTarget(notificationEdgeSourceAddress, notificationSourceModuleId, notificationEdgeDestinationAddress, notificationDestinationModuleId);
    for (INaviEdge edge : edges) {
        notifications.add(new EdgeCommentNotificationContainer(edge, operation, CommentScope.GLOBAL, commentId));
    }
    return notifications;
}
Also used : CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) BigInteger(java.math.BigInteger) CommentOperation(com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation) EdgeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.EdgeCommentNotificationContainer) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) BigInteger(java.math.BigInteger)

Example 95 with INaviModule

use of com.google.security.zynamics.binnavi.disassembly.INaviModule in project binnavi by google.

the class PostgreSQLCommentNotificationParser method processFunctionNodeCommentNotification.

/**
   * Parses the notifications from the database back end for function node comments by using a
   * regular expression. If the regular expression matches the supplied {@link PGNotification}
   * notification, it is determined if the function node in question is currently loaded, and if a
   * {@link CommentNotificationContainer} with the gathered data is returned.
   *
   * @param notification The {@link PGNotification} from the PostgreSQL database server.
   * @param provider The {@link SQLProvider} which is used to communicate with the database.
   */
static CommentNotification processFunctionNodeCommentNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher matcher = FUNCTION_NODE_PATTERN.matcher(notification.getParameter());
    if (!matcher.find()) {
        return null;
    }
    final Integer moduleId = Integer.parseInt(matcher.group(3));
    final Integer nodeId = Integer.parseInt(matcher.group(4));
    final Integer commentId = matcher.group(6).equals("null") ? null : Integer.parseInt(matcher.group(6));
    final INaviModule module = provider.findModule(moduleId);
    if ((module == null) || !module.isLoaded()) {
        return null;
    }
    final INaviFunctionNode functionNode = (INaviFunctionNode) NodeCache.get(provider).getNodeById(nodeId);
    if (functionNode == null) {
        return null;
    }
    final CommentOperation operation = commentId == null ? CommentOperation.DELETE : CommentOperation.APPEND;
    return new FunctionNodeCommentNotificationContainer(functionNode, operation, commentId);
}
Also used : BigInteger(java.math.BigInteger) CommentOperation(com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) Matcher(java.util.regex.Matcher) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) FunctionNodeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionNodeCommentNotificationContainer)

Aggregations

INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)180 Test (org.junit.Test)105 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)69 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)39 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)39 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)29 UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)28 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)28 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)24 BreakpointAddress (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)22 ArrayList (java.util.ArrayList)19 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)18 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)13 BigInteger (java.math.BigInteger)13 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)12 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)11 CTagManager (com.google.security.zynamics.binnavi.Tagging.CTagManager)11 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)9 CAddressSpace (com.google.security.zynamics.binnavi.disassembly.AddressSpaces.CAddressSpace)9 COperandTree (com.google.security.zynamics.binnavi.disassembly.COperandTree)9