use of com.google.security.zynamics.binnavi.disassembly.COperandTree in project binnavi by google.
the class PostgreSQLProviderTest method testInstructionFunctionsAddReference1.
@Test
public void testInstructionFunctionsAddReference1() throws CouldntSaveDataException, CouldntLoadDataException, LoadCancelledException {
final INaviModule module = getProvider().loadModules().get(1);
module.load();
final INaviFunction function = module.getContent().getFunctionContainer().getFunctions().get(1800);
function.load();
final IBlockNode basicBlock = function.getBasicBlocks().get(0);
final INaviInstruction instruction = Iterables.get(basicBlock.getInstructions(), 1);
final COperandTree tree = instruction.getOperands().get(0);
final INaviOperandTreeNode node = tree.getRootNode();
final IAddress address = instruction.getAddress();
final ReferenceType type = ReferenceType.DATA;
final int references = node.getReferences().size();
PostgreSQLInstructionFunctions.addReference(getProvider(), node, address, type);
final INaviModule module2 = getProvider().loadModules().get(1);
module2.load();
final INaviFunction function2 = module2.getContent().getFunctionContainer().getFunctions().get(1800);
function2.load();
final IBlockNode basicBlock2 = function2.getBasicBlocks().get(0);
final INaviInstruction instruction2 = Iterables.get(basicBlock2.getInstructions(), 1);
final COperandTree tree2 = instruction2.getOperands().get(0);
final INaviOperandTreeNode node2 = tree2.getRootNode();
assertEquals(references + 1, node2.getReferences().size());
}
use of com.google.security.zynamics.binnavi.disassembly.COperandTree in project binnavi by google.
the class PostgreSQLProviderTest method testSave.
@Test
public void testSave() throws CouldntSaveDataException, CouldntLoadDataException, CouldntDeleteException, CPartialLoadException, InternalTranslationException, LoadCancelledException, MaybeNullException {
final CTagManager tagManager = getProvider().loadTagManager(TagType.NODE_TAG);
tagManager.addTag(tagManager.getRootTag(), "Node Tag I");
tagManager.addTag(tagManager.getRootTag(), "Node Tag II");
final ITreeNode<CTag> tag1 = tagManager.getRootTag().getChildren().get(0);
final ITreeNode<CTag> tag2 = tagManager.getRootTag().getChildren().get(1);
final INaviModule module = getProvider().loadModules().get(0);
module.load();
final CView view = module.getContent().getViewContainer().createView("Save View", "Save View Description");
final INaviFunction function = module.getContent().getFunctionContainer().getFunction("sub_1002B87");
function.load();
final List<COperandTree> operands = new ArrayList<COperandTree>();
final COperandTreeNode root1 = module.createOperandExpression("dword", ExpressionType.SIZE_PREFIX);
final COperandTreeNode child1 = module.createOperandExpression("eax", ExpressionType.REGISTER);
COperandTreeNode.link(root1, child1);
final COperandTreeNode root2 = module.createOperandExpression("dword", ExpressionType.SIZE_PREFIX);
final COperandTreeNode child2 = module.createOperandExpression("16", ExpressionType.IMMEDIATE_INTEGER);
COperandTreeNode.link(root2, child2);
final COperandTree operand1 = module.createOperand(root1);
final COperandTree operand2 = module.createOperand(root2);
operands.add(operand1);
operands.add(operand2);
final Iterable<INaviInstruction> instructions = function.getBasicBlocks().get(0).getInstructions();
final Iterable<INaviInstruction> instructions2 = function.getBasicBlocks().get(1).getInstructions();
final CCodeNode codeNode = view.getContent().createCodeNode(function, Lists.newArrayList(instructions));
codeNode.tagNode(tag1.getObject());
codeNode.getComments().appendLocalCodeNodeComment("XXX");
codeNode.getComments().appendLocalInstructionComment(Iterables.getLast(codeNode.getInstructions()), "YYY");
Iterables.getLast(codeNode.getInstructions()).appendGlobalComment(" GLOBAL INSTRUCTION COMMENT ");
@SuppressWarnings("unused") final CCodeNode codeNode2 = view.getContent().createCodeNode(null, Lists.newArrayList(instructions2));
final CFunctionNode functionNode = view.getContent().createFunctionNode(function);
functionNode.tagNode(tag2.getObject());
functionNode.appendLocalFunctionComment("ZZZ");
@SuppressWarnings("unused") final CNaviViewEdge edge = view.getContent().createEdge(codeNode, functionNode, EdgeType.JUMP_UNCONDITIONAL);
view.save();
view.close();
view.load();
assertEquals(3, view.getGraph().getNodes().size());
assertEquals(1, view.getGraph().getEdges().size());
assertTrue(view.getGraph().getNodes().get(0).isTagged(tag1.getObject()));
assertTrue(view.getGraph().getNodes().get(2).isTagged(tag2.getObject()));
final CCodeNode loadedCodeNode = (CCodeNode) view.getGraph().getNodes().get(0);
final CCodeNode loadedCodeNode2 = (CCodeNode) view.getGraph().getNodes().get(1);
assertEquals("XXX", loadedCodeNode.getComments().getLocalCodeNodeComment().get(0).getComment());
final INaviInstruction customInstruction = Iterables.getLast(loadedCodeNode.getInstructions());
assertEquals(" GLOBAL INSTRUCTION COMMENT ", customInstruction.getGlobalComment().get(0).getComment());
assertEquals("YYY", loadedCodeNode.getComments().getLocalInstructionComment(customInstruction).get(0).getComment());
final ReilTranslator<INaviInstruction> translator = new ReilTranslator<INaviInstruction>();
translator.translate(new StandardEnvironment(), loadedCodeNode);
translator.translate(new StandardEnvironment(), loadedCodeNode2);
final CFunctionNode loadedFunctionNode = (CFunctionNode) view.getGraph().getNodes().get(2);
assertEquals("ZZZ", loadedFunctionNode.getLocalFunctionComment().get(0).getComment());
tagManager.deleteTag(tag1);
tagManager.deleteTag(tag2);
}
use of com.google.security.zynamics.binnavi.disassembly.COperandTree in project binnavi by google.
the class PostgreSQLProviderTest method testInstructionFunctionsAddReference6.
@Test(expected = CouldntSaveDataException.class)
public void testInstructionFunctionsAddReference6() throws CouldntSaveDataException, CouldntLoadDataException, LoadCancelledException {
final INaviModule module = getProvider().loadModules().get(1);
module.load();
final INaviFunction function = module.getContent().getFunctionContainer().getFunctions().get(1800);
function.load();
final IBlockNode basicBlock = function.getBasicBlocks().get(0);
final INaviInstruction instruction = Iterables.get(basicBlock.getInstructions(), 1);
final COperandTree tree = instruction.getOperands().get(0);
final INaviOperandTreeNode node = tree.getRootNode();
final IAddress address = instruction.getAddress();
final ReferenceType type = ReferenceType.DATA;
PostgreSQLInstructionFunctions.addReference(getProvider(), node, address, type);
}
use of com.google.security.zynamics.binnavi.disassembly.COperandTree in project binnavi by google.
the class PostgreSQLProviderTest method testInstructionFunctionsCreateInstruction1.
@Test
public void testInstructionFunctionsCreateInstruction1() throws SQLException, CouldntLoadDataException, LoadCancelledException {
final INaviModule module = getProvider().loadModules().get(0);
module.load();
final String mnemonic = "burzel";
final IAddress iAddress = new CAddress(0x1234);
final COperandTreeNode rootNode = module.createOperandExpression("eax", ExpressionType.REGISTER);
final COperandTree tree = new COperandTree(rootNode, getProvider(), module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final List<COperandTree> operands = new ArrayList<COperandTree>();
operands.add(tree);
final byte[] data = { 0xF };
final String architecture = "x86-32";
final INaviInstruction instruction = module.createInstruction(iAddress, mnemonic, operands, data, architecture);
PostgreSQLInstructionFunctions.createInstructions(getProvider(), Lists.newArrayList(instruction));
}
use of com.google.security.zynamics.binnavi.disassembly.COperandTree in project binnavi by google.
the class InstructionConverter method generateTree.
/**
* Converts a raw operand tree into a proper operand tree.
*
* @param rawTree The raw operand tree.
* @param provider The connection to the database.
* @param module
*
* @return The proper operand tree.
*/
private static COperandTree generateTree(final OperandTree rawTree, final SQLProvider provider, final INaviModule module) {
final ArrayList<COperandTreeNode> realNodes = new ArrayList<COperandTreeNode>();
final HashMap<COperandTreeNode, OperandTreeNode> realToRawMapping = new HashMap<COperandTreeNode, OperandTreeNode>();
final HashMap<Integer, COperandTreeNode> idToRealMapping = new HashMap<Integer, COperandTreeNode>();
COperandTreeNode root = null;
final TypeManager typeManager = module.getTypeManager();
final TypeInstanceContainer instanceContainer = module.getContent().getTypeInstanceContainer();
for (final OperandTreeNode rawNode : rawTree.getNodes()) {
final COperandTreeNode node = new COperandTreeNode(rawNode.getId(), rawNode.getType(), rawNode.getValue(), rawNode.getReplacement(), rawNode.getReferences(), provider, typeManager, instanceContainer);
if (rawNode.getTypeSubstitution() != null) {
typeManager.initializeTypeSubstitution(node, rawNode.getTypeSubstitution());
}
if (rawNode.getTypeInstanceId() != null) {
instanceContainer.initializeTypeInstanceReference(rawNode.getAddress(), rawNode.getPosition(), rawNode.getId(), node);
}
realToRawMapping.put(node, rawNode);
idToRealMapping.put(rawNode.getId(), node);
if (rawNode.getParentId() == null) {
root = node;
}
realNodes.add(node);
}
for (final COperandTreeNode realNode : realNodes) {
// Link the real nodes here.
// To link two real nodes, it is necessary to know
// which node is the parent and which node is the
// child.
final OperandTreeNode rawNode = realToRawMapping.get(realNode);
final Integer parentId = rawNode.getParentId();
if (parentId == null) {
continue;
}
final COperandTreeNode realParent = idToRealMapping.get(parentId);
COperandTreeNode.link(realParent, realNode);
}
return new COperandTree(root, provider, typeManager, instanceContainer);
}
Aggregations