Search in sources :

Example 56 with INaviInstruction

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

the class FunctionTest method testReil.

@Test
public void testReil() throws CouldntLoadDataException, InternalTranslationException {
    final MockSqlProvider provider = new MockSqlProvider();
    final CModule internalModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, provider);
    @SuppressWarnings("unused") 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 List<INaviInstruction> instructions1 = new ArrayList<INaviInstruction>();
    instructions1.add(new MockInstruction(1234));
    final List<INaviInstruction> instructions2 = new ArrayList<INaviInstruction>();
    instructions2.add(new MockInstruction(1235));
    new CBlockNode(new CBasicBlock(1, "", instructions1));
    new CBlockNode(new CBasicBlock(1, "", instructions2));
    final Function function = new Function(ModuleFactory.get(), m_internalFunction);
    function.load();
    assertNotNull(function.getReilCode());
}
Also used : CBlockNode(com.google.security.zynamics.binnavi.disassembly.CBlockNode) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) ArrayList(java.util.ArrayList) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CBasicBlock(com.google.security.zynamics.binnavi.disassembly.CBasicBlock) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) Test(org.junit.Test)

Example 57 with INaviInstruction

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

the class FunctionTest method testLoad.

@Test
public void testLoad() throws CouldntLoadDataException {
    final MockFunctionListener listener = new MockFunctionListener();
    final MockSqlProvider provider = new MockSqlProvider();
    final CModule internalModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, provider);
    @SuppressWarnings("unused") 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 List<INaviInstruction> instructions1 = new ArrayList<INaviInstruction>();
    instructions1.add(new MockInstruction(1234));
    final List<INaviInstruction> instructions2 = new ArrayList<INaviInstruction>();
    instructions2.add(new MockInstruction(1235));
    new CBlockNode(new CBasicBlock(1, "", instructions1));
    new CBlockNode(new CBasicBlock(1, "", instructions2));
    final Function function = new Function(ModuleFactory.get(), m_internalFunction);
    function.addListener(listener);
    function.load();
    assertEquals("loadedFunction;", listener.events);
    assertEquals(4, function.getEdgeCount());
    assertEquals(5, function.getBlockCount());
    assertEquals(1, function.getGraph().getNodes().get(0).getChildren().size());
    function.close();
    function.removeListener(listener);
    assertEquals("loadedFunction;closedFunction;", listener.events);
    assertFalse(function.isLoaded());
}
Also used : CBlockNode(com.google.security.zynamics.binnavi.disassembly.CBlockNode) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) ArrayList(java.util.ArrayList) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CBasicBlock(com.google.security.zynamics.binnavi.disassembly.CBasicBlock) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) Test(org.junit.Test)

Example 58 with INaviInstruction

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

the class PostgreSQLTypeInstancesNotificationParser method informExpressionTypeInstanceNotification.

/**
 * This function informs the {@link TypeInstanceContainer} about changes related to expression
 * type instances also known as cross references for type instances.
 *
 * @param container The {@link TypeInstancesNotificationContainer} holding the parsed information.
 * @param provider The {@link SQLProvider} used to access the database.
 * @throws CouldntLoadDataException
 */
private void informExpressionTypeInstanceNotification(final TypeInstancesNotificationContainer container, final SQLProvider provider) throws CouldntLoadDataException {
    final TypeInstanceContainer typeContainer = provider.findModule(container.getModuleId()).getContent().getTypeInstanceContainer();
    if (container.getDatabaseOperation().equals("INSERT")) {
        final TypeInstanceReference reference = typeContainer.loadInstanceReference(container.getTypeInstanceId(), container.getAddress().get(), container.getPosition().get(), container.getExpressionId().get());
        final INaviInstruction instruction = InstructionCache.get(provider).getInstructionByAddress(reference.getAddress(), reference.getTypeInstance().getModule().getConfiguration().getId());
        if (instruction != null) {
            final INaviOperandTree operandTree = instruction.getOperands().get(reference.getPosition());
            final INaviOperandTreeNode root = operandTree.getRootNode();
            final OperandOrderIterator iterator = new OperandOrderIterator(root);
            while (iterator.next()) {
                final INaviOperandTreeNode currentNode = (INaviOperandTreeNode) iterator.current();
                if (currentNode.getId() == container.getExpressionId().get()) {
                    typeContainer.initializeTypeInstanceReference(reference.getAddress(), reference.getPosition(), container.getTypeInstanceId(), currentNode);
                    break;
                }
            }
        }
    } else if (container.getDatabaseOperation().equals("UPDATE")) {
    // currently not be possible at all.
    } else if (container.getDatabaseOperation().equals("DELETE")) {
        typeContainer.deleteReference(container.getTypeInstanceId(), container.getAddress().get(), container.getPosition().get(), container.getExpressionId().get());
    } else {
        throw new IllegalStateException("Error: the database operation " + container.getDatabaseOperation() + " is currently not supported.");
    }
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) TypeInstanceReference(com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceReference) INaviOperandTree(com.google.security.zynamics.binnavi.disassembly.INaviOperandTree) OperandOrderIterator(com.google.security.zynamics.zylib.disassembly.OperandOrderIterator) TypeInstanceContainer(com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceContainer) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 59 with INaviInstruction

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

