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