use of com.google.security.zynamics.binnavi.disassembly.Modules.CModule in project binnavi by google.
the class FunctionBlockTest method testLink.
@Test
public void testLink() {
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);
final Function function = new Function(ModuleFactory.get(), parentFunction);
final FunctionBlock block = new FunctionBlock(function);
final FunctionBlock childBlock = new FunctionBlock(function);
FunctionBlock.link(block, childBlock);
assertEquals(0, block.getParents().size());
assertEquals(1, block.getChildren().size());
assertEquals(childBlock, block.getChildren().get(0));
assertEquals(0, childBlock.getChildren().size());
assertEquals(1, childBlock.getParents().size());
assertEquals(block, childBlock.getParents().get(0));
}
use of com.google.security.zynamics.binnavi.disassembly.Modules.CModule in project binnavi by google.
the class CAddressSpaceContentTest method testAddModule.
@Test
public void testAddModule() throws CouldntSaveDataException, CouldntLoadDataException, LoadCancelledException {
final CModule module = MockCreator.createModule(m_sql);
module.getConfiguration().setImageBase(new CAddress(12322));
try {
m_addressSpace.getContent().addModule(module);
fail();
} catch (final NullPointerException exception) {
}
m_addressSpace.load();
m_addressSpace.getContent().addListener(m_listener);
try {
m_addressSpace.getContent().addModule(null);
fail();
} catch (final NullPointerException exception) {
}
m_addressSpace.getContent().addModule(module);
// Check listener
assertEquals("addedModule;changedImageBase;", m_listener.events);
// Check address space
assertEquals(1, m_addressSpace.getModuleCount());
assertEquals(module, m_addressSpace.getContent().getModules().get(0));
assertEquals(BigInteger.valueOf(12322), m_addressSpace.getContent().getImageBase(module).toBigInteger());
try {
m_addressSpace.getContent().addModule(module);
fail();
} catch (final IllegalArgumentException exception) {
}
}
use of com.google.security.zynamics.binnavi.disassembly.Modules.CModule in project binnavi by google.
the class CAddressSpaceContentTest method testRelocation.
@Test
public void testRelocation() throws CouldntSaveDataException, CouldntLoadDataException, LoadCancelledException {
final CModule module = MockCreator.createModule(m_sql);
m_addressSpace.load();
m_addressSpace.getContent().addListener(m_listener);
try {
m_addressSpace.getContent().setImageBase(module, null);
fail();
} catch (final NullPointerException exception) {
}
try {
m_addressSpace.getContent().setImageBase(null, new CAddress(0x123));
fail();
} catch (final NullPointerException exception) {
}
try {
m_addressSpace.getContent().setImageBase(module, new CAddress(0x123));
fail();
} catch (final IllegalArgumentException exception) {
}
m_addressSpace.getContent().addModule(module);
// Check the address space
assertEquals("00000666", m_addressSpace.getContent().getImageBase(module).toHexString());
m_addressSpace.getContent().setImageBase(module, new CAddress(0x123));
// Check the listener events
assertEquals("addedModule;changedImageBase;changedImageBase;", m_listener.events);
// Check the address space
assertEquals("00000123", m_addressSpace.getContent().getImageBase(module).toHexString());
assertEquals("00000666", module.getConfiguration().getImageBase().toHexString());
}
use of com.google.security.zynamics.binnavi.disassembly.Modules.CModule in project binnavi by google.
the class CCodeNodeTest method testLineToInstruction.
@Test
public void testLineToInstruction() {
final MockSqlProvider provider = new MockSqlProvider();
final CModule internalModule = new CModule(1, "", "", new Date(), new Date(), CommonTestObjects.MD5, CommonTestObjects.SHA1, 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);
final CCodeNode node = new CCodeNode(1, 0, 0, 0, 0, Color.BLACK, Color.BLACK, false, true, null, parentFunction, new LinkedHashSet<CTag>(), new MockSqlProvider());
final MockInstruction i1 = new MockInstruction(new CAddress(0x123), "nop", new ArrayList<COperandTree>(), null);
final MockInstruction i2 = new MockInstruction(new CAddress(0x124), "nop", new ArrayList<COperandTree>(), null);
final MockInstruction i3 = new MockInstruction(new CAddress(0x125), "nop", new ArrayList<COperandTree>(), null);
final MockInstruction i4 = new MockInstruction(new CAddress(0x126), "nop", new ArrayList<COperandTree>(), m_globalComment);
final MockInstruction i5 = new MockInstruction(new CAddress(0x127), "nop", new ArrayList<COperandTree>(), null);
node.addInstruction(i1, Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Foo\nBar")));
node.addInstruction(i2, Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "\n")));
node.addInstruction(i3, null);
node.addInstruction(i4, null);
node.addInstruction(i5, null);
try {
node.addInstruction(null, null);
fail();
} catch (final NullPointerException e) {
}
assertEquals(null, CCodeNodeHelpers.lineToInstruction(node, 0));
assertEquals(i1, CCodeNodeHelpers.lineToInstruction(node, 1));
assertEquals(i1, CCodeNodeHelpers.lineToInstruction(node, 2));
assertEquals(i2, CCodeNodeHelpers.lineToInstruction(node, 3));
assertEquals(i2, CCodeNodeHelpers.lineToInstruction(node, 4));
assertEquals(i3, CCodeNodeHelpers.lineToInstruction(node, 5));
assertEquals(i5, CCodeNodeHelpers.lineToInstruction(node, 9));
assertEquals(null, CCodeNodeHelpers.lineToInstruction(node, 10));
}
use of com.google.security.zynamics.binnavi.disassembly.Modules.CModule in project binnavi by google.
the class CCodeNodeTest method testInstructionToLine.
@Test
public void testInstructionToLine() {
final MockSqlProvider provider = new MockSqlProvider();
final CModule internalModule = new CModule(1, "", "", new Date(), new Date(), CommonTestObjects.MD5, CommonTestObjects.SHA1, 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);
final CCodeNode node = new CCodeNode(1, 0, 0, 0, 0, Color.BLACK, Color.BLACK, false, true, null, parentFunction, new LinkedHashSet<CTag>(), new MockSqlProvider());
final MockInstruction i1 = new MockInstruction(new CAddress(0x123), "nop", new ArrayList<COperandTree>(), null);
final MockInstruction i2 = new MockInstruction(new CAddress(0x124), "nop", new ArrayList<COperandTree>(), null);
final MockInstruction i3 = new MockInstruction(new CAddress(0x125), "nop", new ArrayList<COperandTree>(), null);
final MockInstruction i4 = new MockInstruction(new CAddress(0x126), "nop", new ArrayList<COperandTree>(), m_globalComment);
final MockInstruction i5 = new MockInstruction(new CAddress(0x127), "nop", new ArrayList<COperandTree>(), null);
node.addInstruction(i1, Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Foo\nBar")));
node.addInstruction(i2, Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "\n")));
node.addInstruction(i3, null);
node.addInstruction(i4, null);
node.addInstruction(i5, null);
// The first instruction should (naturally) start in the first line.
assertEquals(1, CCodeNodeHelpers.instructionToLine(node, i1));
// The second instruction should start in line 3 - because the first instruction, with the two-
// line comment, eats up lines 1 and 2.
assertEquals(3, CCodeNodeHelpers.instructionToLine(node, i2));
// The third instruction needs to start in line 4 - since the second instruction is a single
// line with an empty newline comment (??). Why is this not 2 lines then?
assertEquals(5, CCodeNodeHelpers.instructionToLine(node, i3));
assertEquals(6, CCodeNodeHelpers.instructionToLine(node, i4));
assertEquals(9, CCodeNodeHelpers.instructionToLine(node, i5));
try {
new CCodeNode(1, 0, 0, 0, 0, Color.BLUE, Color.BLUE, false, true, null, parentFunction, new LinkedHashSet<CTag>(), null);
fail();
} catch (final NullPointerException e) {
}
}
Aggregations