use of com.google.security.zynamics.zylib.disassembly.IAddress in project binnavi by google.
the class AddressSpaceTest method testConstructorAlternative.
@Test
public void testConstructorAlternative() throws com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException, com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException, LoadCancelledException {
final MockSqlProvider provider = new MockSqlProvider();
final MockDatabase mockDb = new MockDatabase(provider);
final Database database = new Database(mockDb);
final com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate template = new com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate(1, "", "", 0, provider);
mockDb.getContent().getDebuggerTemplateManager().addDebugger(template);
final CModule internalModule = new CModule(123, "Name", "Comment", new Date(), new Date(), "12345678123456781234567812345678", "1234567812345678123456781234567812345678", 55, 66, new CAddress(0x555), new CAddress(0x666), new com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate(1, "Mock Debugger", "localhaus", 88, provider), null, Integer.MAX_VALUE, false, provider);
mockDb.getContent().addModule(internalModule);
final CAddressSpace internalAddressSpace = new CAddressSpace(1, "Mock Space", "Mock Space Description", new Date(), new Date(), new LinkedHashMap<INaviModule, IAddress>(), null, provider, new MockProject());
internalAddressSpace.load();
internalAddressSpace.getConfiguration().setDebuggerTemplate(template);
internalAddressSpace.getContent().addModule(internalModule);
final Project project = ProjectFactory.get();
final AddressSpace addressSpace = new AddressSpace(database, project, internalAddressSpace);
assertEquals(1, addressSpace.getModules().size());
assertNotNull(addressSpace.getDebuggerTemplate());
assertNotNull(addressSpace.getDebugger());
}
use of com.google.security.zynamics.zylib.disassembly.IAddress in project binnavi by google.
the class PostgreSQLCommentNotificationParser method processNodeGlobalCommentNotification.
/**
* Parses the notifications from the database back end for global code node comments by using a
* regular expression. If the regular expression matches the supplied {@link PGNotification}
* notification, it is determined if the code node 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 Collection<CommentNotification> processNodeGlobalCommentNotification(final PGNotification notification, final SQLProvider provider) {
final Matcher matcher = NODE_GLOBAL_PATTERN.matcher(notification.getParameter());
if (!matcher.find()) {
return new ArrayList<>();
}
final String databaseOperation = matcher.group(2);
final int moduleId = Integer.parseInt(matcher.group(3));
final IAddress nodeAddress = new CAddress(new BigInteger(matcher.group(4)));
final Integer commentId = matcher.group(6) == null ? null : Integer.parseInt(matcher.group(6));
final INaviModule notificationModule = provider.findModule(moduleId);
if ((notificationModule == null) || !notificationModule.isLoaded()) {
return new ArrayList<>();
}
final ImmutableCollection<INaviViewNode> nodes = NodeCache.get(provider).getNodeByAddress(nodeAddress, moduleId);
if (nodes == null) {
return new ArrayList<>();
}
final CommentOperation operation = databaseOperation.equalsIgnoreCase("DELETE") ? CommentOperation.DELETE : CommentOperation.APPEND;
Collection<CommentNotification> notifications = new ArrayList<>();
for (INaviViewNode node : nodes) {
notifications.add(new CodeNodeCommentNotificationContainer((INaviCodeNode) node, operation, CommentScope.GLOBAL, commentId));
}
return notifications;
}
use of com.google.security.zynamics.zylib.disassembly.IAddress 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;
}
use of com.google.security.zynamics.zylib.disassembly.IAddress 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);
}
use of com.google.security.zynamics.zylib.disassembly.IAddress 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);
}
Aggregations