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