the class PostgreSQLCommentNotificationParser method processNodeLocalInstructionCommentNotification.

/**
 * Parses the {@link PGNotification} notifications from the database back end for local
 * instruction comments by using a regular expression. If the regular expression matches the
 * supplied {@link PGNotification} notification, it is determined if the instruction in the
 * notification is currently loaded, and if a {@link CommentNotificationContainer} with the data
 * from the notification 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 processNodeLocalInstructionCommentNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher instructionMatcher = INSTRUCTION_LOCAL_PATTERN.matcher(notification.getParameter());
    final boolean instructionMatchFound = instructionMatcher.find();
    if (!instructionMatchFound) {
        return null;
    }
    final Integer moduleId = Integer.parseInt(instructionMatcher.group(3));
    final Integer nodeId = Integer.parseInt(instructionMatcher.group(4));
    final BigInteger notificationInstructionAddress = new BigInteger(instructionMatcher.group(6));
    final Integer commentId = instructionMatcher.group(7).equals("null") ? null : Integer.parseInt(instructionMatcher.group(7));
    final INaviModule module = provider.findModule(moduleId);
    if ((module == null) || !module.isLoaded()) {
        return null;
    }
    final IAddress address = new CAddress(notificationInstructionAddress);
    final INaviInstruction instruction = InstructionCache.get(provider).getInstructionByAddress(address, module.getConfiguration().getId());
    if (instruction == null) {
        return null;
    }
    final INaviCodeNode codeNode = (INaviCodeNode) NodeCache.get(provider).getNodeById(nodeId);
    if (codeNode == null) {
        return null;
    }
    final CommentOperation operation = commentId == null ? CommentOperation.DELETE : CommentOperation.APPEND;
    return new InstructionCommentNotificationContainer(instruction, codeNode, operation, CommentScope.LOCAL, commentId);
}
Also used : BigInteger(java.math.BigInteger) CommentOperation(com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) Matcher(java.util.regex.Matcher) BigInteger(java.math.BigInteger) InstructionCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.InstructionCommentNotificationContainer) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 60 with INaviInstruction

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

the class PostgreSQLCommentNotificationParser method processInstructionGlobalCommentNotification.

/**
 * Parses the notifications from the database back end for global instruction comments by using a
 * regular expression. If the regular expression matched the supplied {@link PGNotification}
 * notification, it is determined if the {@link INaviInstruction} instruction in the notification
 * 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 processInstructionGlobalCommentNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher matcher = INSTRUCTION_GLOBAL_PATTERN.matcher(notification.getParameter());
    if (!matcher.find()) {
        return null;
    }
    final Integer moduleId = Integer.parseInt(matcher.group(3));
    final IAddress address = new CAddress(new BigInteger(matcher.group(4)));
    final Integer commentId = matcher.group(7) == null ? null : Integer.parseInt(matcher.group(7));
    final INaviModule module = provider.findModule(moduleId);
    if ((module == null) || !module.isLoaded()) {
        return null;
    }
    final INaviInstruction instruction = InstructionCache.get(provider).getInstructionByAddress(address, moduleId);
    if (instruction == null) {
        return null;
    }
    final CommentOperation operation = commentId == null ? CommentOperation.DELETE : CommentOperation.APPEND;
    return new InstructionCommentNotificationContainer(instruction, null, operation, CommentScope.GLOBAL, 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) BigInteger(java.math.BigInteger) InstructionCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.InstructionCommentNotificationContainer) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Aggregations

INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)82 Test (org.junit.Test)27 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)26 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)24 ArrayList (java.util.ArrayList)24 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)20 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)18 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)16 COperandTree (com.google.security.zynamics.binnavi.disassembly.COperandTree)15 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)15 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)10 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)10 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)9 IBlockNode (com.google.security.zynamics.binnavi.disassembly.IBlockNode)9 INaviOperandTreeNode (com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode)9 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)9 UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)9 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)8 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)8 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)7