use of com.google.security.zynamics.zylib.disassembly.IReference 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.zylib.disassembly.IReference 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.zylib.disassembly.IReference in project binnavi by google.
the class CInliningHelper method inlineFunctionNode.
/**
* Replaces a function node in a view with the basic blocks of the functions represented by the
* function node.
*
* @param view View where the inline operation takes place.
* @param node Node that is inlined.
*/
public static void inlineFunctionNode(final INaviView view, final INaviFunctionNode node) {
Preconditions.checkNotNull(view, "IE00119: View argument can not be null");
Preconditions.checkNotNull(node, "IE00120: Node argument can not be null");
Preconditions.checkArgument(view.isLoaded(), "IE00122: View must be loaded before it can be inlined");
Preconditions.checkArgument(view.getGraph().getNodes().contains(node), "IE00123: Code node does not belong to the view");
Preconditions.checkArgument(node.getFunction().isLoaded(), "IE00124: Function must be loaded before it can be inlined");
Preconditions.checkArgument(node.getFunction().getBasicBlockCount() != 0, "IE00125: Functions with 0 blocks can not be inlined");
GroupHelpers.expandParents(node);
final INaviGroupNode parentGroup = node.getParentGroup();
final List<INaviEdge> oldIncomingEdges = node.getIncomingEdges();
view.getContent().deleteNode(node);
// Insert the nodes and edges from the loaded function
final Triple<CCodeNode, List<CCodeNode>, ArrayList<CCodeNode>> nodes = CInliningHelper.insertNodes(view, node.getFunction(), parentGroup);
final INaviCodeNode entryNode = nodes.first();
final ArrayList<CCodeNode> returnNodes = nodes.third();
for (final INaviEdge incomingEdge : oldIncomingEdges) {
// Create edges from the parent nodes of the original block to entry node
// of the inlined function.
final EdgeType edgeType = incomingEdge.getType();
view.getContent().createEdge(incomingEdge.getSource(), entryNode, edgeType);
}
final List<INaviViewNode> graphNodes = view.getGraph().getNodes();
for (final INaviCodeNode newNode : returnNodes) {
newNode.setX(node.getX());
newNode.setY(node.getY());
for (final INaviInstruction instruction : newNode.getInstructions()) {
final List<IReference> references = getCodeReferences(instruction);
for (final IReference reference : references) {
final List<INaviViewNode> targetNodes = getTargetNode(reference, graphNodes);
for (final INaviViewNode targetNode : targetNodes) {
view.getContent().createEdge(newNode, targetNode, EdgeType.JUMP_UNCONDITIONAL);
}
}
}
}
}
use of com.google.security.zynamics.zylib.disassembly.IReference in project binnavi by google.
the class CReferenceFinder method fetchReferenceMap.
/**
* Fetch for outgoing code references of a tree node and all of its children.
*
* @param node The start node of the search.
* @param instruction The instruction the operand tree belongs to.
* @param functions The map of code references.
*/
private static void fetchReferenceMap(final IOperandTreeNode node, final INaviInstruction instruction, final Map<INaviInstruction, INaviFunction> functions) {
final List<IReference> references = node.getReferences();
for (final IReference reference : references) {
if (ReferenceType.isCodeReference(reference.getType())) {
final IAddress target = reference.getTarget();
final INaviFunction function = instruction.getModule().getContent().getFunctionContainer().getFunction(target);
if (function != null) {
functions.put(instruction, function);
}
}
}
for (final IOperandTreeNode child : node.getChildren()) {
fetchReferenceMap(child, instruction, functions);
}
}
use of com.google.security.zynamics.zylib.disassembly.IReference 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));
}
Aggregations