Search in sources :

Example 1 with Section

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

the class MockSqlProvider method createSection.

@Override
public int createSection(final int moduleId, final String name, final Integer commentId, final BigInteger startAddress, final BigInteger endAddress, final SectionPermission permission, final byte[] data) throws CouldntSaveDataException {
    INaviModule sectionModule = null;
    for (final INaviModule module : modules) {
        if (module.getConfiguration().getId() == moduleId) {
            sectionModule = module;
        }
    }
    final Section section = new Section(sectionId++, name, CommentManager.get(this), sectionModule, new CAddress(startAddress), new CAddress(endAddress), permission, data);
    sections.put(moduleId, section);
    return section.getId();
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) Section(com.google.security.zynamics.binnavi.disassembly.types.Section) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 2 with Section

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

the class PostgreSQLSectionFunctions method loadSections.

/**
   * Loads all sections that are associated with the given module.
   * 
   * @param provider The SQL provider that holds the database connection.
   * @param module The module whose sections should be loaded.
   * @return The list of sections loaded from the database.
   * @throws CouldntLoadDataException Thrown if the sections could not be loaded from the database.
   */
public static Map<Section, Integer> loadSections(final SQLProvider provider, final INaviModule module) throws CouldntLoadDataException {
    Preconditions.checkNotNull(provider, "Error: provider argument can not be null");
    Preconditions.checkNotNull(module, "Error: module argument can not be null");
    final HashMap<Section, Integer> sections = Maps.newHashMap();
    final String query = "SELECT * FROM get_sections(?)";
    try (PreparedStatement statement = provider.getConnection().getConnection().prepareStatement(query)) {
        statement.setInt(1, module.getConfiguration().getId());
        final ResultSet result = statement.executeQuery();
        while (result.next()) {
            final int id = result.getInt("id");
            final String name = result.getString("name");
            Integer commentId = result.getInt("comment_id");
            if (result.wasNull()) {
                commentId = null;
            }
            final IAddress startAddress = new CAddress(result.getLong("start_address"));
            final IAddress endAddress = new CAddress(result.getLong("end_address"));
            final SectionPermission permission = SectionPermission.valueOf(result.getString("permission"));
            final byte[] data = result.getBytes("data");
            sections.put(new Section(id, name, CommentManager.get(provider), module, startAddress, endAddress, permission, data), commentId);
        }
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
    return sections;
}
Also used : SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) PreparedStatement(java.sql.PreparedStatement) Section(com.google.security.zynamics.binnavi.disassembly.types.Section) SectionPermission(com.google.security.zynamics.binnavi.disassembly.types.SectionPermission) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) BigInteger(java.math.BigInteger) ResultSet(java.sql.ResultSet)

Example 3 with Section

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

the class CCodeNodeMenu method addImmediateOperandMenu.

private void addImmediateOperandMenu(final COperandTreeNode node, final SectionContainer sections, final INaviModule module) {
    add(new CIntegerOperandMenu(node, node.getReplacement()));
    final long address = Long.parseLong(node.getValue());
    final List<Section> containingSections = sections.findSections(new CAddress(address));
    if (containingSections.size() == 1) {
        add(new GotoSectionAction(containingSections.get(0), address, module));
    } else if (containingSections.size() > 1) {
        add(new GotoSectionMenu(containingSections, address, module));
    }
    addSeparator();
}
Also used : Section(com.google.security.zynamics.binnavi.disassembly.types.Section) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 4 with Section

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

the class PostgreSQLSectionFunctionsTests method testSetSectionName4.

@Test
public void testSetSectionName4() throws CouldntSaveDataException, CouldntLoadDataException, LoadCancelledException {
    final String newName = " NEW SECTION NAME ";
    final INaviModule module = getKernel32Module();
    final Map<Section, Integer> sections = getProvider().loadSections(module);
    final Section section = sections.keySet().iterator().next();
    getProvider().setSectionName(module.getConfiguration().getId(), section.getId(), newName);
    module.close();
    module.load();
    final Section section2 = module.getContent().getSections().getSection(section.getId());
    Assert.assertEquals(newName, section2.getName());
}
Also used : BigInteger(java.math.BigInteger) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) Section(com.google.security.zynamics.binnavi.disassembly.types.Section) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 5 with Section

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

the class PostgreSQLSectionFunctionsTests method testDeleteSection1.

@Test
public void testDeleteSection1() throws CouldntLoadDataException, LoadCancelledException {
    final INaviModule module = getKernel32Module();
    final Map<Section, Integer> sections = getProvider().loadSections(module);
    final int numberOfSections = sections.size();
    final Section section = sections.keySet().iterator().next();
    getProvider().deleteSection(section);
    module.close();
    module.load();
    final Map<Section, Integer> sections2 = getProvider().loadSections(module);
    Assert.assertEquals(numberOfSections - 1, sections2.size());
}
Also used : BigInteger(java.math.BigInteger) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) Section(com.google.security.zynamics.binnavi.disassembly.types.Section) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Aggregations

Section (com.google.security.zynamics.binnavi.disassembly.types.Section)10 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)4 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)4 BigInteger (java.math.BigInteger)4 Test (org.junit.Test)4 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)3 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)1 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)1 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)1 INaviOperandTreeNode (com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode)1 BaseType (com.google.security.zynamics.binnavi.disassembly.types.BaseType)1 RawTypeInstance (com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstance)1 SectionPermission (com.google.security.zynamics.binnavi.disassembly.types.SectionPermission)1 TypeInstance (com.google.security.zynamics.binnavi.disassembly.types.TypeInstance)1 TypeInstanceContainer (com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceContainer)1 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Before (org.junit.Before)1