use of com.google.security.zynamics.binnavi.disassembly.CFunction in project binnavi by google.
the class FunctionNodeTest method testSetComment.
@Test
public void testSetComment() throws CouldntLoadDataException, CouldntLoadDataException, com.google.security.zynamics.binnavi.API.disassembly.CouldntLoadDataException, LoadCancelledException {
final MockSqlProvider provider = new MockSqlProvider();
final Database database = new Database(new MockDatabase());
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);
internalModule.load();
final CFunction internalFunction = 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 CView internalView = internalModule.getContent().getViewContainer().createView("", "");
@SuppressWarnings("unused") final CFunctionNode internalFunctionNode = internalView.getContent().createFunctionNode(internalFunction);
final TagManager nodeTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.NODE_TAG));
final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
final Function function = new Function(ModuleFactory.get(), internalFunction);
final Module module = new Module(database, internalModule, nodeTagManager, viewTagManager) {
@Override
public Function getFunction(final INaviFunction internalFunction) {
return function;
}
@Override
public boolean isLoaded() {
return true;
}
};
module.load();
final View view = module.getViews().get(2);
final FunctionNode node = (FunctionNode) view.getGraph().getNodes().get(0);
final MockFunctionNodeListener listener = new MockFunctionNodeListener();
node.addListener(listener);
final ArrayList<IComment> comment = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Fark"));
node.initializeComment(comment);
assertEquals("initializedComment;", listener.events);
assertEquals(comment, node.getComment());
node.removeListener(listener);
}
use of com.google.security.zynamics.binnavi.disassembly.CFunction 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.CFunction 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.CFunction in project binnavi by google.
the class ModuleHelpersTest method testGetFunction_1.
@Test
public void testGetFunction_1() {
final Database database = new Database(new MockDatabase());
@SuppressWarnings("unused") final MockModule mockModule = new MockModule();
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);
try {
internalModule.load();
} catch (final CouldntLoadDataException exception) {
CUtilityFunctions.logException(exception);
} catch (final LoadCancelledException exception) {
CUtilityFunctions.logException(exception);
}
@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 TagManager nodeTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.NODE_TAG));
final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
final Module module = new Module(database, internalModule, nodeTagManager, viewTagManager);
assertEquals(module.getFunctions().get(0), ModuleHelpers.getFunction(module, 0x123));
assertNull(ModuleHelpers.getFunction(module, 0x1235));
try {
ModuleHelpers.getFunction(null, -1);
fail();
} catch (final NullPointerException e) {
}
try {
ModuleHelpers.getFunction(module, -1);
fail();
} catch (final IllegalArgumentException e) {
}
}
use of com.google.security.zynamics.binnavi.disassembly.CFunction in project binnavi by google.
the class ModuleHelpersTest method testGetFunction_3.
@Test
public void testGetFunction_3() throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
final Database database = new Database(new MockDatabase());
final MockModule mockModule = new MockModule();
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);
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);
new CFunctionContainer(mockModule, Lists.<INaviFunction>newArrayList(parentFunction));
CFunctionContainerHelper.addFunction(mockModule.getContent().getFunctionContainer(), parentFunction);
final TagManager nodeTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.NODE_TAG));
final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
final Module module = new Module(database, mockModule, nodeTagManager, viewTagManager);
assertEquals(module.getFunctions().get(0), ModuleHelpers.getFunction(module, "Mock Function"));
assertNull(ModuleHelpers.getFunction(module, ""));
try {
ModuleHelpers.getFunction(null, (String) null);
fail();
} catch (final NullPointerException e) {
}
try {
ModuleHelpers.getFunction(module, (String) null);
fail();
} catch (final NullPointerException e) {
}
}
Aggregations