use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class CCodeNodeParserTest method testAddZero.
@Test
public void testAddZero() throws ParserException, CPartialLoadException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
// 00000000: mov eax, [esp+0]
final MockCodeNodeProvider cnProvider = new MockCodeNodeProvider();
final MockCodeNodeData instruction2 = new MockCodeNodeData();
instruction2.nodeId = 5193;
instruction2.address = new CAddress(0x4180dd);
instruction2.mnemonic = "mov";
instruction2.operandPosition = 0;
instruction2.expressionId = 1;
instruction2.expressionType = 6;
instruction2.symbol = "b4";
instruction2.immediate = null;
instruction2.parentId = 0;
instruction2.replacement = null;
final MockCodeNodeData instruction3 = new MockCodeNodeData();
instruction3.nodeId = 5193;
instruction3.address = new CAddress(0x4180dd);
instruction3.mnemonic = "mov";
instruction3.operandPosition = 0;
instruction3.expressionId = 29;
instruction3.expressionType = 4;
instruction3.symbol = "ss:";
instruction3.immediate = null;
instruction3.parentId = 1;
instruction3.replacement = null;
final MockCodeNodeData instruction4 = new MockCodeNodeData();
instruction4.nodeId = 5193;
instruction4.address = new CAddress(0x4180dd);
instruction4.mnemonic = "mov";
instruction4.operandPosition = 0;
instruction4.expressionId = 30;
instruction4.expressionType = 7;
instruction4.symbol = "[";
instruction4.immediate = null;
instruction4.parentId = 29;
instruction4.replacement = null;
final MockCodeNodeData instruction5 = new MockCodeNodeData();
instruction5.nodeId = 5193;
instruction5.address = new CAddress(0x4180dd);
instruction5.mnemonic = "mov";
instruction5.operandPosition = 0;
instruction5.expressionId = 31;
instruction5.expressionType = 4;
instruction5.symbol = "+";
instruction5.immediate = null;
instruction5.parentId = 30;
instruction5.replacement = null;
final MockCodeNodeData instruction6 = new MockCodeNodeData();
instruction6.nodeId = 5193;
instruction6.address = new CAddress(0x4180dd);
instruction6.mnemonic = "mov";
instruction6.operandPosition = 0;
instruction6.expressionId = 32;
instruction6.expressionType = 5;
instruction6.symbol = "esp";
instruction6.immediate = null;
instruction6.parentId = 31;
instruction6.replacement = null;
final MockCodeNodeData instruction7 = new MockCodeNodeData();
instruction7.nodeId = 5193;
instruction7.address = new CAddress(0x4180dd);
instruction7.mnemonic = "mov";
instruction7.operandPosition = 0;
instruction7.expressionId = 498;
instruction7.expressionType = 2;
instruction7.symbol = null;
instruction7.immediate = "0";
instruction7.parentId = 31;
instruction7.replacement = "134h+var_134";
final MockCodeNodeData instruction1 = new MockCodeNodeData();
instruction1.nodeId = 5193;
instruction1.address = new CAddress(0x4180dd);
instruction1.mnemonic = "mov";
instruction1.operandPosition = 1;
instruction1.expressionId = 1594;
instruction1.expressionType = 2;
instruction1.symbol = null;
instruction1.immediate = "4561216";
instruction1.parentId = 0;
instruction1.replacement = null;
cnProvider.data.add(instruction2);
cnProvider.data.add(instruction3);
cnProvider.data.add(instruction4);
cnProvider.data.add(instruction5);
cnProvider.data.add(instruction6);
cnProvider.data.add(instruction7);
cnProvider.data.add(instruction1);
final MockSqlProvider provider = new MockSqlProvider();
final MockModule module = new MockModule();
CFunctionContainerHelper.addFunction(module.getContent().getFunctionContainer(), new MockFunction(0));
final CCodeNodeParser p = new CCodeNodeParser(cnProvider, Lists.newArrayList(module), provider);
final List<CCodeNode> result = p.parse();
assertEquals(1, result.size());
assertEquals(1, Iterables.size(result.get(0).getInstructions()));
final ReilTranslator<INaviInstruction> translator = new ReilTranslator<INaviInstruction>();
try {
translator.translate(new StandardEnvironment(), Iterables.get(result.get(0).getInstructions(), 0));
} catch (final InternalTranslationException exception) {
CUtilityFunctions.logException(exception);
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class PostgreSQLProviderTest method testInstructionFunctionsAddReference5.
@Test(expected = NullPointerException.class)
public void testInstructionFunctionsAddReference5() 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();
PostgreSQLInstructionFunctions.addReference(getProvider(), node, address, null);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class PostgreSQLProviderTest method testInstructionFunctionsDeleteReference4.
@Test
public void testInstructionFunctionsDeleteReference4() throws CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException, CouldntDeleteException, MaybeNullException {
final INaviModule module = getProvider().loadModules().get(1);
module.load();
final INaviFunction function = module.getContent().getFunctionContainer().getFunction("DelayLoadFailureHook");
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().getFunction("DelayLoadFailureHook");
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());
PostgreSQLInstructionFunctions.deleteReference(getProvider(), node2, address, type);
final INaviModule module3 = getProvider().loadModules().get(1);
module3.load();
final INaviFunction function3 = module3.getContent().getFunctionContainer().getFunction("DelayLoadFailureHook");
function3.load();
final IBlockNode basicBlock3 = function3.getBasicBlocks().get(0);
final INaviInstruction instruction3 = Iterables.get(basicBlock3.getInstructions(), 1);
final COperandTree tree3 = instruction3.getOperands().get(0);
final INaviOperandTreeNode node3 = tree3.getRootNode();
assertEquals(references, node3.getReferences().size());
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class PostgreSQLGroupNodeCommentTests method appendInstructionCommentInGroupNode.
@Test
public void appendInstructionCommentInGroupNode() throws CouldntLoadDataException, LoadCancelledException, MaybeNullException, CPartialLoadException, CouldntSaveDataException {
final INaviModule module = getProvider().loadModules().get(0);
module.load();
final INaviFunction function = module.getContent().getFunctionContainer().getFunction("sub_1004565");
final INaviView view = module.getContent().getViewContainer().getView(function);
view.load();
assertEquals(42, view.getNodeCount());
final INaviViewNode node1 = view.getContent().getBasicBlocks().get(1);
final INaviViewNode node2 = view.getContent().getBasicBlocks().get(2);
view.getContent().createGroupNode(Lists.newArrayList(node1, node2));
final ZyGraph graph = CGraphBuilder.buildGraph(view);
final INaviView nonNativeView = graph.saveAs(new CModuleContainer(getDatabase(), module), " TEST INSTRUCTION COMMENTS IN GROUP NODE ", " TESTING GROUP NODE COMMENTS ");
final INaviInstruction instruction = view.getContent().getBasicBlocks().get(0).getLastInstruction();
final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
final String firstCommentString = "TEST INSTRUCTION COMMENT PROPAGATION";
final int firstCommentId = getProvider().appendGlobalInstructionComment(instruction, firstCommentString, user.getUserId());
final IComment firstComment = new CComment(firstCommentId, user, null, firstCommentString);
final ArrayList<IComment> commentsFromDatabase = getProvider().loadCommentById(firstCommentId);
assertNotNull(commentsFromDatabase);
assertEquals(1, commentsFromDatabase.size());
assertTrue(commentsFromDatabase.contains(firstComment));
final INaviInstruction instruction2 = nonNativeView.getBasicBlocks().get(0).getLastInstruction();
assertEquals(1, instruction2.getGlobalComment().size());
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class ZyGraphTest method testAddedCodeNode.
@Test
public void testAddedCodeNode() {
assertEquals(7, m_graph.visibleNodeCount());
assertEquals(89, NodeFunctions.getInvisibleNodes(m_graph).size());
assertEquals(96, m_graph.getRawView().getNodeCount());
final MockFunction function = new MockFunction(m_provider);
final List<INaviInstruction> instructions = Lists.newArrayList((INaviInstruction) new MockInstruction(new CAddress(0x123456), "mov", new ArrayList<COperandTree>(), null, m_module));
final CCodeNode codeNode = m_graph.getRawView().getContent().createCodeNode(function, instructions);
assertEquals(8, m_graph.visibleNodeCount());
assertEquals(89, NodeFunctions.getInvisibleNodes(m_graph).size());
assertEquals(97, m_graph.getRawView().getNodeCount());
final List<NaviNode> nodes = GraphHelpers.getNodes(m_graph);
final NaviNode cnn = searchNode(nodes, codeNode);
assertEquals(codeNode, cnn.getRawNode());
assertTrue(codeNode.isVisible());
assertEquals(codeNode.isVisible(), cnn.isVisible());
codeNode.setVisible(false);
assertFalse(codeNode.isVisible());
assertEquals(codeNode.isVisible(), cnn.isVisible());
codeNode.setVisible(true);
assertTrue(codeNode.isVisible());
assertEquals(codeNode.isVisible(), cnn.isVisible());
assertFalse(codeNode.isSelected());
assertEquals(codeNode.isSelected(), cnn.isSelected());
codeNode.setSelected(false);
assertFalse(codeNode.isSelected());
assertEquals(codeNode.isSelected(), cnn.isSelected());
codeNode.setSelected(true);
assertTrue(codeNode.isSelected());
assertEquals(codeNode.isSelected(), cnn.isSelected());
assertEquals(codeNode.getColor(), cnn.getRealizer().getFillColor());
codeNode.setColor(Color.GREEN);
assertEquals(Color.GREEN, codeNode.getColor());
assertEquals(codeNode.getColor(), cnn.getRealizer().getFillColor());
codeNode.setX(100);
assertEquals(100, codeNode.getX(), 0.1);
assertEquals(codeNode.getX(), cnn.getX(), 0.1);
codeNode.setY(200);
assertEquals(200, codeNode.getY(), 0.1);
assertEquals(codeNode.getY(), cnn.getY(), 0.1);
}
Aggregations