use of com.google.security.zynamics.binnavi.disassembly.COperandTree in project binnavi by google.
the class OperandTest method testConstructor.
@Test
public void testConstructor() {
final MockModule mockModule = new MockModule();
final COperandTreeNode rootNode = new COperandTreeNode(1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), new MockSqlProvider(), mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
final COperandTreeNode childNode = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "eax", null, new ArrayList<IReference>(), new MockSqlProvider(), mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
COperandTreeNode.link(rootNode, childNode);
final COperandTree tree = new COperandTree(rootNode, new MockSqlProvider(), mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
final Operand operand = new Operand(tree);
assertEquals("dword", operand.getRootNode().getValue());
assertEquals(1, operand.getRootNode().getChildren().size());
assertEquals("eax", operand.getRootNode().getChildren().get(0).getValue());
assertEquals("eax", operand.toString());
}
use of com.google.security.zynamics.binnavi.disassembly.COperandTree in project binnavi by google.
the class InstructionTest method testConstructor.
@Test
public void testConstructor() throws CouldntLoadDataException, LoadCancelledException {
final SQLProvider provider = new MockSqlProvider();
final CModule internalModule = new CModule(123, "Name", "Comment", new Date(), new Date(), "12345678123456781234567812345678", "1234567812345678123456781234567812345678", 55, 66, new CAddress(0x555), new CAddress(0x666), new DebuggerTemplate(1, "Mock Debugger", "localhaus", 88, provider), null, Integer.MAX_VALUE, false, provider);
internalModule.load();
final COperandTreeNode rootNode1 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "eax", null, new ArrayList<IReference>(), provider, internalModule.getTypeManager(), internalModule.getContent().getTypeInstanceContainer());
final COperandTreeNode rootNode2 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "ebx", null, new ArrayList<IReference>(), provider, internalModule.getTypeManager(), internalModule.getContent().getTypeInstanceContainer());
final COperandTree operand1 = new COperandTree(rootNode1, provider, internalModule.getTypeManager(), internalModule.getContent().getTypeInstanceContainer());
final COperandTree operand2 = new COperandTree(rootNode2, provider, internalModule.getTypeManager(), internalModule.getContent().getTypeInstanceContainer());
final List<COperandTree> operands = Lists.newArrayList(operand1, operand2);
final CInstruction internalInstruction = new CInstruction(false, internalModule, new CAddress(0x123), "mov", operands, new byte[] { 1, 2, 3 }, "x86-32", provider);
final Instruction instruction = new Instruction(internalInstruction);
assertEquals(0x123, instruction.getAddress().toLong());
assertEquals(null, instruction.getComment());
assertArrayEquals(new byte[] { 1, 2, 3 }, instruction.getData());
assertEquals("mov", instruction.getMnemonic());
assertEquals(2, instruction.getOperands().size());
assertEquals("eax", instruction.getOperands().get(0).getRootNode().getChildren().get(0).getValue());
assertEquals("ebx", instruction.getOperands().get(1).getRootNode().getChildren().get(0).getValue());
assertEquals("123 mov eax, ebx", instruction.toString());
assertEquals("x86-32", instruction.getArchitecture());
}
use of com.google.security.zynamics.binnavi.disassembly.COperandTree in project binnavi by google.
the class PostgreSQLInstructionFunctions method createInstructions.
/**
* Saves an instruction to the database.
*
* @param provider The provider used to access the database.
* @param instructions The instruction to save.
*
* @throws SQLException Thrown if the instruction could not be created.
*/
public static void createInstructions(final SQLProvider provider, final Iterable<INaviInstruction> instructions) throws SQLException {
Preconditions.checkNotNull(provider, "IE01550: Provider argument can not be null");
Preconditions.checkNotNull(instructions, "IE01554: Instruction argument can not be null");
final String query = "INSERT INTO " + CTableNames.INSTRUCTIONS_TABLE + "(module_id, address, mnemonic, data, native, architecture, comment_id) " + "VALUES(?, ?, ?, ?, ?, ?, ?)";
final PreparedStatement insertStatement = provider.getConnection().getConnection().prepareStatement(query);
final ArrayList<INaviInstruction> instructionsWithUnsavedComments = new ArrayList<INaviInstruction>();
final List<List<COperandTree>> operands = new ArrayList<List<COperandTree>>();
for (final INaviInstruction instruction : instructions) {
final String mnemonic = instruction.getMnemonic();
final byte[] data = instruction.getData();
operands.add(instruction.getOperands());
final INaviModule module = instruction.getModule();
final IAddress address = instruction.getAddress();
final int moduleID = module.getConfiguration().getId();
final List<IComment> comments = instruction.getGlobalComment();
final Integer commentId = comments == null ? null : comments.size() == 0 ? null : Iterables.getLast(comments).getId();
if ((comments != null) && (comments.size() != 0) && (commentId == null)) {
instructionsWithUnsavedComments.add(instruction);
}
try {
insertStatement.setInt(1, moduleID);
insertStatement.setObject(2, address.toBigInteger(), Types.BIGINT);
insertStatement.setString(3, mnemonic);
insertStatement.setBytes(4, data);
insertStatement.setBoolean(5, false);
insertStatement.setObject(6, instruction.getArchitecture(), Types.OTHER);
if (commentId == null) {
insertStatement.setNull(7, Types.INTEGER);
} else {
insertStatement.setInt(7, commentId);
}
insertStatement.execute();
} finally {
insertStatement.close();
}
}
// unsaved comments.
for (final INaviInstruction instruction : instructionsWithUnsavedComments) {
final ArrayList<IComment> instructionComments = new ArrayList<IComment>();
for (final IComment comment : instruction.getGlobalComment()) {
try {
final Integer commentId = PostgreSQLInstructionFunctions.appendGlobalInstructionComment(provider, instruction, comment.getComment(), comment.getUser().getUserId());
final IComment newComment = new CComment(commentId, comment.getUser(), comment.getParent(), comment.getComment());
instructionComments.add(newComment);
} catch (final CouldntSaveDataException exception) {
CUtilityFunctions.logException(exception);
}
}
instruction.initializeGlobalComment(instructionComments);
}
for (final List<COperandTree> operand : operands) {
int position = 0;
for (final COperandTree operandTree : operand) {
createOperandTree(provider, operandTree, position);
position++;
}
}
}
use of com.google.security.zynamics.binnavi.disassembly.COperandTree in project binnavi by google.
the class BreakpointHelpersTest method setUp.
@Before
public void setUp() throws DebugExceptionWrapper, CouldntLoadDataException, LoadCancelledException, FileReadException {
ConfigManager.instance().read();
final CDatabase database = new CDatabase("", "", "", "", "", "", "", false, false);
final Database apiDatabase = new Database(database);
final SQLProvider mockProvider = new MockSqlProvider();
final ITreeNode<CTag> nodeRootNode = new TreeNode<CTag>(new CTag(0, "", "", TagType.NODE_TAG, mockProvider));
final Tree<CTag> nodeTagTree = new Tree<CTag>(nodeRootNode);
final TagManager nodeTagManager = new TagManager(new CTagManager(nodeTagTree, TagType.NODE_TAG, mockProvider));
final ITreeNode<CTag> viewRootNode = new TreeNode<CTag>(new CTag(0, "", "", TagType.VIEW_TAG, mockProvider));
final Tree<CTag> viewTagTree = new Tree<CTag>(viewRootNode);
final TagManager viewTagManager = new TagManager(new CTagManager(viewTagTree, TagType.VIEW_TAG, mockProvider));
m_module = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, mockProvider);
m_module.load();
m_mockDebugger = new MockDebugger(m_moduleDebugSettings);
m_mockDebugger.connect();
m_debugger = new Debugger(m_mockDebugger);
final INaviFunction parentFunction = m_module.getContent().getFunctionContainer().getFunctions().get(0);
m_mockDebugger.setAddressTranslator(m_module, new CAddress(0), new CAddress(0x1000));
final ViewContainer viewContainer = new Module(apiDatabase, m_module, nodeTagManager, viewTagManager);
final INaviView naviView = new MockView(mockProvider);
final Function apiFunction = new Function(ModuleFactory.get(), parentFunction);
final COperandTreeNode rootNode1 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "eax", null, new ArrayList<IReference>(), mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
final COperandTreeNode rootNode2 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "ebx", null, new ArrayList<IReference>(), mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
final COperandTree operand1 = new COperandTree(rootNode1, mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
final COperandTree operand2 = new COperandTree(rootNode2, mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
final List<COperandTree> operands = Lists.newArrayList(operand1, operand2);
final CInstruction internalInstruction = new CInstruction(true, m_module, new CAddress(0x1234), "mov", operands, new byte[] { 1, 2, 3 }, "x86-32", mockProvider);
m_view = new View(viewContainer, naviView, nodeTagManager, viewTagManager);
m_node = m_view.createCodeNode(apiFunction, Lists.newArrayList(new Instruction(internalInstruction)));
setM_functionNode(m_view.createFunctionNode(apiFunction));
}
use of com.google.security.zynamics.binnavi.disassembly.COperandTree in project binnavi by google.
the class CCodeNodeUpdater method initializeListeners.
/**
* Initializes the listeners that are responsible for updating the code node.
*/
private void initializeListeners() {
try {
codeNode.getParentFunction().addListener(functionUpdater);
codeNode.getParentFunction().getModule().addListener(moduleUpdater);
} catch (final MaybeNullException exception) {
// The code nodes does not have a parent function, therefore the information
// about the parent function is not shown in the code and does not have to
// be processed when updating.
}
final HashMap<INaviInstruction, INaviFunction> referenceMap = CReferenceFinder.getCodeReferenceMap(codeNode);
for (final INaviFunction functionReference : Sets.newHashSet(referenceMap.values())) {
functionReference.addListener(functionUpdater);
}
codeNode.addListener(codeNodeListener);
for (final INaviInstruction instruction : codeNode.getInstructions()) {
instruction.addListener(instructionUpdater);
for (final COperandTree tree : instruction.getOperands()) {
for (final INaviOperandTreeNode currentNode : tree.getNodes()) {
currentNode.addListener(operandTreeUpdater);
}
}
}
final Iterator<CTag> it = codeNode.getTagsIterator();
while (it.hasNext()) {
it.next().addListener(tagUpdater);
}
for (final IDebugger debugger : provider.getDebuggers()) {
debugger.getProcessManager().addListener(debuggerUpdater);
}
provider.addListener(debuggerProviderListener);
graph.getSettings().getDisplaySettings().addListener(settingsUpdater);
try {
codeNode.getParentFunction().getModule().getTypeManager().addListener(substitutionsUpdater);
} catch (final MaybeNullException exception) {
// If the code node doesn't have a a parent function, it is not in the database and therefore
// cannot receive type substitutions.
}
}
Aggregations